Skip to content

Commit

Permalink
Remove Array core extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 21, 2012
1 parent 9d3c213 commit 2d00f99
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/twitter/api/direct_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def direct_message(id, options={})
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
# @param options [Hash] A customizable set of options.
def direct_messages(*args)
options = args.extract_options!
options = extract_options!(args)
if args.empty?
direct_messages_received(options)
else
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/api/favorites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Favorites
# @example Return the 20 most recent favorite Tweets for @sferik
# Twitter.favorites('sferik')
def favorites(*args)
options = args.extract_options!
options = extract_options!(args)
if user = args.pop
options.merge_user!(user)
end
Expand Down Expand Up @@ -76,7 +76,7 @@ def unfavorite(*args)
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
# @param options [Hash] A customizable set of options.
def favorite(*args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
begin
object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", options.merge(:id => id))
Expand Down Expand Up @@ -106,7 +106,7 @@ def favorite(*args)
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
# @param options [Hash] A customizable set of options.
def favorite!(*args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
begin
object_from_response(Twitter::Tweet, :post, "/1.1/favorites/create.json", options.merge(:id => id))
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def follower_ids(*args)
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
# @param options [Hash] A customizable set of options.
def friendships(*args)
options = args.extract_options!
options = extract_options!(args)
options.merge_users!(Array(args))
collection_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", options)
end
Expand Down Expand Up @@ -129,7 +129,7 @@ def friendships_outgoing(options={})
# @param options [Hash] A customizable set of options.
# @option options [Boolean] :follow (false) Enable notifications for the target user.
def follow(*args)
options = args.extract_options!
options = extract_options!(args)
# Twitter always turns on notifications if the "follow" option is present, even if it's set to false
# so only send follow if it's true
options[:follow] = true if !!options.delete(:follow)
Expand Down Expand Up @@ -159,7 +159,7 @@ def follow(*args)
# @param options [Hash] A customizable set of options.
# @option options [Boolean] :follow (false) Enable notifications for the target user.
def follow!(*args)
options = args.extract_options!
options = extract_options!(args)
# Twitter always turns on notifications if the "follow" option is present, even if it's set to false
# so only send follow if it's true
options[:follow] = true if !!options.delete(:follow)
Expand Down
14 changes: 7 additions & 7 deletions lib/twitter/api/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def lists(*args)
# Twitter.list_timeline(7505382, 'presidents')
# Twitter.list_timeline(7505382, 8863586)
def list_timeline(*args)
options = args.extract_options!
options = extract_options!(args)
options.merge_list!(args.pop)
options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
collection_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", options)
Expand Down Expand Up @@ -511,7 +511,7 @@ def list_remove_members(*args)
# @param args [Array]
# @return [Array<Twitter::User>]
def list_from_response(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
options.merge_list!(args.pop)
options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
object_from_response(Twitter::List, request_method, path, options)
Expand All @@ -522,22 +522,22 @@ def list_from_response(request_method, path, args)
# @param args [Array]
# @return [Array<Twitter::List>]
def lists_from_response(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
merge_default_cursor!(options)
options.merge_user!(args.pop)
cursor_from_response(:lists, Twitter::List, request_method, path, options, calling_method)
end

def list_users(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
merge_default_cursor!(options)
options.merge_list!(args.pop)
options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
cursor_from_response(:users, Twitter::User, request_method, path, options, calling_method)
end

def list_user?(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
options.merge_user!(args.pop)
options.merge_list!(args.pop)
options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
Expand All @@ -548,15 +548,15 @@ def list_user?(request_method, path, args)
end

def list_modify_member(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
options.merge_user!(args.pop)
options.merge_list!(args.pop)
options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
object_from_response(Twitter::List, request_method, path, options)
end

def list_modify_members(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
members = args.pop
options.merge_list!(args.pop)
options.merge_owner!(args.pop || screen_name) unless options[:owner_id] || options[:owner_screen_name]
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/api/saved_searches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module SavedSearches
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
# @param options [Hash] A customizable set of options.
def saved_searches(*args)
options = args.extract_options!
options = extract_options!(args)
if args.empty?
collection_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", options)
else
Expand Down Expand Up @@ -87,7 +87,7 @@ def saved_search_create(query, options={})
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
# @param options [Hash] A customizable set of options.
def saved_search_destroy(*args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", options)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/api/suggested_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module SuggestedUsers
# @example Return the users in the Art & Design category
# Twitter.suggestions("art-design")
def suggestions(*args)
options = args.extract_options!
options = extract_options!(args)
if slug = args.pop
object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", options)
else
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/api/tweets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def update(status, options={})
# @param options [Hash] A customizable set of 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)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
begin
post_retweet(id, options)
Expand All @@ -171,7 +171,7 @@ def retweet(*args)
# @param options [Hash] A customizable set of 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)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
begin
post_retweet(id, options)
Expand Down Expand Up @@ -248,7 +248,7 @@ def oembed(id, options={})
# @option options [String] :related A value for the TWT related parameter, as described in {https://dev.twitter.com/docs/intents Web Intents}. This value will be forwarded to all Web Intents calls.
# @option options [String] :lang Language code for the rendered embed. This will affect the text and localization of the rendered HTML.
def oembeds(*args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
object_from_response(Twitter::OEmbed, :get, "/1.1/statuses/oembed.json?id=#{id}", options)
end
Expand All @@ -261,7 +261,7 @@ def oembeds(*args)
# @param args [Array]
# @return [Array<Twitter::Tweet>]
def threaded_tweets_from_response(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", options)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/api/undocumented.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def activity_by_friends(options={})
# Twitter.following_followers_of('sferik')
# Twitter.following_followers_of(7505382) # Same as above
def following_followers_of(*args)
options = args.extract_options!
options = extract_options!(args)
merge_default_cursor!(options)
options.merge_user!(args.pop || screen_name)
cursor_from_response(:users, Twitter::User, :get, "/users/following_followers_of.json", options)
Expand Down Expand Up @@ -105,7 +105,7 @@ def status_activity(id, options={})
# @param ids [Array<Integer>, Set<Integer>] An array of Tweet IDs.
# @param options [Hash] A customizable set of options.
def statuses_activity(*args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
status_activity(id, options)
end
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def unblock(*args)
# @param users [Array<Integer, String, Twitter::User>, Set<Integer, String, Twitter::User>] An array of Twitter user IDs, screen names, or objects.
# @param options [Hash] A customizable set of options.
def users(*args)
options = args.extract_options!
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))
end.flatten
Expand All @@ -272,7 +272,7 @@ def users(*args)
# Twitter.user('sferik')
# Twitter.user(7505382) # Same as above
def user(*args)
options = args.extract_options!
options = extract_options!(args)
if user = args.pop
options.merge_user!(user)
object_from_response(Twitter::User, :get, "/1.1/users/show.json", options)
Expand Down Expand Up @@ -416,7 +416,7 @@ def update_profile_banner(banner, options={})
# Twitter.profile_banner('sferik')
# Twitter.profile_banner(7505382) # Same as above
def profile_banner(*args)
options = args.extract_options!
options = extract_options!(args)
options.merge_user!(args.pop || screen_name)
object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", options)
end
Expand Down
15 changes: 9 additions & 6 deletions lib/twitter/api/utils.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require 'twitter/core_ext/array'
require 'twitter/core_ext/enumerable'
require 'twitter/core_ext/hash'
require 'twitter/core_ext/kernel'
Expand Down Expand Up @@ -49,7 +48,7 @@ def object_from_response(klass, request_method, path, params={})
# @param args [Array]
# @return [Array]
def objects_from_response(klass, request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
options.merge_user!(args.pop)
collection_from_response(klass, request_method, path, options)
end
Expand All @@ -59,7 +58,7 @@ def objects_from_response(klass, request_method, path, args)
# @param args [Array]
# @return [Array<Integer>]
def ids_from_response(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
merge_default_cursor!(options)
options.merge_user!(args.pop)
cursor_from_response(:ids, nil, request_method, path, options, calling_method)
Expand All @@ -82,7 +81,7 @@ def cursor_from_response(collection_name, klass, request_method, path, params={}
# @param args [Array]
# @return [Array<Twitter::User>]
def users_from_response(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
options.merge_user!(args.pop || screen_name)
collection_from_response(Twitter::User, request_method, path, options)
end
Expand All @@ -92,7 +91,7 @@ def users_from_response(request_method, path, args)
# @param args [Array]
# @return [Array<Twitter::User>]
def threaded_users_from_response(request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |user|
object_from_response(Twitter::User, request_method, path, options.merge_user(user))
end
Expand All @@ -104,7 +103,7 @@ def threaded_users_from_response(request_method, path, args)
# @param args [Array]
# @return [Array]
def threaded_object_from_response(klass, request_method, path, args)
options = args.extract_options!
options = extract_options!(args)
args.flatten.threaded_map do |id|
object_from_response(klass, request_method, path, options.merge(:id => id))
end
Expand All @@ -126,6 +125,10 @@ def screen_name
@screen_name ||= verify_credentials.screen_name
end

def extract_options!(array)
array.last.is_a?(::Hash) ? array.pop : {}
end

end
end
end
7 changes: 0 additions & 7 deletions lib/twitter/core_ext/array.rb

This file was deleted.

0 comments on commit 2d00f99

Please sign in to comment.