forked from nwootton/MMM-UKLiveBusStopInfo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
40 lines (32 loc) · 1.02 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
/* Live Bus Stop Info */
/* Magic Mirror
* Module: UK Live Bus Stop Info
* By Nick Wootton
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function() {
console.log('MMM-UKLiveBusStopInfo 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('BUS_DATA', { 'data': JSON.parse(body), 'url': url });
}
});
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_BUSINFO') {
this.getTimetable(payload.url);
}
}
});