Skip to content

Commit

Permalink
Rename Twitter::Util module to Twitter::Utils
Browse files Browse the repository at this point in the history
For consistency with Twitter::REST::API::Utils (and Faraday::Utils). See
discussion with @charliesome: #503
  • Loading branch information
sferik committed Dec 18, 2013
1 parent 9671a66 commit ca21c5b
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 16 deletions.
1 change: 0 additions & 1 deletion lib/twitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,3 @@
require 'twitter/trend'
require 'twitter/tweet'
require 'twitter/user'
require 'twitter/util'
3 changes: 2 additions & 1 deletion lib/twitter/rest/api/direct_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'twitter/direct_message'
require 'twitter/rest/api/utils'
require 'twitter/user'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -88,7 +89,7 @@ def direct_messages(*args)
if arguments.empty?
direct_messages_received(arguments.options)
else
Util.parallel_map(arguments.flatten) do |id|
Twitter::Utils.parallel_map(arguments.flatten) do |id|
direct_message(id, arguments.options)
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter/rest/api/favorites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'twitter/rest/api/utils'
require 'twitter/tweet'
require 'twitter/user'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -67,7 +68,7 @@ def unfavorite(*args)
# @param options [Hash] A customizable set of options.
def favorite(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |tweet|
Twitter::Utils.parallel_map(arguments.flatten) do |tweet|
id = extract_id(tweet)
begin
object_from_response(Twitter::Tweet, :post, '/1.1/favorites/create.json', arguments.options.merge(:id => id))
Expand Down Expand Up @@ -95,7 +96,7 @@ def favorite(*args)
# @param options [Hash] A customizable set of options.
def favorite!(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |tweet|
Twitter::Utils.parallel_map(arguments.flatten) do |tweet|
id = extract_id(tweet)
begin
object_from_response(Twitter::Tweet, :post, '/1.1/favorites/create.json', arguments.options.merge(:id => id))
Expand Down
3 changes: 2 additions & 1 deletion lib/twitter/rest/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'twitter/relationship'
require 'twitter/rest/api/utils'
require 'twitter/user'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -136,7 +137,7 @@ def follow(*args)
# @option options [Boolean] :follow (false) Enable notifications for the target user.
def follow!(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |user|
Twitter::Utils.parallel_map(arguments.flatten) do |user|
object_from_response(Twitter::User, :post, '/1.1/friendships/create.json', merge_user(arguments.options, user))
end.compact
end
Expand Down
3 changes: 2 additions & 1 deletion lib/twitter/rest/api/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'twitter/rest/api/utils'
require 'twitter/tweet'
require 'twitter/user'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -444,7 +445,7 @@ def list_from_response_with_users(request_method, path, args)
members = arguments.pop
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
Util.parallel_map(members.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users|
Twitter::Utils.parallel_map(members.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users|
object_from_response(Twitter::List, request_method, path, merge_users(arguments.options, users))
end.last
end
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter/rest/api/saved_searches.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'twitter/arguments'
require 'twitter/rest/api/utils'
require 'twitter/saved_search'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -33,7 +34,7 @@ def saved_searches(*args)
if arguments.empty?
objects_from_response(Twitter::SavedSearch, :get, '/1.1/saved_searches/list.json', arguments.options)
else
Util.parallel_map(arguments.flatten) do |id|
Twitter::Utils.parallel_map(arguments.flatten) do |id|
saved_search(id, arguments.options)
end
end
Expand Down Expand Up @@ -81,7 +82,7 @@ def create_saved_search(query, options = {})
# @param options [Hash] A customizable set of options.
def destroy_saved_search(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |id|
Twitter::Utils.parallel_map(arguments.flatten) do |id|
object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options)
end
end
Expand Down
9 changes: 5 additions & 4 deletions lib/twitter/rest/api/tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'twitter/oembed'
require 'twitter/rest/api/utils'
require 'twitter/tweet'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -142,7 +143,7 @@ def update(status, options = {})
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
def retweet(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |tweet|
Twitter::Utils.parallel_map(arguments.flatten) do |tweet|
id = extract_id(tweet)
begin
post_retweet(id, arguments.options)
Expand All @@ -168,7 +169,7 @@ def retweet(*args)
# @option options [Boolean, String, Integer] :trim_user Each tweet returned in a timeline will include a user object with only the author's numerical ID when set to true, 't' or 1.
def retweet!(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |tweet|
Twitter::Utils.parallel_map(arguments.flatten) do |tweet|
id = extract_id(tweet)
begin
post_retweet(id, arguments.options)
Expand Down Expand Up @@ -249,7 +250,7 @@ def oembed(tweet, options = {})
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
def oembeds(*args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |tweet|
Twitter::Utils.parallel_map(arguments.flatten) do |tweet|
id = extract_id(tweet)
oembed(id, arguments.options)
end
Expand Down Expand Up @@ -281,7 +282,7 @@ def retweeters_ids(*args)
# @return [Array<Twitter::Tweet>]
def threaded_tweets_from_response(request_method, path, args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |tweet|
Twitter::Utils.parallel_map(arguments.flatten) do |tweet|
id = extract_id(tweet)
object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", arguments.options)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/twitter/rest/api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
require 'twitter/rest/api/utils'
require 'twitter/settings'
require 'twitter/user'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -226,7 +227,7 @@ def unblock(*args)
def users(*args)
arguments = Twitter::Arguments.new(args)
method = arguments.options.delete(:method) || :post
Util.parallel_map(arguments.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users|
Twitter::Utils.parallel_map(arguments.flatten.each_slice(MAX_USERS_PER_REQUEST)) do |users|
objects_from_response(Twitter::User, method, '/1.1/users/lookup.json', merge_users(arguments.options, users))
end.flatten
end
Expand Down
5 changes: 3 additions & 2 deletions lib/twitter/rest/api/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'twitter/arguments'
require 'twitter/cursor'
require 'twitter/user'
require 'twitter/utils'

module Twitter
module REST
Expand Down Expand Up @@ -50,7 +51,7 @@ def extract_id(object)
# @return [Array<Twitter::User>]
def threaded_user_objects_from_response(request_method, path, args)
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |user|
Twitter::Utils.parallel_map(arguments.flatten) do |user|
object_from_response(Twitter::User, request_method, path, merge_user(arguments.options, user))
end
end
Expand Down Expand Up @@ -102,7 +103,7 @@ def objects_from_array(klass, array)
# @return [Array]
def threaded_objects_from_response(klass, request_method, path, args) # rubocop:disable ParameterLists
arguments = Twitter::Arguments.new(args)
Util.parallel_map(arguments.flatten) do |object|
Twitter::Utils.parallel_map(arguments.flatten) do |object|
id = extract_id(object)
object_from_response(klass, request_method, path, arguments.options.merge(:id => id))
end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/util.rb → lib/twitter/utils.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Twitter
module Util
module Utils
class << self
def parallel_map(enumerable)
# Don't bother spawning a new thread if there's only one item
Expand Down

0 comments on commit ca21c5b

Please sign in to comment.