Skip to content

Commit

Permalink
Allow users method to return more than 100 Twitter::User objects
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Jun 3, 2012
1 parent 5e2eff8 commit 296a884
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/twitter/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ module Twitter
# @note All methods have been separated into modules and follow the same grouping used in {http://dev.twitter.com/doc the Twitter API Documentation}.
# @see http://dev.twitter.com/pages/every_developer
class Client

include Twitter::Authenticatable
include Twitter::Connection
include Twitter::Request

attr_accessor *Config::VALID_OPTIONS_KEYS

MAX_USERS_PER_REQUEST = 100

# Initializes a new API object
#
# @param attrs [Hash]
Expand Down Expand Up @@ -2402,11 +2402,11 @@ def update_with_media(status, image, options={})
# Twitter.users(7505382, 14100886) # Same as above
def users(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
users = args
options.merge_users!(Array(users))
get("/1/users/lookup.json", options).map do |user|
Twitter::User.new(user)
end
args.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
get("/1/users/lookup.json", options.merge_users(Array(users))).map do |user|
Twitter::User.new(user)
end
end.flatten
end

# Access the profile image in various sizes for the user with the indicated screen name
Expand Down
8 changes: 8 additions & 0 deletions lib/twitter/core_ext/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,14 @@ def merge_user!(user, prefix=nil, suffix=nil)
self
end

# Take a multiple users and merge them into the hash with the correct keys
#
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen_names, or objects.
# @return [Hash]
def merge_users(*users)
self.dup.merge_users!(users)
end

# Take a multiple users and merge them into the hash with the correct keys
#
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen_names, or objects.
Expand Down

0 comments on commit 296a884

Please sign in to comment.