forked from devtyr/trello
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
104 lines (81 loc) · 3.2 KB
/
main.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var rest = require('rest-client');
var Trello = function (key, token) {
this.uri = "https://api.trello.com";
this.key = key;
this.token = token;
};
Trello.prototype.createQuery = function () {
return {key: this.key, token: this.token};
};
function makeRequest(method, uri, options, callback) {
rest.send({
url: uri,
method: method,
form: options
}, function(res, body) {
if (res.statusCode === 200) {
callback(null, body);
} else {
callback(new Error(body));
}
});
}
Trello.prototype.addBoard = function (name, description, organizationId, callback) {
var query = this.createQuery();
query.name = name;
if (description !== null)
query.desc = description;
if (organizationId !== null)
query.idOrganization = organizationId;
makeRequest('POST', this.uri + '/1/boards', query, callback);
};
Trello.prototype.addCard = function (name, description, listId, callback) {
var query = this.createQuery();
query.name = name;
query.idList = listId;
if (description !== null)
query.desc = description;
makeRequest('POST', this.uri + '/1/cards', query, callback);
};
Trello.prototype.getCard = function (boardId, cardId, callback) {
makeRequest('GET', this.uri + '/1/boards/' + boardId + '/cards/' + cardId, this.createQuery(), callback);
};
Trello.prototype.getCardsForList = function(listId, actions, callback) {
var query = this.createQuery();
if (actions)
query.actions = actions;
makeRequest('GET', this.uri + '/1/lists/' + listId + '/cards', query, callback);
};
Trello.prototype.addListToBoard = function (boardId, name, callback) {
var query = this.createQuery();
query.name = name;
makeRequest('POST', this.uri + '/1/boards/' + boardId + '/lists', query, callback);
};
Trello.prototype.addCommentToCard = function (cardId, comment, callback) {
var query = this.createQuery();
query.text = comment;
makeRequest('POST', this.uri + '/1/cards/' + cardId + '/actions/comments', query, callback);
};
Trello.prototype.addMemberToCard = function (cardId, memberId, callback) {
var query = this.createQuery();
query.value = memberId;
makeRequest('POST', this.uri + '/1/cards/' + cardId + '/members', query, callback);
};
Trello.prototype.getBoardMembers = function (boardId, callback) {
makeRequest('GET', this.uri + '/1/boards/' + boardId + '/members', this.createQuery(), callback);
};
Trello.prototype.getListsOnBoard = function (boardId, callback) {
makeRequest('GET', this.uri + '/1/boards/' + boardId + '/lists', this.createQuery(), callback);
};
Trello.prototype.getListsOnBoardByFilter = function(boardId, filter, callback) {
var query = this.createQuery();
query.filter = filter;
makeRequest('GET', this.uri + '/1/boards/' + boardId + '/lists', query, callback);
};
Trello.prototype.getCardsOnBoard = function (boardId, callback) {
makeRequest('GET', this.uri + '/1/boards/' + boardId + '/cards', this.createQuery(), callback);
};
Trello.prototype.deleteCard = function (cardId, callback) {
makeRequest('DELETE', this.uri + '/1/cards/' + cardId, this.createQuery(), callback);
};
module.exports = Trello;