-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathnode_helper.js
53 lines (47 loc) · 1.47 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
49
50
51
52
53
/* Magic Mirror
*
* Module: MMM-ISS
*
* By Mykle1 - MIT Licensed
*
*/
const NodeHelper = require('node_helper');
const request = require('request');
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node_helper for: " + this.name);
},
getISS: function(url) {
request({
url: url,
method: 'GET'
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body);
//console.log(response.statusCode); // for checking in terminal
this.sendSocketNotification('ISS_RESULT', result);
}
});
this.getVELALT();
},
getVELALT: function(url) {
request({
url: "https://api.wheretheiss.at/v1/satellites/25544",
method: 'GET'
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body);
//console.log(response.statusCode); // for checking in terminal
this.sendSocketNotification('VELALT_RESULT', result);
}
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_ISS') {
this.getISS(payload);
}
if (notification === 'GET_VELALT') {
this.getVELALT(payload);
}
}
});