-
Notifications
You must be signed in to change notification settings - Fork 1
/
wunderlist-get-tasks.js
34 lines (30 loc) · 992 Bytes
/
wunderlist-get-tasks.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
var wunderlistSDK = require('./wunderlist-sdk');
module.exports = function(RED) {
function WunderlistGetTasks(n) {
RED.nodes.createNode(this, n);
var node = this;
this.config = RED.nodes.getNode(n.config);
this.on('input', function(msg, send, done) {
send = send || function() { node.send.apply(node,arguments) };
var wunderlistAPI = wunderlistSDK.getApi(node.config, msg);
var tasks = wunderlistAPI.http.tasks;
tasks.forList(Number(n.listId || msg.payload), (msg.completed || false))
.done(function (tasksData, statusCode) {
msg.payload = tasksData;
send(msg);
if (done) {
done();
}
})
.fail(function (resp, code) {
var err = resp || 'Wunderlist API error';
if (done) {
done(err)
} else {
node.error(err);
}
});
});
}
RED.nodes.registerType('wunderlist-get-tasks', WunderlistGetTasks);
};