diff --git a/lib/twitter/client/user.rb b/lib/twitter/client/user.rb index 4ef7c137c..4b6c1aa27 100644 --- a/lib/twitter/client/user.rb +++ b/lib/twitter/client/user.rb @@ -237,6 +237,44 @@ def recommendations(options={}) response = get('users/recommendations', options) format.to_s.downcase == 'xml' ? response['userrecommendations'] : response end + + # Returns users the specified user can contribute to. + # + # @see http://dev.twitter.com/docs/api/1/get/users/contributees + # @rate_limited Yes + # @requires_authentication No unless requesting it from a protected user + # + # If getting this data of a protected user, you must authenticate (and be allowed to see that user). + # @response_format `json` + # @response_format `xml` + # @overload contributees(options={}) + # @param options [Hash] A customizable set of options. + # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1. + # @option options [Boolean, String, Integer] :skip_status Do not include contributee's statuses when set to true, 't' or 1. + # @return [Array] + # @example Return the authenticated user's contributees + # Twitter.contributees + ## @overload contributees(user, options={}) + # @param user [Integer, String] A Twitter user ID or screen name. + # @param options [Hash] A customizable set of options. + # @option options [Boolean, String, Integer] :include_entities Include {http://dev.twitter.com/pages/tweet_entities Tweet Entities} when set to true, 't' or 1. + # @option options [Boolean, String, Integer] :skip_status Do not include contributee's statuses when set to true, 't' or 1. + # @return [Array] + # @example Return users @sferik can contribute to + # Twitter.contributees("sferik") + # Twitter.contributees(7505382) # Same as above + def contributees(*args) + options = {} + options.merge!(args.last.is_a?(Hash) ? args.pop : {}) + user = args.pop || get_screen_name + if user + merge_user_into_options!(user, options) + response = get('users/contributees', options) + else + response = get('users/contributees', options) + end + format.to_s.downcase == 'xml' ? response['users'] : response + end end end end diff --git a/spec/fixtures/contributees.json b/spec/fixtures/contributees.json new file mode 100644 index 000000000..d02c0e1e0 --- /dev/null +++ b/spec/fixtures/contributees.json @@ -0,0 +1 @@ +[{"time_zone":"Pacific Time (US & Canada)","protected":false,"profile_use_background_image":true,"name":"Twitter API","contributors_enabled":true,"created_at":"Wed May 23 06:01:13 +0000 2007","profile_background_color":"e8f2f7","expanded_url":null,"listed_count":9032,"profile_background_image_url":"http:\/\/a2.twimg.com\/profile_background_images\/229557229\/twitterapi-bg.png","utc_offset":-28800,"description":"The Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website.","display_url":null,"verified":true,"profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1438634086\/avatar_normal.png","id_str":"6253282","entities":{"user_mentions":[],"urls":[],"hashtags":[]},"lang":"en","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/229557229\/twitterapi-bg.png","favourites_count":22,"profile_text_color":"437792","status":{"truncated":false,"created_at":"Sun Aug 21 15:47:24 +0000 2011","geo":null,"in_reply_to_user_id":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_to_status_id_str":null,"coordinates":null,"id_str":"105305005493452801","in_reply_to_screen_name":null,"in_reply_to_user_id_str":null,"place":null,"contributors":[819797],"retweeted":false,"retweet_count":27,"source":"web","id":105305005493452801,"text":"dev.twitter.com is still inaccessible from some locations. We're working to restore availability to everyone again. ^TS"},"default_profile":false,"friends_count":30,"profile_sidebar_fill_color":"a9d9f1","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1438634086\/avatar_normal.png","screen_name":"twitterapi","default_profile_image":false,"show_all_inline_media":false,"geo_enabled":true,"profile_background_tile":false,"location":"San Francisco, CA","notifications":null,"is_translator":false,"profile_link_color":"0094C2","url":"http:\/\/dev.twitter.com","id":6253282,"follow_request_sent":null,"statuses_count":3044,"following":null,"profile_sidebar_border_color":"0094C2","followers_count":633992},{"time_zone":"Pacific Time (US & Canada)","protected":true,"is_translator":false,"profile_use_background_image":true,"name":"teamteam","follow_request_sent":false,"statuses_count":490,"created_at":"Thu Jun 04 20:20:20 +0000 2009","profile_background_color":"C0DEED","expanded_url":null,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","utc_offset":-28800,"description":"Do more with less. ","display_url":null,"verified":false,"profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/323680542\/Bluebird_of_Happiness_normal.jpg","id_str":"44709792","entities":{"user_mentions":[],"urls":[],"hashtags":[]},"contributors_enabled":true,"lang":"en","favourites_count":18,"profile_text_color":"333333","listed_count":161,"profile_sidebar_fill_color":"DDEEF6","screen_name":"teamteam","default_profile":true,"profile_background_tile":false,"location":"Twitter","notifications":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","friends_count":633,"profile_link_color":"0084B4","url":"http:\/\/www.flickr.com\/photos\/twitteroffice","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/323680542\/Bluebird_of_Happiness_normal.jpg","id":44709792,"default_profile_image":false,"show_all_inline_media":false,"following":false,"geo_enabled":false,"profile_sidebar_border_color":"C0DEED","followers_count":433},{"time_zone":"Pacific Time (US & Canada)","protected":true,"profile_use_background_image":true,"name":"Shoutout","contributors_enabled":true,"created_at":"Sun Dec 27 19:22:01 +0000 2009","profile_background_color":"022330","expanded_url":null,"listed_count":61,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme15\/bg.png","utc_offset":-28800,"description":"Contribute your shoutouts to peeps.","display_url":null,"verified":false,"profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/597683385\/shout_normal.png","id_str":"99765600","entities":{"user_mentions":[],"urls":[],"hashtags":[]},"lang":"en","profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme15\/bg.png","favourites_count":8,"profile_text_color":"333333","friends_count":3,"profile_sidebar_fill_color":"C0DFEC","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/597683385\/shout_normal.png","screen_name":"twittershoutout","default_profile_image":false,"default_profile":false,"show_all_inline_media":false,"geo_enabled":true,"profile_background_tile":false,"location":"","notifications":false,"is_translator":false,"profile_link_color":"0084B4","url":"http:\/\/twitter.com","id":99765600,"follow_request_sent":false,"statuses_count":693,"following":false,"profile_sidebar_border_color":"a8c7f7","followers_count":336},{"time_zone":"Pacific Time (US & Canada)","protected":false,"is_translator":false,"profile_use_background_image":true,"name":"Anywhere","follow_request_sent":null,"statuses_count":31,"created_at":"Sun Oct 21 09:05:41 +0000 2007","profile_background_color":"022330","expanded_url":null,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme15\/bg.png","utc_offset":-28800,"description":"Here. There. Anywhere.","display_url":null,"verified":false,"profile_image_url":"http:\/\/a1.twimg.com\/profile_images\/754566723\/_anywhere_normal.png","id_str":"9576402","entities":{"user_mentions":[],"urls":[],"hashtags":[]},"contributors_enabled":true,"lang":"en","favourites_count":11,"profile_text_color":"333333","status":{"truncated":false,"created_at":"Tue Feb 01 05:28:46 +0000 2011","geo":null,"in_reply_to_user_id":null,"in_reply_to_status_id":null,"favorited":false,"possibly_sensitive":false,"in_reply_to_status_id_str":null,"coordinates":null,"id_str":"32309362097651712","in_reply_to_screen_name":null,"in_reply_to_user_id_str":null,"place":{"country_code":"US","name":"Ashbury Heights","attributes":{},"full_name":"Ashbury Heights, San Francisco","place_type":"neighborhood","country":"United States","bounding_box":{"type":"Polygon","coordinates":[[[-122.45778216,37.75932999],[-122.44248216,37.75932999],[-122.44248216,37.76752899],[-122.45778216,37.76752899]]]},"id":"866269c983527d5a","url":"http:\/\/api.twitter.com\/1\/geo\/id\/866269c983527d5a.json"},"contributors":[777925],"retweeted":false,"retweet_count":75,"source":"web","id":32309362097651712,"text":"Version 1.2 was released today. If you version locked to anything other than '1' you need to update now. Read more: http:\/\/t.co\/ACcUovI"},"listed_count":2246,"profile_sidebar_fill_color":"C0DFEC","screen_name":"anywhere","profile_background_tile":false,"location":"Twitter, HQ","notifications":null,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme15\/bg.png","default_profile":false,"friends_count":16,"profile_link_color":"0084B4","url":null,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/754566723\/_anywhere_normal.png","id":9576402,"default_profile_image":false,"show_all_inline_media":false,"following":null,"geo_enabled":true,"profile_sidebar_border_color":"a8c7f7","followers_count":47444},{"is_translator":false,"time_zone":"Alaska","protected":false,"follow_request_sent":false,"statuses_count":0,"profile_use_background_image":true,"name":"Geo Team","created_at":"Thu Jan 07 20:30:42 +0000 2010","profile_background_color":"C0DEED","expanded_url":null,"profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","utc_offset":-32400,"description":"All your lats and longs are belong to us","display_url":null,"contributors_enabled":true,"verified":false,"profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/622831073\/Geo-profile-icon_normal.png","id_str":"102782288","entities":{"user_mentions":[],"urls":[],"hashtags":[]},"listed_count":202,"lang":"en","favourites_count":0,"profile_text_color":"333333","profile_sidebar_fill_color":"DDEEF6","screen_name":"geo","profile_background_tile":false,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","location":"San Francisco, CA","notifications":false,"friends_count":0,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/622831073\/Geo-profile-icon_normal.png","default_profile_image":false,"default_profile":true,"show_all_inline_media":false,"geo_enabled":true,"profile_link_color":"0084B4","url":null,"id":102782288,"following":false,"profile_sidebar_border_color":"C0DEED","followers_count":3596},{"time_zone":null,"protected":false,"default_profile":true,"listed_count":98,"profile_use_background_image":true,"name":"Site Streams Beta","created_at":"Fri Aug 27 18:04:38 +0000 2010","profile_background_color":"C0DEED","expanded_url":null,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","utc_offset":null,"description":"Twitter Site Streams Beta Announcements. When reporting an issue, include account & UTC. You may DM critical outages.","display_url":null,"contributors_enabled":true,"verified":true,"friends_count":1,"profile_image_url":"http:\/\/a1.twimg.com\/profile_images\/1112022529\/api_normal.png","id_str":"183709371","entities":{"user_mentions":[],"urls":[],"hashtags":[]},"default_profile_image":false,"lang":"en","favourites_count":0,"profile_text_color":"333333","status":{"truncated":false,"created_at":"Thu Aug 18 19:39:20 +0000 2011","geo":null,"in_reply_to_user_id":null,"in_reply_to_status_id":null,"favorited":false,"in_reply_to_status_id_str":null,"coordinates":null,"id_str":"104276210699341825","in_reply_to_screen_name":null,"in_reply_to_user_id_str":null,"place":null,"contributors":[777925],"retweeted":false,"retweet_count":0,"source":"web","id":104276210699341825,"text":"For the moment we've stopped the rollout of the new SSL certificate for sitestreams. We'll tweet again when we resume."},"show_all_inline_media":false,"geo_enabled":false,"profile_sidebar_fill_color":"DDEEF6","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1112022529\/api_normal.png","screen_name":"sitestreams","is_translator":false,"profile_background_tile":false,"location":"San Francisco, CA","follow_request_sent":false,"notifications":false,"statuses_count":139,"profile_link_color":"0084B4","url":"http:\/\/twitter.com","id":183709371,"following":false,"profile_sidebar_border_color":"C0DEED","followers_count":2199}] \ No newline at end of file diff --git a/spec/fixtures/contributees.xml b/spec/fixtures/contributees.xml new file mode 100644 index 000000000..4ba1548f0 --- /dev/null +++ b/spec/fixtures/contributees.xml @@ -0,0 +1,348 @@ + + + + 6253282 + Twitter API + twitterapi + San Francisco, CA + The Real Twitter API. I tweet about API changes, service issues and happily answer questions about Twitter and our API. Don't get an answer? It's on my website. + http://a2.twimg.com/profile_images/1438634086/avatar_normal.png + https://si0.twimg.com/profile_images/1438634086/avatar_normal.png + http://dev.twitter.com + false + 633989 + e8f2f7 + 437792 + 0094C2 + a9d9f1 + 0094C2 + 30 + Wed May 23 06:01:13 +0000 2007 + 22 + -28800 + Pacific Time (US & Canada) + http://a2.twimg.com/profile_background_images/229557229/twitterapi-bg.png + https://si0.twimg.com/profile_background_images/229557229/twitterapi-bg.png + false + true + false + true + true + false + 3044 + en + true + false + 9032 + false + false + false + + + + + + + + false + + Sun Aug 21 15:47:24 +0000 2011 + 105305005493452801 + dev.twitter.com is still inaccessible from some locations. We're working to restore availability to everyone again. ^TS + web + false + false + + + + 25 + false + + + + + 819797 + + + + + 44709792 + teamteam + teamteam + Twitter + Do more with less. + http://a2.twimg.com/profile_images/323680542/Bluebird_of_Happiness_normal.jpg + https://si0.twimg.com/profile_images/323680542/Bluebird_of_Happiness_normal.jpg + http://www.flickr.com/photos/twitteroffice + true + 433 + C0DEED + 333333 + 0084B4 + DDEEF6 + C0DEED + 633 + Thu Jun 04 20:20:20 +0000 2009 + 18 + -28800 + Pacific Time (US & Canada) + http://a0.twimg.com/images/themes/theme1/bg.png + https://si0.twimg.com/images/themes/theme1/bg.png + false + true + false + false + false + false + 490 + en + true + false + 161 + false + true + false + + + + + + + + false + + + 99765600 + Shoutout + twittershoutout + + Contribute your shoutouts to peeps. + http://a2.twimg.com/profile_images/597683385/shout_normal.png + https://si0.twimg.com/profile_images/597683385/shout_normal.png + http://twitter.com + true + 336 + 022330 + 333333 + 0084B4 + C0DFEC + a8c7f7 + 3 + Sun Dec 27 19:22:01 +0000 2009 + 8 + -28800 + Pacific Time (US & Canada) + http://a0.twimg.com/images/themes/theme15/bg.png + https://si0.twimg.com/images/themes/theme15/bg.png + false + true + + true + false + + 693 + en + true + + 61 + false + false + false + + + + + + + + false + + + 9576402 + Anywhere + anywhere + Twitter, HQ + Here. There. Anywhere. + http://a1.twimg.com/profile_images/754566723/_anywhere_normal.png + https://si0.twimg.com/profile_images/754566723/_anywhere_normal.png + + false + 47444 + 022330 + 333333 + 0084B4 + C0DFEC + a8c7f7 + 16 + Sun Oct 21 09:05:41 +0000 2007 + 11 + -28800 + Pacific Time (US & Canada) + http://a0.twimg.com/images/themes/theme15/bg.png + https://si0.twimg.com/images/themes/theme15/bg.png + false + true + false + true + false + false + 31 + en + true + false + 2246 + false + false + false + + + + + + + + false + + Tue Feb 01 05:28:46 +0000 2011 + 32309362097651712 + Version 1.2 was released today. If you version locked to anything other than '1' you need to update now. Read more: http://t.co/ACcUovI + web + false + false + + + + 75 + false + + + + 866269c983527d5a + Ashbury Heights + Ashbury Heights, San Francisco + neighborhood + http://api.twitter.com/1/geo/id/866269c983527d5a.json + + + 37.75932999 -122.45778216 37.75932999 -122.44248216 37.76752899 -122.44248216 37.76752899 -122.45778216 + + United States + + false + + 777925 + + + + + 102782288 + Geo Team + geo + San Francisco, CA + All your lats and longs are belong to us + http://a2.twimg.com/profile_images/622831073/Geo-profile-icon_normal.png + https://si0.twimg.com/profile_images/622831073/Geo-profile-icon_normal.png + + false + 3595 + C0DEED + 333333 + 0084B4 + DDEEF6 + C0DEED + 0 + Thu Jan 07 20:30:42 +0000 2010 + 0 + -32400 + Alaska + http://a0.twimg.com/images/themes/theme1/bg.png + https://si0.twimg.com/images/themes/theme1/bg.png + false + true + + true + false + + 0 + en + true + + 202 + false + true + false + + + + + + + + false + + + 183709371 + Site Streams Beta + sitestreams + San Francisco, CA + Twitter Site Streams Beta Announcements. When reporting an issue, include account & UTC. You may DM critical outages. + http://a1.twimg.com/profile_images/1112022529/api_normal.png + https://si0.twimg.com/profile_images/1112022529/api_normal.png + http://twitter.com + false + 2199 + C0DEED + 333333 + 0084B4 + DDEEF6 + C0DEED + 1 + Fri Aug 27 18:04:38 +0000 2010 + 0 + + + http://a0.twimg.com/images/themes/theme1/bg.png + https://si0.twimg.com/images/themes/theme1/bg.png + false + true + + false + true + + 139 + en + true + + 98 + false + true + false + + + + + + + + false + + Thu Aug 18 19:39:20 +0000 2011 + 104276210699341825 + For the moment we've stopped the rollout of the new SSL certificate for sitestreams. We'll tweet again when we resume. + web + false + false + + + + 0 + false + + + + + 777925 + + + + diff --git a/spec/twitter/client/user_spec.rb b/spec/twitter/client/user_spec.rb index 9d938aa28..a182f059b 100644 --- a/spec/twitter/client/user_spec.rb +++ b/spec/twitter/client/user_spec.rb @@ -436,6 +436,54 @@ recommendations.first.user.name.should == "John Trupiano" end end + + describe ".contributees" do + + context "with a screen name passed" do + + before do + stub_get("users/contributees.#{format}"). + with(:query => {:screen_name => "sferik"}). + to_return(:body => fixture("contributees.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"}) + end + + it "should get the correct resource" do + @client.contributees("sferik") + a_get("users/contributees.#{format}"). + with(:query => {:screen_name => "sferik"}). + should have_been_made + end + + it "should return a user's contributees" do + contributees = @client.contributees("sferik") + contributees.should be_an Array + contributees.first.name.should == "Twitter API" + end + end + + context "without arguments passed" do + + before do + @client.stub!(:get_screen_name).and_return('sferik') + stub_get("users/contributees.#{format}"). + with(:query => {:screen_name => "sferik"}). + to_return(:body => fixture("contributees.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"}) + end + + it "should get the correct resource" do + @client.contributees + a_get("users/contributees.#{format}"). + with(:query => {:screen_name => "sferik"}). + should have_been_made + end + + it "should return a user's contributees" do + contributees = @client.contributees + contributees.should be_an Array + contributees.first.name.should == "Twitter API" + end + end + end end end end