Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Twitter::API::Lists#lists_owned method

  • Loading branch information...
commit 9e97b51c20aabf4485a91ae7db697ee3be131a89 1 parent 3cd4262
@sferik authored
View
26 lib/twitter/api/lists.rb
@@ -23,11 +23,13 @@ module Lists
# @return [Array<Twitter::List>]
# @overload lists(options={})
# @param options [Hash] A customizable set of options.
+ # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
# @example Return all lists the authenticating user subscribes to
# Twitter.lists
# @overload lists(user, options={})
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
# @param options [Hash] A customizable set of options.
+ # @option options [Boolean] :reverse Set this to true if you would like owned lists to be returned first.
# @example Return all lists that @sferik subscribes to
# Twitter.lists('sferik')
# Twitter.lists(7505382)
@@ -506,6 +508,30 @@ def list_remove_members(*args)
list_from_response_with_users(:post, "/1.1/lists/members/destroy_all.json", args)
end
+ # Returns the lists owned by the specified Twitter user
+ #
+ # @see https://dev.twitter.com/docs/api/1.1/get/lists/ownerships
+ # @rate_limited Yes
+ # @authentication Requires user context
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
+ # @return [Array<Twitter::List>]
+ # @overload lists_owned(options={})
+ # @param options [Hash] A customizable set of options.
+ # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
+ # @example Return all lists the authenticating user owns
+ # Twitter.lists_owend
+ # @overload lists_owned(user, options={})
+ # @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, or object.
+ # @param options [Hash] A customizable set of options.
+ # @option options [Integer] :count The amount of results to return per page. Defaults to 20. No more than 1000 results will ever be returned in a single page.
+ # @example Return all lists that @sferik owns
+ # Twitter.lists_owned('sferik')
+ # Twitter.lists_owned(7505382)
+ def lists_owned(*args)
+ cursor_from_response_with_user(:lists, Twitter::List, :get, "/1.1/lists/ownerships.json", args, :lists_owned)
+ end
+ alias lists_ownerships lists_owned
+
private
# @param request_method [Symbol]
View
2  lib/twitter/api/oauth.rb
@@ -18,7 +18,7 @@ module OAuth
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Twitter::Token] The Bearer Token. token_type should be 'bearer'.
# @example Generate a Bearer Token
- # client = Twitter::Client.new :consumer_key => "abc", :consumer_secret => 'def'
+ # client = Twitter::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
# bearer_token = client.token
def token
object_from_response(Twitter::Token, :post, "/oauth2/token", :grant_type => "client_credentials", :bearer_token_request => true)
View
1  spec/fixtures/ownerships.json
@@ -0,0 +1 @@
+{"next_cursor":0,"next_cursor_str":"0","previous_cursor":0,"previous_cursor_str":"0","lists":[{"id":78890017,"id_str":"78890017","name":"My favstar.fm list","uri":"\/sferik\/my-favstar-fm-list","subscriber_count":0,"member_count":137,"mode":"private","description":"My favorite tweeters, created with help from http:\/\/favstar.fm","slug":"my-favstar-fm-list","full_name":"@sferik\/my-favstar-fm-list","created_at":"Fri Oct 12 19:47:53 +0000 2012","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":73546689,"id_str":"73546689","name":"test","uri":"\/sferik\/test","subscriber_count":0,"member_count":2,"mode":"private","description":"","slug":"test","full_name":"@sferik\/test","created_at":"Sun Jul 08 22:19:05 +0000 2012","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":20817728,"id_str":"20817728","name":"interesting","uri":"\/sferik\/interesting","subscriber_count":0,"member_count":4,"mode":"private","description":"People who are interesting.","slug":"interesting","full_name":"@sferik\/interesting","created_at":"Sat Sep 04 00:46:03 +0000 2010","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":20712515,"id_str":"20712515","name":"recommended","uri":"\/sferik\/recommended","subscriber_count":0,"member_count":71,"mode":"private","description":"Users recommended to me by Twitter","slug":"recommended","full_name":"@sferik\/recommended","created_at":"Thu Sep 02 18:29:24 +0000 2010","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}},{"id":8863586,"id_str":"8863586","name":"presidents","uri":"\/sferik\/presidents","subscriber_count":0,"member_count":2,"mode":"public","description":"Presidents of the United States of America","slug":"presidents","full_name":"@sferik\/presidents","created_at":"Mon Mar 15 06:10:13 +0000 2010","following":true,"user":{"id":7505382,"id_str":"7505382","name":"Erik Michaels-Ober","screen_name":"sferik","location":"San Francisco","description":"Write code. Not too much. Mostly Ruby.","url":"https:\/\/github.com\/sferik","entities":{"url":{"urls":[{"url":"https:\/\/github.com\/sferik","expanded_url":null,"indices":[0,25]}]},"description":{"urls":[]}},"protected":false,"followers_count":8855,"friends_count":248,"listed_count":167,"created_at":"Mon Jul 16 12:59:01 +0000 2007","favourites_count":6063,"utc_offset":-28800,"time_zone":"Pacific Time (US & Canada)","geo_enabled":true,"verified":false,"statuses_count":11166,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"000000","profile_background_image_url":"http:\/\/a0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/677717672\/bb0b3653dcf0644e344823e0a2eb3382.png","profile_background_tile":false,"profile_image_url":"http:\/\/a0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1759857427\/image1326743606_normal.png","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/7505382\/1349499693","profile_link_color":"0084B4","profile_sidebar_border_color":"000000","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"default_profile":false,"default_profile_image":false,"following":false,"follow_request_sent":false,"notifications":false}}]}
View
36 spec/twitter/api/lists_spec.rb
@@ -829,4 +829,40 @@
end
end
+ describe "#lists_owned" do
+ context "with a screen name passed" do
+ before do
+ stub_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"}).to_return(:body => fixture("ownerships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "requests the correct resource" do
+ @client.lists_owned("sferik")
+ expect(a_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"})).to have_been_made
+ end
+ it "returns the requested list" do
+ lists = @client.lists_owned("sferik")
+ expect(lists).to be_a Twitter::Cursor
+ expect(lists.lists).to be_an Array
+ expect(lists.lists.first).to be_a Twitter::List
+ expect(lists.lists.first.name).to eq "My favstar.fm list"
+ end
+ end
+ context "without a screen name passed" do
+ before do
+ stub_get("/1.1/account/verify_credentials.json").to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ stub_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"}).to_return(:body => fixture("ownerships.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "requests the correct resource" do
+ @client.lists_owned
+ expect(a_get("/1.1/lists/ownerships.json").with(:query => {:screen_name => "sferik", :cursor => "-1"})).to have_been_made
+ end
+ it "returns the requested list" do
+ lists = @client.lists_owned
+ expect(lists).to be_a Twitter::Cursor
+ expect(lists.lists).to be_an Array
+ expect(lists.lists.first).to be_a Twitter::List
+ expect(lists.lists.first.name).to eq "My favstar.fm list"
+ end
+ end
+ end
+
end
View
3  spec/twitter/api/oauth_spec.rb
@@ -3,7 +3,7 @@
describe Twitter::API::OAuth do
before do
- @client = Twitter::Client.new :consumer_key => 'CK', :consumer_secret => 'CS'
+ @client = Twitter::Client.new(:consumer_key => 'CK', :consumer_secret => 'CS')
end
describe "#token" do
@@ -45,4 +45,5 @@
expect(token.token_type).to eq nil
end
end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.