Permalink
Browse files

Performance improvement in #user

Only make one request when user ID or screen name isn't provided.
  • Loading branch information...
sferik committed Dec 7, 2011
1 parent d776fa2 commit 9cfaa1514ccb5ce09c5454f1400d532a3f9344fc
Showing with 7 additions and 8 deletions.
  1. +6 −3 lib/twitter/client/users.rb
  2. +1 −5 spec/twitter/client/users_spec.rb
@@ -85,9 +85,12 @@ def user_search(query, options={})
# Twitter.user(7505382) # Same as above
def user(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
- user = args.pop || self.current_user.screen_name
- options.merge_user!(user)
- user = get("/1/users/show.json", options)
+ if user = args.pop
+ options.merge_user!(user)
+ user = get("/1/users/show.json", options)
+ else
+ user = get("/1/account/verify_credentials.json", options)
+ end
Twitter::User.new(user)
end
@@ -180,14 +180,10 @@
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/show.json").
- with(:query => {:screen_name => "sferik"}).
- to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
it "should request the correct resource" do
@client.user
- a_get("/1/users/show.json").
- with(:query => {:screen_name => "sferik"}).
+ a_get("/1/account/verify_credentials.json").
should have_been_made
end
end

0 comments on commit 9cfaa15

Please sign in to comment.