]> jfr.im git - z_archive/twitter.git/commitdiff
Merge https://github.com/sixohsix/twitter into pr-rouxrc
authorRouxRC <redacted>
Mon, 3 Feb 2014 22:54:37 +0000 (23:54 +0100)
committerRouxRC <redacted>
Mon, 3 Feb 2014 22:54:37 +0000 (23:54 +0100)
twitter/api.py
twitter/ircbot.py
twitter/twitter_globals.py

index 42068c69bd2e5bd280234ef71a969fbe2332e1cb..f3ba89f24c7d8d7fab88dcb01da6fcee942813fd 100644 (file)
@@ -196,16 +196,45 @@ class TwitterCall(object):
         uriBase = "http%s://%s/%s%s%s" %(
                     secure_str, self.domain, uri, dot, self.format)
 
+        # Catch media arguments to handle oauth query differently for multipart
+        media = None
+        for arg in ['media[]', 'banner', 'image']:
+            if arg in kwargs:
+                media = kwargs.pop(arg)
+                mediafield = arg
+                break
+
         headers = {'Accept-Encoding': 'gzip'} if self.gzip else dict()
         body = None; arg_data = None
         if self.auth:
             headers.update(self.auth.generate_headers())
-            arg_data = self.auth.encode_params(uriBase, method, kwargs)
-            if method == 'GET':
+            # Use urlencoded oauth args with no params when sending media
+            # via multipart and send it directly via uri even for post
+            arg_data = self.auth.encode_params(uriBase, method,
+                {} if media else kwargs )
+            if method == 'GET' or media:
                 uriBase += '?' + arg_data
             else:
                 body = arg_data.encode('utf8')
 
+        # Handle query as multipart when sending media
+        if media:
+            BOUNDARY = "###Python-Twitter###"
+            bod = []
+            bod.append('--' + BOUNDARY)
+            bod.append('Content-Disposition: form-data; name="%s"' %
+                mediafield)
+            bod.append('')
+            bod.append(media)
+            for k, v in kwargs.items():
+                bod.append('--' + BOUNDARY)
+                bod.append('Content-Disposition: form-data; name="%s"' % k)
+                bod.append('')
+                bod.append(v)
+            bod.append('--' + BOUNDARY + '--')
+            body = '\r\n'.join(bod)
+            headers['Content-Type'] = 'multipart/form-data; boundary=%s' % BOUNDARY
+
         req = urllib_request.Request(uriBase, body, headers)
         return self._handle_response(req, uri, arg_data, _timeout)
 
index 9113377be20443374a65eb3e875c17d110df7a65..e683316a72e61f92ac676f56201f84a11346e90a 100644 (file)
@@ -148,7 +148,6 @@ class TwitterBot(object):
         self.twitter = Twitter(
             auth=OAuth(
                 oauth_token, oauth_secret, CONSUMER_KEY, CONSUMER_SECRET),
-            api_version='1',
             domain='api.twitter.com')
 
         self.irc = irclib.IRC()
@@ -255,7 +254,7 @@ class TwitterBot(object):
                 "%sI'm already following %s." %(get_prefix('error'), name))
         else:
             try:
-                self.twitter.friendships.create(id=name)
+                self.twitter.friendships.create(screen_name=name)
             except TwitterError:
                 conn.privmsg(
                     userNick,
@@ -279,7 +278,7 @@ class TwitterBot(object):
                 userNick,
                 "%sI'm not following %s." %(get_prefix('error'), name))
         else:
-            self.twitter.friendships.destroy(id=name)
+            self.twitter.friendships.destroy(screen_name=name)
             conn.privmsg(
                 userNick,
                 "%sOkay! I've stopped following %s." %(
index 999625597b41ca850917c69611e85a3bf377b982..d7572ee06e2a1578109a4f727176ca4122b32542 100644 (file)
@@ -8,7 +8,7 @@
 POST_ACTIONS = [
 
     # Status Methods
-    'update', 'retweet',
+    'update', 'retweet', 'update_with_media',
 
     # Direct Message Methods
     'new',