-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
118 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* @public | ||
* @description this function returns a list of methods passed in parameters with a true or false value if they are exposed by a module. | ||
* @name gladys.module.getMethods | ||
* @param {string} module The module slug | ||
* @param {string} service The name of the gladys api service, like 'television', 'music', ... (option) | ||
* @param {array} methods the module's method(s) you want to test | ||
* @returns {array} data | ||
* @example | ||
* | ||
* var params = { | ||
'module' :"livebox", | ||
'service':"television", | ||
'methods' :["getState", "setChannel", "getChannel", "setMuted", "getMuted"] | ||
}; | ||
* | ||
* gladys.module.getMethods(params) | ||
* .then((data) => { | ||
* var availableMethods = data.data | ||
* | ||
* }) | ||
* .catch((err) => { | ||
* // something bad happened ! :/ | ||
* }); | ||
* | ||
* The structure of availableMethods is then as follows: | ||
* { | ||
* getState: true, | ||
* setChannel: true, | ||
* getChannel: false, | ||
* setMuted: true, | ||
* getMuted: false | ||
* } | ||
*/ | ||
|
||
|
||
module.exports = function getMethods(params) { | ||
var availableMethods = {}; | ||
if(params.hasOwnProperty('service')) { | ||
params.methods.forEach(function(method) { | ||
if (!gladys.modules[params.module] || !gladys.modules[params.module][params.service] || typeof gladys.modules[params.module][params.service][method] != 'function') { | ||
availableMethods[method] = false; | ||
} else { | ||
availableMethods[method] = true; | ||
} | ||
}); | ||
} else { | ||
params.methods.forEach(function(method) { | ||
if (!gladys.modules[params.module] || typeof gladys.modules[params.module][method] != 'function') { | ||
availableMethods[method] = false; | ||
} else { | ||
availableMethods[method] = true; | ||
} | ||
}); | ||
} | ||
|
||
|
||
return Promise.resolve(availableMethods); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,48 @@ | ||
|
||
(function () { | ||
'use strict'; | ||
'use strict'; | ||
|
||
angular | ||
.module('gladys') | ||
.factory('moduleService', moduleService); | ||
angular | ||
.module('gladys') | ||
.factory('moduleService', moduleService); | ||
|
||
moduleService.$inject = ['$http']; | ||
moduleService.$inject = ['$http']; | ||
|
||
function moduleService($http) { | ||
function moduleService($http) { | ||
|
||
var service = { | ||
get: get, | ||
install: install, | ||
config: config, | ||
uninstall: uninstall, | ||
upgrade: upgrade | ||
}; | ||
|
||
return service; | ||
|
||
function get() { | ||
return $http({method: 'GET', url: '/module'}); | ||
} | ||
var service = { | ||
get: get, | ||
install: install, | ||
config: config, | ||
uninstall: uninstall, | ||
upgrade: upgrade, | ||
getMethods: getMethods | ||
}; | ||
|
||
return service; | ||
|
||
function get() { | ||
return $http({method: 'GET', url: '/module'}); | ||
} | ||
|
||
function install(module){ | ||
return $http({method: 'POST', url: '/module/install', data: module}); | ||
} | ||
function install(module){ | ||
return $http({method: 'POST', url: '/module/install', data: module}); | ||
} | ||
|
||
function config(slug){ | ||
return $http({method: 'POST', url: '/module/' + slug + '/config'}); | ||
} | ||
function config(slug){ | ||
return $http({method: 'POST', url: '/module/' + slug + '/config'}); | ||
} | ||
|
||
function uninstall(id){ | ||
return $http({method: 'DELETE', url: '/module/' + id }); | ||
} | ||
function uninstall(id){ | ||
return $http({method: 'DELETE', url: '/module/' + id }); | ||
} | ||
|
||
function upgrade(id, version){ | ||
return $http({method: 'POST', url: '/module/' + id + '/upgrade', data: {version: version}}); | ||
} | ||
|
||
function upgrade(id, version){ | ||
return $http({method: 'POST', url: '/module/' + id + '/upgrade', data: {version: version}}); | ||
} | ||
function getMethods(params) { | ||
return $http({method: 'POST', url: '/module/getMethods', data: params}); | ||
} | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters