-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_helper.js
37 lines (31 loc) · 1.01 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
/* Timetable for Trains Module */
/* Magic Mirror
* Module: SwissTransport
*
* By Benjamin Angst http://www.beny.ch
* based on a Script from Michael Teeuw http://michaelteeuw.nl
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log('MMM-Trainconnections helper started ...');
},
getTrains: function(api_url) {
var self = this;
request({url: api_url, method: 'GET'}, function(error, response, body) {
if (!error && response.statusCode == 200) {
var trains = JSON.parse(body);
self.sendSocketNotification('TRAIN_CONNECTIONS', {'trains':trains});
}
});
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
//console.log(notification);
if (notification === 'TRAIN_URL') {
this.getTrains(payload);
}
}
});