-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
44 lines (37 loc) · 1.21 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
/* Magic Mirror
* Node Helper: MMM-Reddito
*
* By bittiez
* MIT Licensed.
*/
var NodeHelper = require("node_helper");
var request = require('request');
module.exports = NodeHelper.create({
// Override socketNotificationReceived method.
/* socketNotificationReceived(notification, payload)
* This method is called when a socket notification arrives.
*
* argument notification string - The identifier of the noitication.
* argument payload mixed - The payload of the notification.
*/
socketNotificationReceived: function(notification, infoRecv) {
var self = this;
if (notification === "MMM-Reddito-DATA_CHANGE") {
var payload = infoRecv.config;
var id = infoRecv.id;
var urlApi = "https://reddit.com/r/" + payload.subreddit + "/" + payload.sortby + "/.rss";
request({ url: urlApi, method: 'GET' }, function (error, response, body) {
if (!error && response.statusCode == 200) {
var result = body;
self.sendNotificationUpdate({id: id, config: result});
} else if (error) {
console.log(error);
}
});
}
},
// Example function send notification test
sendNotificationUpdate: function(payload) {
this.sendSocketNotification("MMM-Reddito-DATA_CHANGE", payload);
},
});