Permalink
Browse files

Add accept and deny methods

  • Loading branch information...
1 parent da3455c commit c251055137b9aa02f085b06f031d18ca65ee0716 @sferik committed Oct 31, 2011
Showing with 72 additions and 0 deletions.
  1. +34 −0 lib/twitter/client/friends_and_followers.rb
  2. +38 −0 spec/twitter/client/friends_and_followers_spec.rb
@@ -254,6 +254,40 @@ def no_retweet_ids(options={})
get("/1/friendships/no_retweet_ids.json", options, :phoenix => true)
end
+ # Allows the authenticating user to accept the specified user's follow request
+ #
+ # @note Undocumented
+ # @rate_limited No
+ # @requires_authentication Yes
+ # @param user [Integer, String] A Twitter user ID or screen name.
+ # @param options [Hash] A customizable set of options.
+ # @return [Twitter::User] The accepted user.
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
+ # @example Accept @sferik's follow request
+ # Twitter.accept("sferik")
+ def accept(user, options={})
+ options.merge_user!(user)
+ user = post("/1/friendships/accept.json", options)
+ Twitter::User.new(user)
+ end
+
+ # Allows the authenticating user to deny the specified user's follow request
+ #
+ # @note Undocumented
+ # @rate_limited No
+ # @requires_authentication Yes
+ # @param user [Integer, String] A Twitter user ID or screen name.
+ # @param options [Hash] A customizable set of options.
+ # @return [Twitter::User] The denied user.
+ # @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
+ # @example Deny @sferik's follow request
+ # Twitter.deny("sferik")
+ def deny(user, options={})
+ options.merge_user!(user)
+ user = post("/1/friendships/deny.json", options)
+ Twitter::User.new(user)
+ end
+
end
end
end
@@ -437,4 +437,42 @@
end
end
+ describe ".accept" do
+ before do
+ stub_post("/1/friendships/accept.json").
+ with(:body => {:screen_name => "sferik"}).
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should get the correct resource" do
+ @client.accept("sferik")
+ a_post("/1/friendships/accept.json").
+ with(:body => {:screen_name => "sferik"}).
+ should have_been_made
+ end
+ it "should return the accepted user" do
+ user = @client.accept("sferik")
+ user.should be_a Twitter::User
+ user.name.should == "Erik Michaels-Ober"
+ end
+ end
+
+ describe ".deny" do
+ before do
+ stub_post("/1/friendships/deny.json").
+ with(:body => {:screen_name => "sferik"}).
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should get the correct resource" do
+ @client.deny("sferik")
+ a_post("/1/friendships/deny.json").
+ with(:body => {:screen_name => "sferik"}).
+ should have_been_made
+ end
+ it "should return the denied user" do
+ user = @client.deny("sferik")
+ user.should be_a Twitter::User
+ user.name.should == "Erik Michaels-Ober"
+ end
+ end
+
end

0 comments on commit c251055

Please sign in to comment.