-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
28 lines (23 loc) · 864 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
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
socketNotificationReceived (notification, payload) {
if(notification === "GET_TRASH_DATA") {
const rovaApiUrl = 'https://www.rova.nl/api/waste-calendar/upcoming?postalcode=' + payload.zipCode + '&houseNumber=' + payload.houseNr + '&addition=' + payload.houseNrAddition + '&take=3';
const errorResponse = {error: true};
fetch(rovaApiUrl)
.then((response) => {
if (! response.ok) {
throw new Error('Kon geen gegevens ophalen, werkt het internet?');
}
return response.json();
})
.then((data) => {
this.sendSocketNotification("TRASH_DATA", data);
})
.catch(error => {
//console.error("Fout bij ophalen: ", error);
this.sendSocketNotification("TRASH_DATA", errorResponse); // Send error response
});
}
},
});