-
Notifications
You must be signed in to change notification settings - Fork 15
/
node_helper.js
40 lines (32 loc) · 971 Bytes
/
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
/* Live Station Info */
/* Magic Mirror
* Module: UK National Rail Info
* By Nick Wootton
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log('MMM-UKNationalRail helper started ...');
},
/* getTimetable()
* Requests new data from TransportAPI.com
* Sends data back via socket on succesfull response.
*/
getTimetable: function(url) {
var self = this;
var retry = true;
request({url:url, method: 'GET'}, function(error, response, body) {
if(!error && response.statusCode == 200) {
self.sendSocketNotification('TRAIN_DATA', {'data': JSON.parse(body), 'url': url});
}
});
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_TRAININFO') {
this.getTimetable(payload.url);
}
}
});