Permalink
Browse files

Remove Array core extensions

  • Loading branch information...
1 parent 9d3c213 commit 2d00f99f4ac43e13e24bf90fcc813252175273f2 @sferik committed Nov 21, 2012
@@ -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
@@ -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
@@ -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))
@@ -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))
@@ -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
@@ -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)
@@ -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)
View
@@ -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)
@@ -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)
@@ -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]
@@ -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]
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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)
@@ -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
@@ -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
@@ -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)
@@ -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
View
@@ -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
@@ -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)
@@ -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
View
@@ -1,4 +1,3 @@
-require 'twitter/core_ext/array'
require 'twitter/core_ext/enumerable'
require 'twitter/core_ext/hash'
require 'twitter/core_ext/kernel'
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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
@@ -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
@@ -1,7 +0,0 @@
-class Array
-
- def extract_options!
- last.is_a?(::Hash) ? pop : {}
- end unless method_defined?(:extract_options!)
-
-end

0 comments on commit 2d00f99

Please sign in to comment.