forked from eckonator/MMM-Oelpreise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
33 lines (29 loc) · 1009 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
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log('MMM-Oelpreise helper started...');
},
getJson: function (url) {
var self = this;
console.log("MMM-Oelpreise getJson url: " + url);
request({ url: url, method: 'GET' }, function (error, response, body) {
if (!error && response.statusCode == 200) {
var json = JSON.parse(body);
// Send the json data back with the url to distinguish it on the receiving part
self.sendSocketNotification("MMM-Oelpreise_JSON_RESULT", {url: url, data: json});
console.log("MMM-Oelpreise request was succesfull");
}
else {
console.log("MMM-Oelpreise request had error", error, response);
}
});
},
socketNotificationReceived: function (notification, url) {
console.log(notification);
if (notification === "MMM-Oelpreise_GET_JSON") {
console.log("MMM-Oelpreise_GET_JSON received for url: " + url);
this.getJson(url);
}
}
});