Skip to content

Commit 9be25ca

Browse files
committed
Merge branch 'master' into hashbang
2 parents 442e100 + c63b024 commit 9be25ca

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

testdata/retweet.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"created_at":"Sun Jun 03 18:15:29 +0000 2007","text":"\u041c\u043e\u0451 \u0441\u0443\u0434\u043d\u043e \u043d\u0430 \u0432\u043e\u0437\u0434\u0443\u0448\u043d\u043e\u0439 \u043f\u043e\u0434\u0443\u0448\u043a\u0435 \u043f\u043e\u043b\u043d\u043e \u0443\u0433\u0440\u0435\u0439","id":89512102,"user":{"name":"Kesuke Miyagi","description":"\u79c1\u306e\u30db\u30d0\u30fc\u30af\u30e9\u30d5\u30c8 \u306f\u9c3b\u304c\u4e00\u676f\u3067\u3059\u3002","location":"Okinawa, Japan","profile_image_url":"http://assets1.twitter.com/system/user/profile_image/718443/normal/kesuke.png?1169966399","url":null,"id":718443,"screen_name":"kesuke","protected":false}}

twitter.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2871,6 +2871,33 @@ def PostUpdates(self, status, continuation=None, **kwargs):
28712871
results.append(self.PostUpdate(lines[-1], **kwargs))
28722872
return results
28732873

2874+
def PostRetweet(self, original_id):
2875+
'''Retweet a tweet with the Retweet API.
2876+
2877+
The twitter.Api instance must be authenticated.
2878+
2879+
Args:
2880+
original_id:
2881+
The numerical id of the tweet that will be retweeted
2882+
Returns:
2883+
A twitter.Status instance representing the original tweet with retweet details embedded.
2884+
'''
2885+
if not self._oauth_consumer:
2886+
raise TwitterError("The twitter.Api instance must be authenticated.")
2887+
2888+
try:
2889+
if int(original_id) <= 0:
2890+
raise TwitterError("'original_id' must be a positive number")
2891+
except ValueError:
2892+
raise TwitterError("'original_id' must be an integer")
2893+
2894+
url = '%s/statuses/retweet/%s.json' % (self.base_url, original_id)
2895+
2896+
data = {'id': original_id}
2897+
json = self._FetchUrl(url, post_data=data)
2898+
data = self._ParseAndCheckTwitter(json)
2899+
return Status.NewFromJsonDict(data)
2900+
28742901
def GetUserRetweets(self, count=None, since_id=None, max_id=None, include_entities=False):
28752902
'''Fetch the sequence of retweets made by a single user.
28762903

twitter_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,13 @@ def testPostUpdate(self):
415415
# This is rather arbitrary, but spot checking is better than nothing
416416
self.assertEqual(u'Моё судно на воздушной подушке полно угрей', status.text)
417417

418+
def testPostRetweet(self):
419+
'''Test the twitter.Api PostRetweet method'''
420+
self._AddHandler('https://api.twitter.com/1/statuses/retweet/89512102.json',
421+
curry(self._OpenTestData, 'retweet.json'))
422+
status = self._api.PostRetweet(89512102)
423+
self.assertEqual(89512102, status.id)
424+
418425
def testPostUpdateLatLon(self):
419426
'''Test the twitter.Api PostUpdate method, when used in conjunction with latitude and longitude'''
420427
self._AddHandler('https://api.twitter.com/1/statuses/update.json',

0 commit comments

Comments
 (0)