-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrello_api.py
172 lines (145 loc) · 4.49 KB
/
trello_api.py
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import requests
import os
import json
import pprint
import requests
from .trello_card import TrelloCard
from .trello_list import TrelloList
from .exceptions import StatusCodeError
class TrelloAPI:
def __init__(self, token, key, secret):
self.token = token
self.key = key
self.secret = secret
self.base_url = "https://api.trello.com/1"
def test_create_card(self, id_list):
url = f"{self.base_url}/cards"
query = {
"idList": id_list,
"key": self.key,
"token": self.token,
}
response = requests.post(url, params=query)
if response.status_code == 200:
return response.json()
else:
raise StatusCodeError(response.status_code)
def get_boards(self):
url = f"{self.base_url}/members/me/boards"
query = {
"key": self.key,
"token": self.token
}
response = requests.get(url, params=query)
if response.status_code == 200:
return response.json()
else:
raise StatusCodeError(response.status_code)
def get_board(self, board_id):
url = f"{self.base_url}/boards/{board_id}"
headers = {
"Accept": "application/json"
}
query = {
"key": self.key,
"token": self.token
}
response = requests.get(url, headers=headers, params=query)
if response.status_code == 200:
return response.json()
else:
print(response.status_code)
print(response.text)
return False
def get_lists(self, board_id):
url = f"{self.base_url}/boards/{board_id}/lists"
query = {
"key": self.key,
"token": self.token
}
response = requests.get(url, params=query)
if response.status_code == 200:
return response.json()
else:
return False
def update_board_description(self, board_id, description):
url = f"{self.base_url}/boards/{board_id}"
query = {
"key": self.key,
"token": self.token,
"desc": description
}
response = requests.put(url, params=query)
if response.status_code == 200:
return response.json()
else:
print(response.status_code)
print(response.text)
return False
def update_card_description(self, card_id, description):
url = f"{self.base_url}/cards/{card_id}"
query = {
"key": self.key,
"token": self.token,
"desc": description
}
response = requests.put(url, params=query)
if response.status_code == 200:
return response.json()
else:
print(response.status_code)
print(response.text)
return False
def get_organization(self, org_id):
url = f"{self.base_url}/organizations/{org_id}"
query = {
"key": self.key,
"token": self.token
}
response = requests.get(url, params=query)
if response.status_code == 200:
return response.json()
else:
return False
def get_cards(self, board_id):
url = f"{self.base_url}/boards/{board_id}/cards"
query = {
"key": self.key,
"token": self.token
}
response = requests.get(url, params=query)
if response.status_code == 200:
return response.json()
else:
print(response.status_code)
print(response.text)
return False
def create_card(self, list_id, name, desc):
url = f"{self.base_url}/cards/"
headers = {
"Accept": "application/json"
}
query = {
"idList": list_id,
"key": self.key,
"token": self.token,
"name": name,
"desc": desc
}
response = requests.post(url, headers=headers, params=query)
if response.status_code == 200:
print(response)
return True
else:
print(response.status_code)
print(response.text)
return False
def create_board(self):
url = f"{self.base_url}/boards/"
query = {
"name": "Test Board",
"key": self.key,
"token": self.token
}
response = requests.post(url, params=query)
return response.json()