forked from Com-Lum/MMM-RMV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
53 lines (43 loc) · 1.19 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-RMV
*
* By Com-Lum
* MIT Licensed.
*/
const request = require('request');
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start: function()
{
console.log("node helper: " + this.name);
},
//Built_Para - return URL parameter as string
Built_Para: function()
{
var para = this.config.apiKey;
para +="&id=" + this.config.stationId;
para +="&duration=" + this.config.maxT;
para +="&maxJourneys=" + this.config.maxJ;
para +="&format=json";
return para;
},
socketNotificationReceived: function(notification, payload)
{
if(notification === 'CONFIG')
{
this.config = payload;
var rmvUrl = this.config.apiUrl + this.Built_Para();
this.getData(rmvUrl, this.config.stationId);
//console.log(rmvUrl);
}
},
getData: function(options, stationId) {
request(options, (error, response, body) => {
if (response.statusCode === 200) {
this.sendSocketNotification("Trains" + stationId, JSON.parse(body));
} else {
console.log("Error: No connection data recieved. Error code: " + response.statusCode);
}
});
}
});