Fix favorites methods. Retry request when enabled by defaults will retry on any non...
authorJosh Roesslein <jroesslein@gmail.com>
Wed, 14 Oct 2009 17:30:36 +0000 (12:30 -0500)
committerJosh Roesslein <jroesslein@gmail.com>
Wed, 14 Oct 2009 17:30:36 +0000 (12:30 -0500)
tweepy/api.py
tweepy/binder.py

index a0d73fa60d643ccf2faef80810e5e0212c058af6..c5c917dcf226e3c7f8f86347104b9452b80944bc 100644 (file)
@@ -16,7 +16,7 @@ class API(object):
 
     def __init__(self, auth_handler=None, host='twitter.com', cache=None,
             secure=False, api_root='', validate=True,
-            retry_count=0, retry_delay=0, retry_errors=[500,502,503]):
+            retry_count=0, retry_delay=0, retry_errors=None):
         # you may access these freely
         self.auth_handler = auth_handler
         self.host = host
@@ -692,13 +692,14 @@ class API(object):
 
         http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-favorites%C2%A0create
     """
-    create_favorite = bind_api(
-        path = '/favorites/create.json',
-        method = 'POST',
-        parser = parse_status,
-        allowed_param = ['id'],
-        require_auth = True
-    )
+    def create_favorite(self, id):
+        return bind_api(
+            path = '/favorites/create/%s.json' % id,
+            method = 'POST',
+            parser = parse_status,
+            allowed_param = ['id'],
+            require_auth = True
+        )(self, id)
 
     """ favorites/destroy
 
@@ -710,13 +711,14 @@ class API(object):
 
         http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-favorites%C2%A0destroy
     """
-    destroy_favorite = bind_api(
-        path = '/favorites/destroy.json',
-        method = 'DELETE',
-        parser = parse_status,
-        allowed_param = ['id'],
-        require_auth = True
-    )
+    def destroy_favorite(self, id):
+        return bind_api(
+            path = '/favorites/destroy/%s.json' % id,
+            method = 'DELETE',
+            parser = parse_status,
+            allowed_param = ['id'],
+            require_auth = True
+        )(self, id)
 
     """ notifications/follow
 
index 79865d621aa0291eb04bf97d56a1693da21eea18..9097d75d32b804875ccc67bd446d29b60870fc71 100644 (file)
@@ -112,8 +112,10 @@ def bind_api(path, parser, allowed_param=[], method='GET', require_auth=False,
             resp = conn.getresponse()
 
             # Exit request loop if non-retry error code
-            if resp.status not in retry_errors:
-                break
+            if retry_errors is None:
+                if resp.status == 200: break
+            else:
+                if resp.status not in retry_errors: break
 
             # Sleep before retrying request again
             time.sleep(retry_delay)