jeedom-request-jsonrpc
Advanced tools
Comparing version 1.0.1 to 1.0.2
const axios = require('axios') | ||
class jeedomRequest { | ||
constructor(url, apikey, reqParams = {}, jsonrpc = '2.0') { | ||
/** | ||
* | ||
* @param url | ||
* @param apikey | ||
* @param reqParams | ||
* @param options | ||
* @param jsonrpc | ||
*/ | ||
constructor(url, apikey, reqParams = {}, options = {}, jsonrpc = '2.0') { | ||
this.url = url | ||
@@ -12,3 +21,10 @@ this.apikey = apikey | ||
getBody(method, paramsCustom = false) { | ||
/** | ||
* | ||
* @param method | ||
* @param paramsCustom | ||
* @returns {{jsonrpc: (string|*), method: *, params: {apikey: *}}} | ||
* @private | ||
*/ | ||
_getBody(method, paramsCustom = false) { | ||
let params = { | ||
@@ -27,7 +43,11 @@ "apikey": this.apikey | ||
getBaseUrl() { | ||
return this.url | ||
} | ||
getResult(body) { | ||
/** | ||
* | ||
* @param cmd | ||
* @param params | ||
* @returns {*} | ||
* @private | ||
*/ | ||
_getResult(cmd, params) { | ||
let body = this._getBody(cmd, params) | ||
let reqParamsToSend = {...{}, ...this.reqParams} | ||
@@ -37,9 +57,113 @@ return axios.post(this.url, body, reqParamsToSend) | ||
messageAll() { | ||
// 1) Divers | ||
ping(params = {}) { | ||
return this._getResult('ping', params) | ||
} | ||
version(params = {}) { | ||
return this._getResult('version', params) | ||
} | ||
datetime(params = {}) { | ||
return this._getResult('datetime', params) | ||
} | ||
// 2) API config | ||
config_byKey(params = {}) { | ||
return this._getResult('config::byKey', params) | ||
} | ||
config_save(params = {}) { | ||
return this._getResult('config::save', params) | ||
} | ||
// 3) API JSON Event | ||
event_changes(params = {}) { | ||
return this._getResult('event::changes', params) | ||
} | ||
// 4) API JSON Plugin | ||
plugin_listPlugin(params = {}) { | ||
return this._getResult('plugin::listPlugin', params) | ||
} | ||
// API JSON Cmd | ||
cmd_all(params = {}) { | ||
return this._getResult('cmd::all', params) | ||
} | ||
cmd_byId(params = {}) { | ||
return this._getResult('cmd::byId', params) | ||
} | ||
cmd_byEqLogicId(params = {}) { | ||
return this._getResult('cmd::byEqLogicId', params) | ||
} | ||
cmd_execCmd(params = {}) { | ||
return this._getResult('cmd::execCmd', params) | ||
} | ||
cmd_getStatistique(params = {}) { | ||
return this._getResult('cmd::getStatistique', params) | ||
} | ||
cmd_getTendance(params = {}) { | ||
return this._getResult('cmd::getTendance', params) | ||
} | ||
cmd_getHistory(params = {}) { | ||
return this._getResult('cmd::getHistory', params) | ||
} | ||
cmd_save(params = {}) { | ||
return this._getResult('cmd::save', params) | ||
} | ||
// 9) API JSON Scenario | ||
scenario_all(params = {}) { | ||
return this._getResult('scenario::all', params) | ||
} | ||
scenario_byId(params = {}) { | ||
return this._getResult('scenario::byId', params) | ||
} | ||
scenario_export(params = {}) { | ||
return this._getResult('scenario::export', params) | ||
} | ||
scenario_import(params = {}) { | ||
return this._getResult('scenario::import', params) | ||
} | ||
scenario_changeState(params = {}) { | ||
return this._getResult('scenario::changeState', params) | ||
} | ||
// API JSON Message | ||
messageAll(p = {}) { | ||
let cmd = 'message::all' | ||
return this.getResult(this.getBody(cmd)) | ||
return this._getResult(cmd, p) | ||
} | ||
// all constant | ||
get scenario_state() { | ||
return { | ||
RUN: "run", | ||
STOP: "stop", | ||
ENABLE: "enable", | ||
DISABLE: "disable" | ||
} | ||
} | ||
} | ||
module.exports = jeedomRequest; |
{ | ||
"name": "jeedom-request-jsonrpc", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Module node pour API JEEDOM JSON-RPC", | ||
@@ -14,5 +14,5 @@ "main": "/lib/jeedom-request-jsonrpc.js", | ||
"keywords": [ | ||
"jeedom" | ||
"jeedom", "api", "json" | ||
], | ||
"author": "", | ||
"author": "Clement BERARD", | ||
"license": "ISC", | ||
@@ -19,0 +19,0 @@ "dependencies": { |
@@ -9,2 +9,31 @@ # Jeedom API - JSON RPC | ||
## Installation | ||
`npm i jeedom-request-jsonrpc` | ||
## Exemple complet (pour les plus rapides ! Détails en dessous :) | ||
```javascript | ||
const jeedomApiModule = require('jeedom-request-jsonrpc'); | ||
const jeedomApiJson = new jeedomApiModule( | ||
'{IP-JEEDOM}/core/api/jeeApi.php', | ||
'mon-api-key' | ||
) | ||
// je veux executer la method cmd::execCmd | ||
let req = jeedomApiJson.cmd_execCmd({ | ||
id: 802 | ||
}) | ||
req | ||
.then(response => { | ||
console.log('Ma reponse est : ', response.data) | ||
}) | ||
.catch(error => { | ||
console.log('Oups une erreur : ',error) | ||
}) | ||
``` | ||
## Initialisation | ||
@@ -30,3 +59,3 @@ | ||
```javascript | ||
constructor(url, apikey, reqParams = {}, jsonrpc = '2.0') { | ||
constructor(url, apikey, reqParams = {}, options = {}, jsonrpc = '2.0') { | ||
this.url = url | ||
@@ -48,3 +77,3 @@ this.apikey = apikey | ||
Exemple : `object::full` devient `objectFull`, `cmd::execCmd` devient `cmdExecCmd` etc... | ||
Exemple : `object::full` devient `object_full`, `cmd::execCmd` devient `cmd_execCmd` etc... | ||
@@ -69,25 +98,4 @@ ## Appel des fonctions | ||
## Exemple complet | ||
```javascript | ||
const jeedomApiModule = require('./jeedom-request'); | ||
const axios = require('axios') | ||
const jeedomApiJson = new jeedomApiModule( | ||
'{IP-JEEDOM}/core/api/jeeApi.php', | ||
'mon-api-key' | ||
) | ||
let req = jeedomApiJson.messageAll() | ||
req | ||
.then(response => { | ||
console.log('Ma reponse est : ', response.data) | ||
}) | ||
.catch(error => { | ||
console.log('Oups une erreur : ',error) | ||
}) | ||
``` | ||
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
6148
129
2
98