Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add ability to pass a user to recommendations as an argument

  • Loading branch information...
commit 19f5796ba618e634ed56e936eb8f3bcb9822124c 1 parent 250f088
@sferik authored
Showing with 45 additions and 14 deletions.
  1. +5 −1 lib/twitter/client/users.rb
  2. +40 −13 spec/twitter/client/users_spec.rb
View
6 lib/twitter/client/users.rb
@@ -190,7 +190,11 @@ def contributors(*args)
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @example Return recommended users for the authenticated user
# Twitter.recommendations
- def recommendations(options={})
+ def recommendations(*args)
+ options = {}
+ options.merge!(args.last.is_a?(Hash) ? args.pop : {})
+ user = args.pop || self.current_user.screen_name
+ options.merge_user!(user)
options[:excluded] = options[:excluded].join(',') if options[:excluded].is_a?(Array)
get("/1/users/recommendations.json", options).map do |recommendation|
Twitter::User.new(recommendation['user'])
View
53 spec/twitter/client/users_spec.rb
@@ -303,20 +303,47 @@
end
describe ".recommendations" do
- before do
- stub_get("/1/users/recommendations.json").
- to_return(:body => fixture("recommendations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
- end
- it "should request the correct resource" do
- @client.recommendations
- a_get("/1/users/recommendations.json").
- should have_been_made
+ context "with a screen name passed" do
+ before do
+ stub_get("/1/users/recommendations.json").
+ with(:query => {:screen_name => "sferik"}).
+ to_return(:body => fixture("recommendations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.recommendations("sferik")
+ a_get("/1/users/recommendations.json").
+ with(:query => {:screen_name => "sferik"}).
+ should have_been_made
+ end
+ it "should return recommended users for the authenticated user" do
+ recommendations = @client.recommendations("sferik")
+ recommendations.should be_an Array
+ recommendations.first.should be_a Twitter::User
+ recommendations.first.name.should == "John Trupiano"
+ end
end
- it "should return recommended users for the authenticated user" do
- recommendations = @client.recommendations
- recommendations.should be_an Array
- recommendations.first.should be_a Twitter::User
- recommendations.first.name.should == "John Trupiano"
+ context "without arguments 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_get("/1/users/recommendations.json").
+ with(:query => {:screen_name => "sferik"}).
+ to_return(:body => fixture("recommendations.json"), :headers => {:content_type => "application/json; charset=utf-8"})
+ end
+ it "should request the correct resource" do
+ @client.recommendations
+ a_get("/1/account/verify_credentials.json").
+ should have_been_made
+ a_get("/1/users/recommendations.json").
+ with(:query => {:screen_name => "sferik"}).
+ should have_been_made
+ end
+ it "should return recommended users for the authenticated user" do
+ recommendations = @client.recommendations
+ recommendations.should be_an Array
+ recommendations.first.should be_a Twitter::User
+ recommendations.first.name.should == "John Trupiano"
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.