Permalink
Browse files

Allow users method to return more than 100 Twitter::User objects

  • Loading branch information...
1 parent 5e2eff8 commit 296a8847aa9bea0881369649a91e38fc2e9b3076 @sferik committed Jun 3, 2012
Showing with 15 additions and 7 deletions.
  1. +7 −7 lib/twitter/client.rb
  2. +8 −0 lib/twitter/core_ext/hash.rb
View
@@ -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]
@@ -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
@@ -96,6 +96,14 @@ def merge_user!(user, prefix=nil, suffix=nil)
#
# @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.
+ # @return [Hash]
def merge_users!(*users)
user_ids, screen_names = [], []
users.flatten.each do |user|

0 comments on commit 296a884

Please sign in to comment.