-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMMM-HTTPRequest.js
More file actions
61 lines (48 loc) · 1.76 KB
/
MMM-HTTPRequest.js
File metadata and controls
61 lines (48 loc) · 1.76 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* global Module */
/* Magic Mirror
* Module: MMM-HTTPRequest
*
* By Andreas Cederström andreas.cederstrom@gmail.com
* MIT Licensed.
*/
Module.register("MMM-HTTPRequest",{
requiresVersion: "2.1.0",
// Default module config
defaults: {
showAlertOnError: true,
requests: {}
},
start: function() {
this.logInfo("Starting module");
for (var request in this.config.requests) {
if (this.config.requests.hasOwnProperty(request)) {
var requestConfig = this.config.requests[request];
if (!requestConfig.url) {
this.logError("Request " + request + " does not have the mandatory attribute 'url'");
}
}
}
this.sendSocketNotification("HTTP_REQUEST_INIT", {
config: this.config
});
},
logInfo: function(message) {
Log.info(this.name + ": " + message);
},
logError: function(message) {
Log.error(this.name + ": " + message);
},
notificationReceived: function(notification, payload, sender) {
if (notification === "HTTP_REQUEST") {
this.logInfo("Got " + notification + "with payload.request: " + payload.request);
this.sendSocketNotification("HTTP_REQUEST_SEND", {
id: payload.request
});
}
},
socketNotificationReceived: function(notification, payload) {
if (notification === "HTTP_REQUEST_CALLBACK") {
this.sendNotification(payload.notification, payload.payload);
}
}
});