Skip to content
Browse files

Handle new API v1.1 list response format

Closes sferik/t#70.
  • Loading branch information...
1 parent 97ffdbd commit 2aace25fcf946de995e5ce1788f24ad35bc79438 @sferik committed Oct 5, 2012
Showing with 17 additions and 15 deletions.
  1. +13 −8 lib/twitter/api.rb
  2. +1 −1 spec/fixtures/lists.json
  3. +3 −6 spec/twitter/api/lists_spec.rb
View
21 lib/twitter/api.rb
@@ -1197,20 +1197,25 @@ def list_create(name, options={})
object_from_response(Twitter::List, :post, "/1.1/lists/create.json", options.merge(:name => name))
end
- # List the lists of the specified user
- # Returns all lists the authenticating or specified user subscribes to, including their own.
+ # Returns all lists the authenticating or specified user subscribes to, including their own
#
# @see https://dev.twitter.com/docs/api/1.1/get/lists/list
# @rate_limited Yes
# @authentication_required Requires user context
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
- # @return [Twitter::Cursor]
- # @param options [Hash] A customizable set of options.
- # @option options [Integer] :cursor (-1) Breaks the results into pages. Provide values as returned in the response objects's next_cursor and previous_cursor attributes to page back and forth in the list.
- # @example List the authenticated user's lists
- # Twitter.lists
+ # @return [Array<Twitter::List>]
+ # @overload memberships(options={})
+ # @param options [Hash] A customizable set of options.
+ # @example Returns all lists the authenticating user subscribes to
+ # Twitter.lists
+ # @overload memberships(user, options={})
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
+ # @param options [Hash] A customizable set of options.
+ # @example Returns all lists that @sferik subscribes to
+ # Twitter.lists('sferik')
+ # Twitter.lists(7505382)
def lists(*args)
- lists_from_response(:get, "/1.1/lists/list.json", args)
+ objects_from_response(Twitter::List, :get, "/1.1/lists/list.json", args)
end
alias lists_subscribed_to lists
View
2 spec/fixtures/lists.json
@@ -1 +1 @@
-{"lists":[{"mode":"public","description":"","id_str":"1129440","member_count":494,"uri":"\/pengwynn\/rubyists","subscriber_count":28,"full_name":"@pengwynn\/rubyists","user":{"statuses_count":3950,"profile_background_image_url":"http:\/\/a1.twimg.com\/profile_background_images\/61741268\/twitter-small.png","profile_link_color":"35abe9","description":"Christian husband and father. Dev Experience @ HP Cloud Services. Co-host of the @changelogshow. Mashup of design & development.","screen_name":"pengwynn","show_all_inline_media":false,"friends_count":1919,"id_str":"14100886","contributors_enabled":false,"profile_background_tile":false,"profile_sidebar_fill_color":"dddddd","geo_enabled":true,"favourites_count":32,"profile_sidebar_border_color":"cccccc","followers_count":2788,"url":"http:\/\/wynnnetherland.com","verified":false,"follow_request_sent":false,"lang":"en","time_zone":"Central Time (US & Canada)","created_at":"Sat Mar 08 16:34:22 +0000 2008","location":"Dallas, TX","profile_background_color":"efefef","protected":false,"name":"Wynn Netherland","following":true,"profile_use_background_image":true,"profile_text_color":"666666","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/485575482\/komikazee_normal.png","id":14100886,"listed_count":186,"notifications":false,"utc_offset":-21600},"name":"Rubyists","following":true,"slug":"rubyists","id":1129440},{"mode":"public","description":"","id_str":"574","member_count":308,"uri":"\/twitter\/team","subscriber_count":76189,"full_name":"@twitter\/team","user":{"follow_request_sent":false,"profile_background_image_url":"http:\/\/s.twimg.com\/a\/1288202850\/images\/themes\/theme18\/bg.gif","profile_link_color":"038543","description":"Always wondering what's happening. ","screen_name":"twitter","id_str":"783214","profile_background_tile":false,"profile_sidebar_fill_color":"F6F6F6","listed_count":49543,"favourites_count":0,"profile_sidebar_border_color":"EEEEEE","followers_count":3916812,"url":"http:\/\/twitter.com","statuses_count":896,"show_all_inline_media":true,"lang":"en","time_zone":"Pacific Time (US & Canada)","created_at":"Tue Feb 20 14:35:54 +0000 2007","friends_count":340,"location":"San Francisco, CA","contributors_enabled":true,"profile_background_color":"ACDED6","protected":false,"geo_enabled":true,"name":"Twitter","following":false,"profile_use_background_image":true,"profile_text_color":"333333","profile_image_url":"http:\/\/a1.twimg.com\/profile_images\/1124040897\/at-twitter_normal.png","id":783214,"verified":true,"notifications":false,"utc_offset":-28800},"name":"Team","following":true,"slug":"team","id":574}], "next_cursor":0, "previous_cursor":0, "next_cursor_str":"0", "previous_cursor_str":"0"}
+[{"uri":"\/pengwynn\/rubyists","name":"Rubyists","full_name":"@pengwynn\/rubyists","description":"","mode":"public","user":{"id":14100886,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/images\/themes\/theme1\/bg.png","time_zone":"Central Time (US & Canada)","location":"Denton, TX","profile_background_image_url":"http:\/\/a0.twimg.com\/images\/themes\/theme1\/bg.png","id_str":"14100886","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2221455972\/wynn-mic-bw_normal.jpg","utc_offset":-21600,"profile_use_background_image":false,"statuses_count":7384,"name":"Wynn Netherland","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"pengwynn","listed_count":397,"protected":false,"is_translator":false,"followers_count":6182,"profile_sidebar_border_color":"FFFFFF","description":"Christian, husband, father, GitHubber, Co-host of @thechangelog, Co-author of Sass, Compass, #CSS book http:\/\/wynn.fm\/sass-meap","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2221455972\/wynn-mic-bw_normal.jpg","profile_background_tile":false,"following":true,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"http:\/\/wynnnetherland.com","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/14100886\/1347987369","favourites_count":338,"created_at":"Sat Mar 08 16:34:22 +0000 2008","friends_count":3528,"verified":false,"notifications":false,"profile_background_color":"292929","contributors_enabled":false},"following":true,"created_at":"Fri Oct 30 14:39:25 +0000 2009","member_count":499,"id_str":"1129440","subscriber_count":39,"slug":"rubyists","id":1129440},{"uri":"\/twitter\/team","name":"Team","full_name":"@twitter\/team","description":"","mode":"public","user":{"id":783214,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/657090062\/l1uqey5sy82r9ijhke1i.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco, CA","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/657090062\/l1uqey5sy82r9ijhke1i.png","id_str":"783214","profile_link_color":"038543","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/2284174758\/v65oai7fxn47qv9nectx_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":1433,"name":"Twitter","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"twitter","listed_count":73287,"protected":false,"followers_count":13711595,"profile_sidebar_border_color":"EEEEEE","is_translator":false,"description":"Always wondering what's happening. ","profile_background_tile":true,"following":true,"profile_sidebar_fill_color":"F6F6F6","default_profile_image":false,"url":"http:\/\/blog.twitter.com\/","profile_banner_url":"https:\/\/si0.twimg.com\/profile_banners\/783214\/1347405327","favourites_count":18,"created_at":"Tue Feb 20 14:35:54 +0000 2007","friends_count":1249,"verified":true,"notifications":false,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/2284174758\/v65oai7fxn47qv9nectx_normal.png","profile_background_color":"ACDED6","contributors_enabled":true},"following":true,"created_at":"Wed Sep 23 01:18:01 +0000 2009","member_count":1199,"id_str":"574","subscriber_count":78078,"slug":"team","id":574},{"uri":"\/sferik\/test","name":"test","full_name":"@sferik\/test","description":"","mode":"private","user":{"id":7505382,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","id_str":"7505382","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":8576,"name":"Erik Michaels-Ober","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"sferik","listed_count":129,"protected":false,"followers_count":2449,"profile_sidebar_border_color":"000000","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","description":"An ingredient in your recipe.","is_translator":false,"profile_background_tile":false,"following":false,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"https:\/\/github.com\/sferik","favourites_count":4321,"created_at":"Mon Jul 16 12:59:01 +0000 2007","friends_count":203,"verified":false,"notifications":false,"profile_background_color":"000000","contributors_enabled":false},"following":false,"created_at":"Sun Jul 08 22:19:05 +0000 2012","member_count":2,"id_str":"73546689","subscriber_count":0,"slug":"test","id":73546689},{"uri":"\/sferik\/interesting","name":"interesting","full_name":"@sferik\/interesting","description":"People who are interesting.","mode":"private","user":{"id":7505382,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","id_str":"7505382","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":8576,"name":"Erik Michaels-Ober","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"sferik","listed_count":129,"protected":false,"followers_count":2449,"profile_sidebar_border_color":"000000","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","description":"An ingredient in your recipe.","is_translator":false,"profile_background_tile":false,"following":false,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"https:\/\/github.com\/sferik","favourites_count":4321,"created_at":"Mon Jul 16 12:59:01 +0000 2007","friends_count":203,"verified":false,"notifications":false,"profile_background_color":"000000","contributors_enabled":false},"following":false,"created_at":"Sat Sep 04 00:46:03 +0000 2010","member_count":4,"id_str":"20817728","subscriber_count":0,"slug":"interesting","id":20817728},{"uri":"\/sferik\/recommended","name":"recommended","full_name":"@sferik\/recommended","description":"Users recommended to me by Twitter","mode":"private","user":{"id":7505382,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","id_str":"7505382","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":8576,"name":"Erik Michaels-Ober","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"sferik","listed_count":129,"protected":false,"followers_count":2449,"profile_sidebar_border_color":"000000","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","description":"An ingredient in your recipe.","is_translator":false,"profile_background_tile":false,"following":false,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"https:\/\/github.com\/sferik","favourites_count":4321,"created_at":"Mon Jul 16 12:59:01 +0000 2007","friends_count":203,"verified":false,"notifications":false,"profile_background_color":"000000","contributors_enabled":false},"following":false,"created_at":"Thu Sep 02 18:29:24 +0000 2010","member_count":71,"id_str":"20712515","subscriber_count":0,"slug":"recommended","id":20712515},{"uri":"\/sferik\/presidents","name":"presidents","full_name":"@sferik\/presidents","description":"Presidents of the United States of America","mode":"public","user":{"id":7505382,"profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","time_zone":"Pacific Time (US & Canada)","location":"San Francisco","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/665875854\/bb0b3653dcf0644e344823e0a2eb3382.png","id_str":"7505382","profile_link_color":"0084B4","geo_enabled":true,"default_profile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","utc_offset":-28800,"profile_use_background_image":true,"statuses_count":8576,"name":"Erik Michaels-Ober","follow_request_sent":false,"profile_text_color":"333333","lang":"en","screen_name":"sferik","listed_count":129,"protected":false,"followers_count":2449,"profile_sidebar_border_color":"000000","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","description":"An ingredient in your recipe.","is_translator":false,"profile_background_tile":false,"following":false,"profile_sidebar_fill_color":"DDEEF6","default_profile_image":false,"url":"https:\/\/github.com\/sferik","favourites_count":4321,"created_at":"Mon Jul 16 12:59:01 +0000 2007","friends_count":203,"verified":false,"notifications":false,"profile_background_color":"000000","contributors_enabled":false},"following":false,"created_at":"Mon Mar 15 06:10:13 +0000 2010","member_count":2,"id_str":"8863586","subscriber_count":1,"slug":"presidents","id":8863586}]
View
9 spec/twitter/api/lists_spec.rb
@@ -789,21 +789,18 @@
describe "#lists" do
before do
stub_get("/1.1/lists/list.json").
- with(:query => {:cursor => "-1"}).
to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "requests the correct resource" do
@client.lists
a_get("/1.1/lists/list.json").
- with(:query => {:cursor => "-1"}).
should have_been_made
end
it "returns the requested list" do
lists = @client.lists
- lists.should be_a Twitter::Cursor
- lists.lists.should be_an Array
- lists.lists.first.should be_a Twitter::List
- lists.lists.first.name.should eq "Rubyists"
+ lists.should be_an Array
+ lists.first.should be_a Twitter::List
+ lists.first.name.should eq "Rubyists"
end
end

0 comments on commit 2aace25

Please sign in to comment.
Something went wrong with that request. Please try again.