pairs = ''.join(['%s%s' % (k, v) for (k, v) in sortedItems(params)])
return md5(self._secret+pairs).hexdigest()
+ @staticmethod
+ def open_url(url, queryArgs=None):
+ if queryArgs:
+ url += '?' + urllib.urlencode(queryArgs)
+ warnings.warn("Performing download of %s" % url, stacklevel=5)
+ return urllib.urlopen(url)
+
def get(self, **params):
"Get the XML response for the passed `params`."
params['api_key'] = self._apiKey
params['format'] = 'json'
params['api_sig'] = self._sign(params)
- json = openURL(SERVICE_URL, params).read()
+ json = self.open_url(SERVICE_URL, params).read()
if _use_simplejson:
- data = dottedDict('ROOT', simplejson.loads(json))
+ data = DottedDict('ROOT', simplejson.loads(json))
else:
- data = dottedJSON(json)
+ data = DottedDict('ROOT', safer_eval(json))
rsp = data.rsp
if rsp.stat == 'fail':
yield key, dictionary[key]
-def openURL(url, queryArgs=None):
- if queryArgs:
- url = url + '?' + urllib.urlencode(queryArgs)
- return urllib.urlopen(url)
-
-
-class dottedDict(object):
+class DottedDict(object):
"Make dictionary items accessible via the object-dot notation."
def __init__(self, name, dictionary):
if isinstance(dictionary, dict):
for key, value in dictionary.items():
if isinstance(value, dict):
- value = dottedDict(key, value)
+ value = DottedDict(key, value)
elif isinstance(value, (list, tuple)):
- value = [dottedDict('%s_%d' % (key, i), item)
+ value = [DottedDict('%s_%d' % (key, i), item)
for i, item in enumerate(value)]
setattr(self, key, value)
)
-def safeEval(string):
+def safer_eval(string):
return eval(string, {}, {})
-def dottedJSON(json):
- return dottedDict('ROOT', safeEval(json))
-
-
API = {
'auth': {
'checkToken':
[(), ()],
'getToken':
[('frob'), ()]
- },
+ },
'contacts': {
'add':
[('timeline', 'contact'), ()],
'delete':
[('timeline', 'contact_id'), ()],
'getList':
- [(), ()]
- },
+ [(), ()],
+ },
'groups': {
'add':
[('timeline', 'group'), ()],
[(), ()],
'removeContact':
[('timeline', 'group_id', 'contact_id'), ()],
- },
+ },
'lists': {
'add':
[('timeline', 'name'), ('filter'), ()],
[('timeline', 'list_id', 'name'), ()],
'unarchive':
[('timeline'), ('list_id'), ()],
- },
+ },
'locations': {
'getList':
- [(), ()]
- },
+ [(), ()],
+ },
'reflection': {
'getMethodInfo':
[('methodName',), ()],
'getMethods':
- [(), ()]
- },
+ [(), ()],
+ },
'settings': {
'getList':
- [(), ()]
- },
+ [(), ()],
+ },
'tasks': {
'add':
[('timeline', 'name',), ('list_id', 'parse',)],
'uncomplete':
[('timeline', 'list_id', 'taskseries_id', 'task_id'),
()],
- },
+ },
'tasksNotes': {
'add':
[('timeline', 'list_id', 'taskseries_id', 'task_id', 'note_title', 'note_text'), ()],
'delete':
[('timeline', 'note_id'), ()],
'edit':
- [('timeline', 'note_id', 'note_title', 'note_text'), ()]
- },
+ [('timeline', 'note_id', 'note_title', 'note_text'), ()],
+ },
'test': {
'echo':
[(), ()],
'login':
- [(), ()]
- },
+ [(), ()],
+ },
'time': {
'convert':
[('to_timezone',), ('from_timezone', 'to_timezone', 'time')],
'parse':
- [('text',), ('timezone', 'dateformat')]
- },
+ [('text',), ('timezone', 'dateformat')],
+ },
'timelines': {
'create':
- [(), ()]
- },
+ [(), ()],
+ },
'timezones': {
'getList':
- [(), ()]
- },
+ [(), ()],
+ },
'transactions': {
'undo':
- [('timeline', 'transaction_id'), ()]
- },
- }
+ [('timeline', 'transaction_id'), ()],
+ },
+}