From fb7727d1c0ee0a93376773943436779e27f60ba8 Mon Sep 17 00:00:00 2001 From: Jannik Schönartz Date: Sun, 5 Aug 2018 01:24:49 +0000 Subject: [external-backends] Added comments for the API functions and in the external-backend prototype file. Added iDoIT method to get a list of all objects. --- server/lib/external-backends/external-backends.js | 54 +++++++++++++++++++++-- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'server/lib/external-backends/external-backends.js') diff --git a/server/lib/external-backends/external-backends.js b/server/lib/external-backends/external-backends.js index be32c13..e01a15c 100644 --- a/server/lib/external-backends/external-backends.js +++ b/server/lib/external-backends/external-backends.js @@ -3,16 +3,34 @@ const fs = require('fs') const path = require('path') class ExternalBackends { + /* + * Returns a list of all backends which have a .js file. + */ getBackends () { var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends')) return files } + /* + * Returns the credential structure / fields, defined in the backends. + * + * If type === switch there can be child elements in the elements attribute. + * Those elements are only shown, if the switch is set to true. + * [{ type: 'text', id: 1, name: '', icon: '' }, + * { type: 'password', id: 2, name: '', icon: '' }, + * { type: 'switch', id: 3, name: '', icon: '' , elements: [ { type: ... } ] }, + * { type: 'select', id: 4, name: '', icon: '' }, ...] + */ getCredentials () { console.log('If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!') return null } + /* + * type: + * + * Returns the instance of a given backend type. + */ getInstance (type) { const bList = this.getBackends() const bType = type + '-backend.js' @@ -27,16 +45,46 @@ class ExternalBackends { return backend } + /* Returns an empty array [] if the backends doesn't have the function implemented. + * + * return: ['', ...] + */ getSyncTypes () { return [] } + /* + * credendtials: + * + * Returns a list of all objects in the backend. + */ + async getObjects (credendtials) { + return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getObjects method' } + } + + /* + * credendtials: + * oid: + * + * Call the API of the backend and returns the information to the object including a list of childs. + */ + async getObject (credentials, oid) { + return { status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a getObject method' } + } + + /* + * Checks the connection of a given backend. + * + * return: { success: , status: '', error: '' } + */ async checkConnection (backend) { - console.log('If this method gets called the backend class has NOT IMPLEMENTED the checkConnection method!') - return null + return { success: false, status: 'NOT_IMPLEMENTED_EXCEPTION', error: 'The provided backend does not have a checkConnection method' } } - // Return an empty array [] if the backends doesn't have such a function. + /* Returns an empty array [] if the backends doesn't have such a function. + * + * return: [{id: , title: }, ...] + */ async getObjectTypes (credentials) { return [] } -- cgit v1.2.3-55-g7522