-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnode_helper.js
42 lines (37 loc) · 957 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
41
42
/* global module */
/* Magic Mirror
* Node Helper: MMM-CuandoLlega
*
* By Jose Forte
* MIT Licensed.
*/
var NodeHelper = require('node_helper')
var request = require('request')
var cuandoLlegaAPI = 'https://ws.rosario.gob.ar/ubicaciones/public/cuandollega'
module.exports = NodeHelper.create({
start: function () {
console.log('Starting node helper for: ' + this.name)
},
getBusInfo: function(info) {
var self = this
var options = {
method: 'GET',
qs: {
linea: info.line,
parada: info.stop
},
url: cuandoLlegaAPI
}
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body)
self.sendSocketNotification('BUS_RESULT', result)
}
})
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_INFO') {
this.getBusInfo(payload)
}
}
});