Trello » TrelloSimple A very simple helper for the Trello API in Python Read More
Clone URL:  
Pushed to one repository · View In Graph Contained in tip

tip Add proxy exmample (fiddler) and add scope_override option to explicitly set the scope.

Changeset eeef45bd880a

Parent 449230ad6594

by Profile picture of User 476Ben McCormack <benm@fogcreek.com>

Changes to one file · Browse files at eeef45bd880a Showing diff from parent 449230ad6594 Diff from another changeset...

Change 1 of 1 Show Changes Only trelloSimple.py Stacked
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
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
 try:   import simplejson as json  except ImportError:   import json  import requests  from urllib import quote_plus    class TrelloSimple(object):   def __init__(self, apikey, token=None):   self._apikey = apikey   self._token = token   self._apiversion = 1   self._proxies = None     def set_token(self, token):   self._token = token     def set_proxy(self, proxies): + '''e.g. proxies={'https':'127.0.0.1:8888'}'''   self._proxies = proxies   - def get_token_url(self, app_name, expires='30days', write_access=True): - return 'https://trello.com/1/authorize?key=%s&name=%s&expiration=%s&response_type=token&scope=%s' % (self._apikey, quote_plus(app_name), expires, 'read,write' if write_access else 'read') + def get_token_url(self, app_name, expires='30days', write_access=True, scope_override = ''): + scope = '' + if scope_override != '': + scope = scope_override + else: + scope = 'read,write' if write_access else 'read' + return 'https://trello.com/1/authorize?key=%s&name=%s&expiration=%s&response_type=token&scope=%s' % (self._apikey, quote_plus(app_name), expires, scope)     def get(self, urlPieces, arguments = None):   return self._http_action('get',urlPieces, arguments)     def put(self, urlPieces, arguments = None, files=None):   return self._http_action('put',urlPieces, arguments,files)     def post(self, urlPieces, arguments = None, files=None):   return self._http_action('post',urlPieces, arguments,files)     def delete(self, urlPieces, arguments = None):   return self._http_action('delete',urlPieces, arguments)     def _http_action(self, method, urlPieces, arguments = None, files=None):   #If the user wants to pass in a formatted string for urlPieces, just use   #the string. Otherwise, assume we have a list of strings and join with /.   if not isinstance(urlPieces, basestring):   urlPieces = '/'.join(urlPieces)   baseUrl = 'https://trello.com/%s/%s' % (self._apiversion, urlPieces)     params = {'key':self._apikey,'token':self._token}     if method in ['get','delete'] and arguments:   params = dict(params.items() + arguments.items())   if method == 'get':   resp = requests.get(baseUrl,params=params, proxies=self._proxies)   elif method == 'delete':   resp = requests.delete(baseUrl,params=params, proxies=self._proxies)   elif method == 'put':   resp = requests.put(baseUrl,params=params,data=arguments, proxies=self._proxies,files=files)   elif method == 'post':   resp = requests.post(baseUrl,params=params,data=arguments, proxies=self._proxies, files=files)     resp.raise_for_status()   return json.loads(resp.content)