Skip to content

Commit

Permalink
Move Twitter::Arguments out of REST::API namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Aug 18, 2013
1 parent fab85db commit 8faa153
Show file tree
Hide file tree
Showing 12 changed files with 57 additions and 61 deletions.
11 changes: 11 additions & 0 deletions lib/twitter/arguments.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Twitter
class Arguments < Array
attr_reader :options

def initialize(args)
@options = args.last.is_a?(::Hash) ? args.pop : {}
super(args)
end

end
end
15 changes: 0 additions & 15 deletions lib/twitter/rest/api/arguments.rb

This file was deleted.

6 changes: 3 additions & 3 deletions lib/twitter/rest/api/direct_messages.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/arguments'
require 'twitter/direct_message'
require 'twitter/rest/api/utils'
require 'twitter/user'

module Twitter
Expand Down Expand Up @@ -84,7 +84,7 @@ def direct_message(id, options={})
# @param ids [Enumerable<Integer>] A collection of direct message IDs.
# @param options [Hash] A customizable set of options.
def direct_messages(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
if arguments.empty?
direct_messages_received(arguments.options)
else
Expand Down
10 changes: 5 additions & 5 deletions lib/twitter/rest/api/favorites.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/arguments'
require 'twitter/error/already_favorited'
require 'twitter/error/forbidden'
require 'twitter/rest/api/utils'
require 'twitter/tweet'
require 'twitter/user'

Expand Down Expand Up @@ -30,7 +30,7 @@ module Favorites
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 100.
# @option options [Integer] :since_id Returns results with an ID greater than (that is, more recent than) the specified ID.
def favorites(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
if user = arguments.pop
merge_user!(arguments.options, user)
end
Expand Down Expand Up @@ -70,7 +70,7 @@ def unfavorite(*args)
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
# @param options [Hash] A customizable set of options.
def favorite(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |tweet|
id = extract_id(tweet)
begin
Expand Down Expand Up @@ -99,7 +99,7 @@ def favorite(*args)
# @param tweets [Enumerable<Integer, String, URI, Twitter::Tweet>] A collection of Tweet IDs, URIs, or objects.
# @param options [Hash] A customizable set of options.
def favorite!(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |tweet|
id = extract_id(tweet)
begin
Expand Down
10 changes: 5 additions & 5 deletions lib/twitter/rest/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/arguments'
require 'twitter/cursor'
require 'twitter/error/forbidden'
require 'twitter/relationship'
require 'twitter/rest/api/utils'
require 'twitter/user'

module Twitter
Expand Down Expand Up @@ -64,7 +64,7 @@ def follower_ids(*args)
# @param users [Enumerable<Integer, String, Twitter::User>] A collection of Twitter user IDs, screen names, or objects.
# @param options [Hash] A customizable set of options.
def friendships(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_users!(arguments.options, arguments)
objects_from_response(Twitter::User, :get, "/1.1/friendships/lookup.json", arguments.options)
end
Expand Down Expand Up @@ -109,7 +109,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)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(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
arguments.options[:follow] = true if !!arguments.options.delete(:follow)
Expand Down Expand Up @@ -137,7 +137,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)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(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
arguments.options[:follow] = true if !!arguments.options.delete(:follow)
Expand Down
16 changes: 8 additions & 8 deletions lib/twitter/rest/api/lists.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/arguments'
require 'twitter/core_ext/enumerable'
require 'twitter/cursor'
require 'twitter/error/forbidden'
require 'twitter/error/not_found'
require 'twitter/list'
require 'twitter/rest/api/utils'
require 'twitter/tweet'
require 'twitter/user'

Expand Down Expand Up @@ -56,7 +56,7 @@ def lists(*args)
# @option options [Integer] :max_id Returns results with an ID less than (that is, older than) or equal to the specified ID.
# @option options [Integer] :count The number of results to retrieve.
def list_timeline(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
objects_from_response(Twitter::Tweet, :get, "/1.1/lists/statuses.json", arguments.options)
Expand Down Expand Up @@ -401,21 +401,21 @@ def lists_owned(*args)
# @param args [Array]
# @return [Array<Twitter::User>]
def list_from_response(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
object_from_response(Twitter::List, request_method, path, arguments.options)
end

def cursor_from_response_with_list(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
cursor_from_response(:users, Twitter::User, request_method, path, arguments.options)
end

def list_user?(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
Expand All @@ -426,15 +426,15 @@ def list_user?(request_method, path, args)
end

def list_from_response_with_user(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
object_from_response(Twitter::List, request_method, path, arguments.options)
end

def list_from_response_with_users(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
members = arguments.pop
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/rest/api/saved_searches.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'twitter/rest/api/arguments'
require 'twitter/arguments'
require 'twitter/rest/api/utils'
require 'twitter/saved_search'

Expand Down Expand Up @@ -29,7 +29,7 @@ module SavedSearches
# @param ids [Enumerable<Integer>] A collection of saved search IDs.
# @param options [Hash] A customizable set of options.
def saved_searches(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
if arguments.empty?
objects_from_response(Twitter::SavedSearch, :get, "/1.1/saved_searches/list.json", arguments.options)
else
Expand Down Expand Up @@ -79,7 +79,7 @@ def saved_search_create(query, options={})
# @param ids [Enumerable<Integer>] A collection of saved search IDs.
# @param options [Hash] A customizable set of options.
def saved_search_destroy(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |id|
object_from_response(Twitter::SavedSearch, :post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/rest/api/suggested_users.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'twitter/rest/api/arguments'
require 'twitter/arguments'
require 'twitter/rest/api/utils'
require 'twitter/suggestion'
require 'twitter/user'
Expand All @@ -25,7 +25,7 @@ module SuggestedUsers
# @param slug [String] The short name of list or a category.
# @param options [Hash] A customizable set of options.
def suggestions(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
if slug = arguments.pop
object_from_response(Twitter::Suggestion, :get, "/1.1/users/suggestions/#{slug}.json", arguments.options)
else
Expand Down
16 changes: 8 additions & 8 deletions lib/twitter/rest/api/tweets.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/error/already_retweeted'
require 'twitter/arguments'
require 'twitter/error/already_posted'
require 'twitter/error/already_retweeted'
require 'twitter/error/forbidden'
require 'twitter/oembed'
require 'twitter/rest/api/utils'
require 'twitter/tweet'

module Twitter
Expand Down Expand Up @@ -138,7 +138,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)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |tweet|
id = extract_id(tweet)
begin
Expand All @@ -164,7 +164,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)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |tweet|
id = extract_id(tweet)
begin
Expand Down Expand Up @@ -239,7 +239,7 @@ def oembed(tweet, 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)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |tweet|
id = extract_id(tweet)
oembed(id, arguments.options)
Expand All @@ -259,7 +259,7 @@ def oembeds(*args)
# @param tweet [Integer, String, URI, Twitter::Tweet] A Tweet ID, URI, or object.
# @param options [Hash] A customizable set of options.
def retweeters_ids(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.options[:id] ||= extract_id(arguments.first)
cursor_from_response(:ids, nil, :get, "/1.1/statuses/retweeters/ids.json", arguments.options)
end
Expand All @@ -271,7 +271,7 @@ def retweeters_ids(*args)
# @param args [Array]
# @return [Array<Twitter::Tweet>]
def parallel_tweets_from_response(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |tweet|
id = extract_id(tweet)
object_from_response(Twitter::Tweet, request_method, path + "/#{id}.json", arguments.options)
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/api/undocumented.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'twitter/arguments'
require 'twitter/cursor'
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/tweet'
require 'twitter/user'
Expand Down
10 changes: 5 additions & 5 deletions lib/twitter/rest/api/users.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'twitter/arguments'
require 'twitter/core_ext/enumerable'
require 'twitter/error/not_found'
require 'twitter/profile_banner'
require 'twitter/rest/api/arguments'
require 'twitter/rest/api/utils'
require 'twitter/settings'
require 'twitter/user'
Expand Down Expand Up @@ -151,7 +151,7 @@ def blocking(options={})
# @overload block(options={})
# @param options [Hash] A customizable set of options.
def blocked_ids(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop)
cursor_from_response(:ids, nil, :get, "/1.1/blocks/ids.json", arguments.options)
end
Expand Down Expand Up @@ -226,7 +226,7 @@ def unblock(*args)
# @option options [Symbol, String] :method Requests users via a GET request instead of the standard POST request if set to ':get'.
# @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
def users(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
method = arguments.options.delete(:method) || :post
arguments.flatten.each_slice(MAX_USERS_PER_REQUEST).pmap do |users|
objects_from_response(Twitter::User, method, "/1.1/users/lookup.json", merge_users(arguments.options, users))
Expand All @@ -252,7 +252,7 @@ def users(*args)
# @option options [Boolean] :include_entities The tweet entities node will be disincluded when set to false.
# @option options [Boolean, String, Integer] :skip_status Do not include user's Tweets when set to true, 't' or 1.
def user(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
if user = arguments.pop
merge_user!(arguments.options, user)
object_from_response(Twitter::User, :get, "/1.1/users/show.json", arguments.options)
Expand Down Expand Up @@ -372,7 +372,7 @@ def update_profile_banner(banner, options={})
# @overload profile_banner(user, options={})
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
def profile_banner(*args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
object_from_response(Twitter::ProfileBanner, :get, "/1.1/users/profile_banner.json", arguments.options)
end
Expand Down
12 changes: 6 additions & 6 deletions lib/twitter/rest/api/utils.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'twitter/arguments'
require 'twitter/cursor'
require 'twitter/rest/api/arguments'
require 'twitter/user'
require 'uri'

Expand Down Expand Up @@ -35,7 +35,7 @@ def extract_id(object)
# @param args [Array]
# @return [Array<Twitter::User>]
def parallel_user_objects_from_response(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |user|
object_from_response(Twitter::User, request_method, path, merge_user(arguments.options, user))
end
Expand All @@ -46,7 +46,7 @@ def parallel_user_objects_from_response(request_method, path, args)
# @param args [Array]
# @return [Array<Twitter::User>]
def user_objects_from_response(request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
objects_from_response(Twitter::User, request_method, path, arguments.options)
end
Expand All @@ -57,7 +57,7 @@ def user_objects_from_response(request_method, path, args)
# @param args [Array]
# @return [Array]
def objects_from_response_with_user(klass, request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop)
objects_from_response(klass, request_method, path, arguments.options)
end
Expand Down Expand Up @@ -87,7 +87,7 @@ def objects_from_array(klass, array)
# @param args [Array]
# @return [Array]
def parallel_objects_from_response(klass, request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
arguments.flatten.pmap do |object|
id = extract_id(object)
object_from_response(klass, request_method, path, arguments.options.merge(:id => id))
Expand All @@ -111,7 +111,7 @@ def object_from_response(klass, request_method, path, options={})
# @param args [Array]
# @return [Twitter::Cursor]
def cursor_from_response_with_user(collection_name, klass, request_method, path, args)
arguments = Twitter::REST::API::Arguments.new(args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
cursor_from_response(collection_name, klass, request_method, path, arguments.options)
end
Expand Down

0 comments on commit 8faa153

Please sign in to comment.