Adding little cleanups here or there to the raw API wrapper
[doneit] / src / rtmapi.py
index 0525805..e8f0183 100644 (file)
@@ -84,12 +84,12 @@ class RTMapi(object):
                params['format'] = 'json'
                params['api_sig'] = self._sign(params)
 
-               json = openURL(SERVICE_URL, params).read()
+               json = 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':
@@ -168,13 +168,13 @@ def sortedItems(dictionary):
                yield key, dictionary[key]
 
 
-def openURL(url, queryArgs=None):
+def open_url(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):
@@ -183,9 +183,9 @@ class dottedDict(object):
                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)
 
@@ -205,14 +205,10 @@ class dottedDict(object):
                )
 
 
-def safeEval(string):
+def safer_eval(string):
        return eval(string, {}, {})
 
 
-def dottedJSON(json):
-       return dottedDict('ROOT', safeEval(json))
-
-
 API = {
        'auth': {
                'checkToken':
@@ -221,15 +217,15 @@ API = {
                        [(), ()],
                'getToken':
                        [('frob'), ()]
-               },
+       },
        'contacts': {
                'add':
                        [('timeline', 'contact'), ()],
                'delete':
                        [('timeline', 'contact_id'), ()],
                'getList':
-                       [(), ()]
-               },
+                       [(), ()],
+       },
        'groups': {
                'add':
                        [('timeline', 'group'), ()],
@@ -241,7 +237,7 @@ API = {
                        [(), ()],
                'removeContact':
                        [('timeline', 'group_id', 'contact_id'), ()],
-               },
+       },
        'lists': {
                'add':
                        [('timeline', 'name'), ('filter'), ()],
@@ -257,21 +253,21 @@ API = {
                        [('timeline', 'list_id', 'name'), ()],
                'unarchive':
                        [('timeline'), ('list_id'), ()],
-               },
+       },
        'locations': {
                'getList':
-                       [(), ()]
-               },
+                       [(), ()],
+       },
        'reflection': {
                'getMethodInfo':
                        [('methodName',), ()],
                'getMethods':
-                       [(), ()]
-               },
+                       [(), ()],
+       },
        'settings': {
                'getList':
-                       [(), ()]
-               },
+                       [(), ()],
+       },
        'tasks': {
                'add':
                        [('timeline', 'name',), ('list_id', 'parse',)],
@@ -324,37 +320,37 @@ API = {
                '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'), ()],
+       },
+}