Skip to content

Commit

Permalink
Add ability to pass a user to recommendations as an argument
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 25, 2012
1 parent 250f088 commit 19f5796
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 14 deletions.
6 changes: 5 additions & 1 deletion lib/twitter/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand Down
53 changes: 40 additions & 13 deletions spec/twitter/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 19f5796

Please sign in to comment.