Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
152 lines (115 loc) · 5.09 KB
/
Copy pathmain.js
File metadata and controls
152 lines (115 loc) · 5.09 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
var rest = require('restler');
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(fn, uri, options, callback) {
fn(uri, options)
.on('complete', function (result) {
if (result instanceof Error) {
callback(result);
} else {
callback(null, result);
}
});
}
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(rest.post, this.uri + '/1/boards', {query: 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(rest.post, this.uri + '/1/cards', {query: query}, callback);
};
Trello.prototype.getCard = function (boardId, cardId, callback) {
makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/cards/' + cardId, {query: this.createQuery()}, callback);
};
Trello.prototype.getCardsForList = function(listId, actions, callback) {
var query = this.createQuery();
if (actions)
query.actions = actions;
makeRequest(rest.get, this.uri + '/1/lists/' + listId + '/cards', {query: query}, callback);
};
Trello.prototype.addListToBoard = function (boardId, name, callback) {
var query = this.createQuery();
query.name = name;
makeRequest(rest.post, this.uri + '/1/boards/' + boardId + '/lists', {query: query}, callback);
};
Trello.prototype.addCommentToCard = function (cardId, comment, callback) {
var query = this.createQuery();
query.text = comment;
makeRequest(rest.post, this.uri + '/1/cards/' + cardId + '/actions/comments', {query: query}, callback);
};
Trello.prototype.addMemberToCard = function (cardId, memberId, callback) {
var query = this.createQuery();
query.value = memberId;
makeRequest(rest.post, this.uri + '/1/cards/' + cardId + '/members', {query: query}, callback);
};
Trello.prototype.getBoards = function(memberId, callback) {
makeRequest(rest.get, this.uri + '/1/members/' + memberId + '/boards', {query: this.createQuery()}, callback);
};
Trello.prototype.addItemToChecklist = function (checkListId, name, callback) {
var query = this.createQuery();
query.name = name;
makeRequest(rest.post, this.uri + '/1/checklists/' + checkListId + '/checkitems', {query: query}, callback);
}
Trello.prototype.updateCard = function (cardId, field, value, callback) {
var query = this.createQuery();
query.value = value;
makeRequest(rest.put, this.uri + '/1/cards/' + cardId + '/' + field, {query: query}, callback);
}
Trello.prototype.updateCardName = function (cardId, name, callback) {
this.updateCard(cardId, 'name', name, callback);
}
Trello.prototype.updateCardDescription = function (cardId, description, callback) {
this.updateCard(cardId, 'desc', description, callback);
}
Trello.prototype.updateCardList = function (cardId, listId, callback) {
this.updateCard(cardId, 'idList', listId, callback);
}
Trello.prototype.getBoardMembers = function (boardId, callback) {
makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/members', {query: this.createQuery()}, callback);
};
Trello.prototype.getListsOnBoard = function (boardId, callback) {
makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/lists', {query: this.createQuery()}, callback);
};
Trello.prototype.getListsOnBoardByFilter = function(boardId, filter, callback) {
var query = this.createQuery();
query.filter = filter;
makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/lists', {query: query}, callback);
};
Trello.prototype.getCardsOnBoard = function (boardId, callback) {
makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/cards', {query: this.createQuery()}, callback);
};
Trello.prototype.getCardsOnList = function (listId, callback) {
makeRequest(rest.get, this.uri + '/1/lists/' + listId + '/cards', {query: this.createQuery()}, callback);
}
Trello.prototype.deleteCard = function (cardId, callback) {
makeRequest(rest.del, this.uri + '/1/cards/' + cardId, {query: this.createQuery()}, callback);
};
Trello.prototype.addWebhook = function (description, callbackUrl, idModel, callback) {
var query = this.createQuery();
var data = {};
data.description = description;
data.callbackURL = callbackUrl;
data.idModel = idModel;
makeRequest(rest.post, this.uri + '/1/tokens/' + this.token + '/webhooks/', { data: data, query: query }, callback);
};
Trello.prototype.deleteWebhook = function (webHookId, callback) {
var query = this.createQuery();
makeRequest(rest.del, this.uri + '/1/webhooks/' + webHookId, { query: query }, callback);
};
module.exports = Trello;