forked from Jopyth/MMM-Trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node-trello-lite.js
52 lines (42 loc) · 1.22 KB
/
node-trello-lite.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
var querystring = require("querystring");
// Creates a new Trello request wrapper.
// Syntax: new Trello(applicationApiKey, userToken)
var Trello = module.exports = function (key, token) {
if (!key) {
throw new Error("Application API key is required");
}
this.key = key;
this.token = token;
this.host = "https://api.trello.com";
};
Trello.prototype.getCards = async function (listId) {
const queryString = querystring.stringify(this.addAuthArgs({}));
const res = await fetch(`${this.host}/1/lists/${listId}/cards?${queryString}`);
if (res.ok) {
return res.json();
}
}
Trello.prototype.getChecklist = async function (checkListId) {
const queryString = querystring.stringify(this.addAuthArgs({}));
const res = await fetch(`${this.host}/1/checklists/${checkListId}?${queryString}`);
if (res.ok) {
return res.json();
}
}
Trello.prototype.addAuthArgs = function (args) {
args.key = this.key;
if (this.token) {
args.token = this.token;
}
return args;
};
Trello.prototype.parseQuery = function (uri, args) {
if (uri.indexOf("?") !== -1) {
var ref = querystring.parse(uri.split("?")[1]);
for (var key in ref) {
var value = ref[key];
args[key] = value;
}
}
return args;
};