forked from CFenner/MMM-LocalTransport
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnode_helper.js
More file actions
44 lines (42 loc) · 1.32 KB
/
Copy pathnode_helper.js
File metadata and controls
44 lines (42 loc) · 1.32 KB
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
/* Magic Mirror
* Module: localtransport
*
* By Christopher Fenner https://github.com/CFenner
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log(this.name + ' helper started ...');
},
makeAPIrequest: function(payload,responseName){
var that = this;
request({
url: payload.url,
method: 'GET'
}, function(error, response, body) {
if (!error && response.statusCode == 200) {
that.sendSocketNotification(responseName, {
id: payload.id,
data: JSON.parse(body)
});
}
});
},
socketNotificationReceived: function(notification, payload) {
//console.log(notification);
if (notification === 'LOCAL_TRANSPORT_REQUEST') {
this.makeAPIrequest(payload,'LOCAL_TRANSPORT_RESPONSE');
}
if (notification === 'LOCAL_TRANSPORT_WALK_REQUEST') {
this.makeAPIrequest(payload,'LOCAL_TRANSPORT_WALK_RESPONSE');
}
if (notification === 'LOCAL_TRANSPORT_CYCLE_REQUEST') {
this.makeAPIrequest(payload,'LOCAL_TRANSPORT_CYCLE_RESPONSE');
}
if (notification === 'LOCAL_TRANSPORT_DRIVE_REQUEST') {
this.makeAPIrequest(payload,'LOCAL_TRANSPORT_DRIVE_RESPONSE');
}
}
});