-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.js
33 lines (31 loc) · 1.15 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const request = require('request'); // require in request
const config = require('./config.json');
const initGetVoiceCSQDetailsStats = {uri: 'http://' + config.puccxipaddr + ':9080/realtime/VoiceCSQDetailsStats'};
const initGetVoiceIAQStats = {uri: 'http://' + config.puccxipaddr + ':9080/realtime/VoiceIAQStats'};
const apiCaller = function (url, cb) {
//use request to make the external http call to the JSON api
request({
url: url,
json: true
}, function (error, response, body) {
if (!error && response.statusCode === 200) {
cb(body);// Send body/response to callback
//console.log(response);
}
if (error) {
console.log(error);
//cb("Error");
}
})};
// Call the api with a call back
const apiGetVoiceCSQDetailsStats = function(cb) {
return apiCaller(initGetVoiceCSQDetailsStats.uri, cb);
};
const apiGetVoiceIAQStats = function(cb) {
return apiCaller(initGetVoiceIAQStats.uri, cb);
};
// Export the functions for external access
module.exports = {
apiGetVoiceCSQDetailsStats: apiGetVoiceCSQDetailsStats,
apiGetVoiceIAQStats: apiGetVoiceIAQStats
};