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

git.mdns.eu/nextcloud/passwords-client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Model/Server/Server.js')
-rw-r--r--src/Model/Server/Server.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/Model/Server/Server.js b/src/Model/Server/Server.js
new file mode 100644
index 0000000..6c36ba3
--- /dev/null
+++ b/src/Model/Server/Server.js
@@ -0,0 +1,80 @@
+import ConfigruationError from '../../Exception/ConfigruationError';
+import Properties from '../../Configuration/Server';
+import AbstractModel from './../AbstractModel';
+import ObjectMerger from '../../Utility/ObjectMerger';
+
+export default class Server extends AbstractModel {
+
+ /**
+ *
+ * @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/`;
+ }
+} \ No newline at end of file