]> jfr.im git - z_archive/twitter.git/commitdiff
Merge in Hatem's twitter_agent branch.
authorMike Verdone <redacted>
Sun, 15 Feb 2009 21:35:28 +0000 (14:35 -0700)
committerMike Verdone <redacted>
Sun, 15 Feb 2009 21:35:28 +0000 (14:35 -0700)
1  2 
twitter/api.py

diff --cc twitter/api.py
index e22fb468e15b770cdf1d096bd830ca55fa8341e2,1334e438155935a6db453181463e63a8ab9d55fb..02274c650e8c6828ef49b218f7d5ed7a5b99ef00
@@@ -22,13 -22,11 +22,16 @@@ class TwitterError(Exception)
      """
      pass
  
 +# These actions require POST http requests instead of GET
 +_POST_ACTIONS = [
 +    "create", "update", "destroy", "new", "follow", "leave",
 +    ]
 +
  class TwitterCall(object):
-     def __init__(self, username, password, format, domain, uri=""):
+     def __init__(
+         self, username, password, format, domain, uri="",
+         agent="Python Twitter Tools"
+     ):
          self.username = username
          self.password = password
          self.format = format
          except AttributeError:
              return TwitterCall(
                  self.username, self.password, self.format, self.domain,
-                 self.uri + "/" + k)
+                 self.uri + "/" + k, self.agent
+             )
      def __call__(self, **kwargs):
 +        uri = self.uri
          method = "GET"
 -        if (self.uri.endswith('new') 
 -            or self.uri.endswith('update')
 -            or self.uri.endswith('create')
 -            or self.uri.endswith('destroy')):
 -            method = "POST"
 +        for action in _POST_ACTIONS:
 +            if self.uri.endswith(action):
 +                method = "POST"
 +                break
+             if (self.agent):
+                 kwargs["source"] = self.agent
          
 +        id = kwargs.pop('id', None)
 +        if id:
 +            uri += "/%s" %(id)
 +            
          encoded_kwargs = urlencode(kwargs.items())
          argStr = ""
          if kwargs and (method == "GET"):