Skip to content

Commit

Permalink
Update to match the twitter API docs for the user show action
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Schmalzle authored and sferik committed Sep 24, 2010
1 parent 05dd3e5 commit cb31e4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
9 changes: 7 additions & 2 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ def followers(query={})
perform_get("/#{Twitter.api_version}/statuses/followers.json", :query => query)
end

def user(id, query={})
perform_get("/#{Twitter.api_version}/users/show/#{id}.json", :query => query)
def user(id_or_username, query={})
if id_or_username.is_a?(Integer)
query.merge!({:user_id => id_or_username})
elsif id_or_username.is_a?(String)
query.merge!({:screen_name => id_or_username})
end
perform_get("/#{Twitter.api_version}/users/show.json", :query => query)
end

def users(*ids_or_usernames)
Expand Down
10 changes: 8 additions & 2 deletions test/twitter/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ class BaseTest < Test::Unit::TestCase
assert !@twitter.friendship_show(:source_screen_name => "dcrec1", :target_screen_name => "pengwynn").relationship.target.followed_by
end

should "be able to lookup a user" do
stub_get("/1/users/show/4243.json", "user.json")
should "be able to lookup a user by id" do
stub_get("/1/users/show.json?user_id=4243", "user.json")
user = @twitter.user(4243)
assert_equal 'jnunemaker', user.screen_name
end

should "be able to lookup a user by screen_name" do
stub_get("/1/users/show.json?screen_name=jnunemaker", "user.json")
user = @twitter.user('jnunemaker')
assert_equal 'jnunemaker', user.screen_name
end

should "be able to lookup users in bulk" do
stub_get("/1/users/lookup.json?screen_name=sferik&user_id=59593,774010", "users.json")
users = @twitter.users("sferik", 59593, 774010)
Expand Down

0 comments on commit cb31e4a

Please sign in to comment.