-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnode_helper.js
47 lines (41 loc) · 1.17 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
var NodeHelper = require("node_helper");
var request = require("request");
module.exports = NodeHelper.create({
start: function () {
console.log(`Starting node helper for: ${this.name}`);
},
socketNotificationReceived: function (notification, data) {
if (notification === "FETCH_MPK_DATA") {
this.getMpkData(data);
}
if (notification === "NOTIFICATION_MPK") {
this.logNotification(data);
}
if (notification === "SEARCH_MPK_STOP") {
this.getMpkStop(data);
}
},
getMpkData(url) {
request(url, (error, response, body) => {
const statusCode = response && response.statusCode;
this.sendSocketNotification("NEW_MPK_DATA", {
statusCode,
body
})
});
},
getMpkStop(name) {
name = name.replace(' ', '+');
const url = `http://www.ttss.krakow.pl/internetservice/services/lookup/autocomplete/json?query=${name}&language=pl`;
request(url, (error, response, body) => {
const statusCode = response && response.statusCode;
this.sendSocketNotification("NEW_MPK_STOP", {
statusCode,
body
})
});
},
logNotification(message) {
console.log(message)
}
});