-
Notifications
You must be signed in to change notification settings - Fork 7
/
node_helper.js
66 lines (62 loc) · 1.9 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* Magic Mirror
* Module: MMM-CANVAS
*
* By Chase Cromwell
*
*/
const NodeHelper = require('node_helper');
const request = require('request');
var smallpayload = [
["", "", ""],
];
var finalpayload = [
["", ""],
];
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node_helper for: " + this.name);
},
getCANVAS: function(payload) {
var key = payload[0];
var courses = payload[1];
var urlbase = payload[2];
var count = 0;
var self = this;
courses.forEach(runCourses);
var timer = setInterval(function() {
if (count == courses.length) {
self.sendSocketNotification('CANVAS_RESULT', finalpayload);
finalpayload = [
["", ""],
];
smallpayload = [
["", ""],
];
count = 0;
}
}, 400);
function runCourses(item, index) {
var url = "https://"+ urlbase +"/api/v1/courses/" + courses[index] + "/assignments?access_token=" + key + "&per_page=30&bucket=upcoming&order_by=due_at";
request({
url: url,
method: 'GET'
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var result = JSON.parse(body);
for (var j in result) {
smallpayload.push([result[j].name, result[j].due_at, index]);
}
} else {
smallpayload.push(["ERROR", JSON.parse(error), ""]);
}
finalpayload.push(smallpayload);
count++;
});
}
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_CANVAS') {
this.getCANVAS(payload);
}
}
});