Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add list_remove_members method

  • Loading branch information...
commit 025c5281c9e695ad7fd21bcc34d4df4aaf0f3fb7 1 parent 05ed01f
@sferik authored
Showing with 118 additions and 1 deletion.
  1. +43 −1 lib/twitter/client/lists.rb
  2. +75 −0 spec/twitter/client/lists_spec.rb
View
44 lib/twitter/client/lists.rb
@@ -324,7 +324,7 @@ def list_unsubscribe(*args)
Twitter::List.new(list)
end
- # Adds multiple members to a list
+ # Adds specified members to a list
#
# @see https://dev.twitter.com/docs/api/1/post/lists/members/create_all
# @note Lists are limited to having 500 members, and you are limited to adding up to 100 members to a list at a time with this method.
@@ -367,6 +367,48 @@ def list_add_members(*args)
Twitter::List.new(list)
end
+ # Removes specified members from the list
+ #
+ # @see https://dev.twitter.com/docs/api/1/post/lists/members/destroy_all
+ # @rate_limited No
+ # @requires_authentication Yes
+ # @overload list_remove_members(list, users_to_remove, options={})
+ # @param list [Integer, String] The list_id or slug of the list.
+ # @param users_to_remove [Array] The user IDs and/or screen names to remove.
+ # @param options [Hash] A customizable set of options.
+ # @return [Twitter::List] The list.
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
+ # @example Remove @BarackObama and @pengwynn from the authenticated user's "presidents" list
+ # Twitter.list_remove_members('presidents', ['BarackObama', 'pengwynn'])
+ # Twitter.list_remove_members('presidents', [813286, 18755393])
+ # Twitter.list_remove_members(8863586, ['BarackObama', 'pengwynn'])
+ # Twitter.list_remove_members(8863586, [813286, 18755393])
+ # @overload list_remove_members(user, list, users_to_remove, options={})
+ # @param user [Integer, String] A Twitter user ID or screen name.
+ # @param list [Integer, String] The list_id or slug of the list.
+ # @param users_to_remove [Array] The user IDs and/or screen names to remove.
+ # @param options [Hash] A customizable set of options.
+ # @return [Twitter::List] The list.
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
+ # @example Remove @BarackObama and @pengwynn from @sferik's "presidents" list
+ # Twitter.list_remove_members('sferik', 'presidents', ['BarackObama', 'pengwynn'])
+ # Twitter.list_remove_members('sferik', 'presidents', [813286, 18755393])
+ # Twitter.list_remove_members(7505382, 'presidents', ['BarackObama', 'pengwynn'])
+ # Twitter.list_remove_members(7505382, 'presidents', [813286, 18755393])
+ # Twitter.list_remove_members(7505382, 8863586, ['BarackObama', 'pengwynn'])
+ # Twitter.list_remove_members(7505382, 8863586, [813286, 18755393])
+ def list_remove_members(*args)
+ options = args.last.is_a?(Hash) ? args.pop : {}
+ users_to_remove = args.pop
+ options.merge_users!(Array(users_to_remove))
+ list = args.pop
+ options.merge_list!(list)
+ owner = args.pop || self.current_user.screen_name
+ options.merge_owner!(owner)
+ list = post("/1/lists/members/destroy_all.json", options)
+ Twitter::List.new(list)
+ end
+
# Check if a user is a member of the specified list
#
# @see https://dev.twitter.com/docs/api/1/get/lists/members/show
View
75 spec/twitter/client/lists_spec.rb
@@ -632,6 +632,81 @@
end
end
+ describe ".list_remove_members" do
+ context "with a screen name passed" do
+ before do
+ stub_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.list_remove_members("sferik", "presidents", [813286, 18755393])
+ a_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
+ should have_been_made
+ end
+ it "should return the list" do
+ list = @client.list_remove_members("sferik", "presidents", [813286, 18755393])
+ list.should be_a Twitter::List
+ list.name.should == "presidents"
+ end
+ end
+ context "with an Integer user_id passed" do
+ before do
+ stub_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_id => '12345678', :slug => 'presidents', :user_id => "813286,18755393"}).
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.list_remove_members(12345678, "presidents", [813286, 18755393])
+ a_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_id => '12345678', :slug => 'presidents', :user_id => "813286,18755393"}).
+ should have_been_made
+ end
+ end
+ context "with an Integer list_id passed" do
+ before do
+ stub_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => "813286,18755393"}).
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.list_remove_members('sferik', 12345678, [813286, 18755393])
+ a_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :list_id => '12345678', :user_id => "813286,18755393"}).
+ should have_been_made
+ end
+ end
+ context "with a combination of member IDs and member screen names to add" do
+ before do
+ stub_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.list_remove_members('sferik', 'presidents', [813286, 'pengwynn', 18755393, 'erebor'])
+ a_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393", :screen_name => "pengwynn,erebor"}).
+ should have_been_made
+ end
+ end
+ context "without a screen name passed" do
+ before do
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ stub_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
+ to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.list_remove_members("presidents", [813286, 18755393])
+ a_post("/1/lists/members/destroy_all.json").
+ with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
+ should have_been_made
+ end
+ end
+ end
+
describe ".list_member?" do
context "with a screen name passed" do
before do
Please sign in to comment.
Something went wrong with that request. Please try again.