From 7de2d6204028b6741ce7a72b12efe868e074331c Mon Sep 17 00:00:00 2001 From: Wynn Netherland Date: Sat, 20 Mar 2010 12:05:15 -0500 Subject: [PATCH] Added support for new retweeted_by and retweeted_by ids API methods --- lib/twitter/base.rb | 6 + test/fixtures/retweeters_of_tweet.json | 166 +++++++++++++++++++++++++ test/twitter/base_test.rb | 14 +++ 3 files changed, 186 insertions(+) create mode 100644 test/fixtures/retweeters_of_tweet.json diff --git a/lib/twitter/base.rb b/lib/twitter/base.rb index 37a896490..89a1e7929 100644 --- a/lib/twitter/base.rb +++ b/lib/twitter/base.rb @@ -68,6 +68,12 @@ def retweeted_to_me(query={}) def retweets_of_me(query={}) perform_get("/#{API_VERSION}/statuses/retweets_of_me.json", :query => query) end + + # options: count, page, ids_only + def retweeters_of(id, options={}) + ids_only = !!(options.delete(:ids_only)) + perform_get("/#{API_VERSION}/statuses/#{id}/retweeted_by#{"/ids" if ids_only}.json", :query => options, :mash => !ids_only) + end def status_destroy(id) perform_post("/#{API_VERSION}/statuses/destroy/#{id}.json") diff --git a/test/fixtures/retweeters_of_tweet.json b/test/fixtures/retweeters_of_tweet.json new file mode 100644 index 000000000..e47e46b64 --- /dev/null +++ b/test/fixtures/retweeters_of_tweet.json @@ -0,0 +1,166 @@ +[ +{ + "contributors_enabled": false, + "created_at": "Thu Jan 18 12:47:55 +0000 2007", + "description": "You ever get an itch on your back you can't scratch?", + "favourites_count": 24, + "followers_count": 1389, + "following": null, + "friends_count": 528, + "geo_enabled": false, + "id": 659933, + "lang": "en", + "location": "Baltimore, MD", + "name": "Bryan Liles (\u30c4)", + "notifications": null, + "profile_background_color": "585858", + "profile_background_image_url": "http://a3.twimg.com/profile_background_images/3252365/twitter-bg.png", + "profile_background_tile": false, + "profile_image_url": "http://a1.twimg.com/profile_images/71274618/Photo_26_normal.jpg", + "profile_link_color": "030005", + "profile_sidebar_border_color": "141617", + "profile_sidebar_fill_color": "F8F8F8", + "profile_text_color": "000000", + "protected": false, + "screen_name": "bryanl", + "status": { + "created_at": "Sat Mar 20 12:38:08 +0000 2010", + "favorited": false, + "id": 10770771392, + "in_reply_to_screen_name": "invalidrecord", + "in_reply_to_status_id": 10770727390, + "in_reply_to_user_id": 14143472, + "source": "Echofon", + "text": "@invalidrecord really? you've seen one? wow ;)", + "truncated": false + }, + "statuses_count": 6899, + "time_zone": "Eastern Time (US & Canada)", + "url": "http://smartic.us", + "utc_offset": -18000, + "verified": false +}, +{ + "contributors_enabled": false, + "created_at": "Tue Jan 27 00:34:57 +0000 2009", + "description": "Web dev guy by day. Corny joke, photography, vinyl and heavy metal music fan. Battery operated hamster enthusiast. I need more hobbies. What are yours?", + "favourites_count": 7, + "followers_count": 116, + "following": null, + "friends_count": 174, + "geo_enabled": false, + "id": 19568588, + "lang": "en", + "location": "Victoria, BC, Canada", + "name": "Jonathon Watney", + "notifications": null, + "profile_background_color": "d1d1d1", + "profile_background_image_url": "http://s.twimg.com/a/1268699350/images/themes/theme5/bg.gif", + "profile_background_tile": false, + "profile_image_url": "http://a1.twimg.com/profile_images/690859908/gary_normal.jpg", + "profile_link_color": "990000", + "profile_sidebar_border_color": "b3b3b3", + "profile_sidebar_fill_color": "e6e6e6", + "profile_text_color": "454545", + "protected": false, + "screen_name": "jonathonwatney", + "status": { + "created_at": "Sat Mar 20 03:38:55 +0000 2010", + "favorited": false, + "id": 10756267124, + "in_reply_to_screen_name": null, + "in_reply_to_status_id": null, + "in_reply_to_user_id": null, + "source": "web", + "text": "RT @BrentO: Reason 1,357 why I still prefer XP over Win7: it doesn't give me crap when I edit the hosts file and save it.", + "truncated": false + }, + "statuses_count": 1240, + "time_zone": "Pacific Time (US & Canada)", + "url": null, + "utc_offset": -28800, + "verified": false +}, +{ + "contributors_enabled": false, + "created_at": "Thu May 08 15:53:12 +0000 2008", + "description": "Web dev'r, motorcyclist, gun shooter. Sometimes (er, most times) I talk about nerdy things.", + "favourites_count": 1, + "followers_count": 107, + "following": false, + "friends_count": 99, + "geo_enabled": false, + "id": 14701839, + "lang": "en", + "location": "Nebraska", + "name": "Adam Jahnke", + "notifications": false, + "profile_background_color": "6FB433", + "profile_background_image_url": "http://a1.twimg.com/profile_background_images/3202932/bg_2.png", + "profile_background_tile": false, + "profile_image_url": "http://a3.twimg.com/profile_images/566612101/IMG_5256w_normal.jpg", + "profile_link_color": "000000", + "profile_sidebar_border_color": "696969", + "profile_sidebar_fill_color": "6FB433", + "profile_text_color": "454545", + "protected": false, + "screen_name": "adamyonk", + "status": { + "created_at": "Fri Mar 19 21:18:55 +0000 2010", + "favorited": false, + "id": 10741609904, + "in_reply_to_screen_name": null, + "in_reply_to_status_id": null, + "in_reply_to_user_id": null, + "source": "twidroid", + "text": "Sorry to anyone trying to contact me via chat today. Having some connectivity issues.", + "truncated": false + }, + "statuses_count": 1443, + "time_zone": "Central Time (US & Canada)", + "url": "http://adamyonk.com", + "utc_offset": -21600, + "verified": false +}, +{ + "contributors_enabled": false, + "created_at": "Sat Jul 26 06:44:07 +0000 2008", + "description": null, + "favourites_count": 0, + "followers_count": 50, + "following": false, + "friends_count": 52, + "geo_enabled": false, + "id": 15608533, + "lang": "en", + "location": "buzzd: 33.019368,-96.700780", + "name": "Ein2015", + "notifications": false, + "profile_background_color": "1A1B1F", + "profile_background_image_url": "http://s.twimg.com/a/1268687377/images/themes/theme9/bg.gif", + "profile_background_tile": false, + "profile_image_url": "http://a1.twimg.com/profile_images/57259620/galactica_avatar_msn_057_normal.jpg", + "profile_link_color": "2FC2EF", + "profile_sidebar_border_color": "181A1E", + "profile_sidebar_fill_color": "252429", + "profile_text_color": "666666", + "protected": false, + "screen_name": "Ein2015", + "status": { + "created_at": "Sun Mar 14 06:30:45 +0000 2010", + "favorited": false, + "id": 10459323128, + "in_reply_to_screen_name": null, + "in_reply_to_status_id": null, + "in_reply_to_user_id": null, + "source": "Loopt", + "text": "Feel free to come if you want. @ Cairo Hookah Lounge http://loopt.us/YYGRHw.t", + "truncated": false + }, + "statuses_count": 229, + "time_zone": "Central Time (US & Canada)", + "url": null, + "utc_offset": -21600, + "verified": false +} +] \ No newline at end of file diff --git a/test/twitter/base_test.rb b/test/twitter/base_test.rb index 8a475b423..be54404ba 100644 --- a/test/twitter/base_test.rb +++ b/test/twitter/base_test.rb @@ -127,6 +127,20 @@ class BaseTest < Test::Unit::TestCase first.user.name.should == 'Michael D. Ivey' first.text.should == "Trying out geotweets in Birdfeed. No \"new RT\" support, though. Any iPhone client with RTs yet?" end + + should "be able to get users who retweeted a tweet" do + stub_get('/1/statuses/9021932472/retweeted_by.json', 'retweeters_of_tweet.json') + retweeters = @twitter.retweeters_of("9021932472") + retweeters.size.should == 4 + first = retweeters.first + first.screen_name.should == 'bryanl' + end + + should "be able to get ids of users who retweeted a tweet" do + stub_get('/1/statuses/9021932472/retweeted_by/ids.json', 'ids.json') + retweeters = @twitter.retweeters_of("9021932472", :ids_only => true) + retweeters.first.should == 61940910 + end should "be able to get follower ids" do stub_get('/1/followers/ids.json', 'follower_ids.json')