Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Server.js « Server « Model « src - git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cfce53a8f833c66ee973e6671466324131fb2522 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import ConfigruationError from '../../Exception/ConfigruationError';
import Properties from '../../Configuration/Server.json';
import AbstractModel from './../AbstractModel';
import ObjectMerger from '../../Utility/ObjectMerger';

export default class Server extends AbstractModel {

    get MODEL_TYPE() {return 'server';}

    /**
     *
     * @param {Object} data
     * @param {(Object|null)} [properties=null]
     */
    constructor(data = {}, properties = null) {
        if(!data.hasOwnProperty('baseUrl') || data.baseUrl.substr(0, 5) !== 'https') {
            throw new ConfigruationError('Base URL missing or invalid');
        }

        if(properties !== null) ObjectMerger.merge(Properties, properties);
        super(Properties, data);
    }

    /**
     * @return {String}
     */
    getBaseUrl() {
        return this.getProperty('baseUrl');
    }

    /**
     * @param {String} value
     *
     * @return {Server}
     */
    setBaseUrl(value) {
        if(value.substr(0, 5) !== 'https') {
            throw new ConfigruationError('Base URL missing or invalid');
        }

        return this.setProperty('baseUrl', value);
    }

    /**
     * @return {String}
     */
    getUser() {
        return this.getProperty('user');
    }

    /**
     * @param {String} value
     *
     * @return {Server}
     */
    setUser(value) {
        return this.setProperty('user', value);
    }

    /**
     * @return {String}
     */
    getToken() {
        return this.getProperty('token');
    }

    /**
     * @param {String} value
     *
     * @return {Server}
     */
    setToken(value) {
        return this.setProperty('token', value);
    }

    /**
     * @return {String}
     */
    getApiUrl() {
        return `${this.getBaseUrl()}index.php/apps/passwords/api/`;
    }
}