-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwunderlist.py
51 lines (37 loc) · 1.34 KB
/
wunderlist.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
import requests
class WunderApi(object):
BASE_URL = 'https://a.wunderlist.com/api/v1'
def __init__(self, access_token, client_id):
self.headers = {
'X-Access-Token' : access_token,
'X-Client-ID' : client_id
}
def result(self, request):
if request.status_code == 200: return request.json()
else: return request.text
def get_lists(self):
url = '/'.join([self.BASE_URL, 'lists'])
r = requests.get(url, headers=self.headers)
return self.result(r)
def get_tasks(self, list_id):
url = '/'.join([self.BASE_URL, 'tasks']) + '?list_id=%d' % list_id
r = requests.get(url, headers=self.headers)
return self.result(r)
def create_task(self, list_id, title):
url = '/'.join([self.BASE_URL, 'tasks'])
payload = {
'list_id': list_id,
'title': title,
'pos': 'top'
}
r = requests.post(url, json=payload, headers=self.headers)
return self.result(r)
def update_task(self, task_id, task_revision, title=None, starred=None, completed=None):
url = '/'.join([self.BASE_URL, 'tasks', task_id])
payload = {}
payload['revision'] = task_revision
if title: payload['title'] = title
if starred: payload['starred'] = starred
if completed: payload['completed'] = completed
r = requests.patch(url, json=payload, headers=self.headers)
return self.result(r)