databoom.js
Version:
Client functionalities to send data to DATABOOM.
140 lines (119 loc) • 4.35 kB
JavaScript
/**
* DATABOOM APIs
* Visit us ... https://databoom.com/
* Created by rickymarchiori on 21/03/2016
*/
;
//Dependencies
var config = require('./config/config.js'),
request = require('request');
exports.getAlarms = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIAlarms, callback);
else throw new Error('You need a callback to read the result');
}
exports.getAlarmById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APIAlarms+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
}
exports.getChartSignal = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APIChartSignal+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
}
exports.getDashboards = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIDashboards, callback);
else throw new Error('You need a callback to read the result');
};
exports.getDashboardById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APIDashboards+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
};
exports.getWidgets = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIWidgets, callback);
else throw new Error('You need a callback to read the result');
};
exports.getWidgetById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APIWidgets+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
};
exports.getDevices = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIDevices, callback);
else throw new Error('You need a callback to read the result');
}
exports.getDeviceById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APIDevices+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
}
exports.getDeviceByToken = function(apikey, token, callback){
if(token && callback)
getReqDataboom(apikey, config.api.APIDevicesToken+'/'+token, callback);
else throw new Error('Missing parameter token or callback');
}
exports.getDevicesTypes = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIDevicesType, callback);
else throw new Error('You need a callback to read the result');
}
exports.getRules = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIRules, callback);
else throw new Error('You need a callback to read the result');
}
exports.getRuleById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APIRules+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
}
exports.getUnits = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APIUnits, callback);
else throw new Error('You need a callback to read the result');
}
exports.getSignals = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APISignals, callback);
else throw new Error('You need a callback to read the result');
}
exports.getSignalById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APISignals+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
}
exports.getTeams = function(apikey, callback){
if(callback)
getReqDataboom(apikey, config.api.APITeams, callback);
else throw new Error('You need a callback to read the result');
}
exports.getTeamById = function(apikey, id, callback){
if(id && callback)
getReqDataboom(apikey, config.api.APITeams+'/'+id, callback);
else throw new Error('Missing parameter id or callback');
}
function getReqDataboom(apikey, uri, callback){
var options = {
uri: uri,
method: 'GET',
headers: {
'apikey': apikey
}
};
request(options, function (error, response, body) {
if (!error && body) {
callback(body);
}
else if (error) {
throw new Error(error);
}
else{
throw new Error('Unknown error, server response:\n' + response);
}
});
}