Skip to content

Commit

Permalink
Remove merge_users and merge_users! from Hash core extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 21, 2012
1 parent 96fba4b commit 2e8bfa3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion lib/twitter/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def follower_ids(*args)
# @param options [Hash] A customizable set of options.
def friendships(*args)
options = extract_options!(args)
options.merge_users!(Array(args))
merge_users!(options, Array(args))
collection_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", options)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/api/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def list_modify_members(request_method, path, args)
merge_list!(options, args.pop)
merge_owner!(options, args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
members.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
object_from_response(Twitter::List, request_method, path, options.merge_users(users))
object_from_response(Twitter::List, request_method, path, merge_users(options, users))
end.last
end

Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def unblock(*args)
def users(*args)
options = extract_options!(args)
args.flatten.each_slice(MAX_USERS_PER_REQUEST).threaded_map do |users|
collection_from_response(Twitter::User, :post, "/1.1/users/lookup.json", options.merge_users(users))
collection_from_response(Twitter::User, :post, "/1.1/users/lookup.json", merge_users(options, users))
end.flatten
end

Expand Down
31 changes: 31 additions & 0 deletions lib/twitter/api/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,37 @@ def merge_user!(hash, user, prefix=nil)
hash
end

# Take a multiple users and merge them into the hash with the correct keys
#
# @param hash [Hash]
# @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(hash, users)
merge_users!(hash.dup, users)
end

# Take a multiple users and merge them into the hash with the correct keys
#
# @param hash [Hash]
# @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!(hash, users)
user_ids, screen_names = [], []
users.flatten.each do |user|
case user
when Integer
user_ids << user
when String
screen_names << user
when Twitter::User
user_ids << user.id
end
end
hash[:user_id] = user_ids.join(',') unless user_ids.empty?
hash[:screen_name] = screen_names.join(',') unless screen_names.empty?
hash
end

end
end
end
29 changes: 0 additions & 29 deletions lib/twitter/core_ext/hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,4 @@ def except!(*keys)
self
end unless method_defined?(:except!)

# 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.
# @return [Hash]
def merge_users!(*users)
user_ids, screen_names = [], []
users.flatten.each do |user|
case user
when Integer
user_ids << user
when String
screen_names << user
when Twitter::User
user_ids << user.id
end
end
self[:user_id] = user_ids.join(',') unless user_ids.empty?
self[:screen_name] = screen_names.join(',') unless screen_names.empty?
self
end

end

0 comments on commit 2e8bfa3

Please sign in to comment.