Permalink
Browse files

Update to match the twitter API docs for the user show action

  • Loading branch information...
1 parent 05dd3e5 commit cb31e4a26b20d93006d568fab50ccce5c4d1626f Ed Schmalzle committed with Sep 24, 2010
Showing with 15 additions and 4 deletions.
  1. +7 −2 lib/twitter/base.rb
  2. +8 −2 test/twitter/base_test.rb
View
@@ -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)
View
@@ -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)

0 comments on commit cb31e4a

Please sign in to comment.