-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
48 lines (39 loc) · 1.24 KB
/
node_helper.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const request = require('request');
const NodeHelper = require('node_helper');
module.exports = NodeHelper.create({
socketNotificationReceived(notification, payload) {
var that = this;
request(
'https://russianwarship.rip/api/v1/statistics/latest',
function (error, response, body) {
if (error) {
console.error('GET_DATA error:', error.message);
return that.sendSocketNotification('ERR', {
type: 'request error',
msg: error,
});
}
if (response.statusCode !== 200) {
console.error('GET_DATA wrong status code:', response.statusCode);
return that.sendSocketNotification('ERR', {
type: 'request statusCode',
msg: response && response.statusCode,
});
}
if (!error && response.statusCode === 200) {
let data;
try {
data = JSON.parse(body);
} catch (e) {
console.error('GET_DATA json parse:', e.message);
return that.sendSocketNotification('ERR', {
type: 'request error',
msg: error,
});
}
that.sendSocketNotification('DATA', data.data);
}
}
);
},
});