Skip to content

Commit

Permalink
Rename utility methods to be less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Nov 4, 2014
1 parent 0c9f9d6 commit 2b1ccec
Show file tree
Hide file tree
Showing 16 changed files with 169 additions and 205 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ end

require 'yardstick/rake/verify'
Yardstick::Rake::Verify.new do |verify|
verify.threshold = 59.6
verify.threshold = 59.4
end

task :default => [:spec, :rubocop, :verify_measurements]
8 changes: 4 additions & 4 deletions lib/twitter/rest/direct_messages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module DirectMessages
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
# @option options [Integer] :page Specifies the page of results to retrieve.
def direct_messages_received(options = {})
perform_with_objects(:get, '/1.1/direct_messages.json', options, Twitter::DirectMessage)
get_with_objects('/1.1/direct_messages.json', options, Twitter::DirectMessage)
end

# Returns the 20 most recent direct messages sent by the authenticating user
Expand All @@ -42,7 +42,7 @@ def direct_messages_received(options = {})
# @option options [Integer] :count Specifies the number of records to retrieve. Must be less than or equal to 200.
# @option options [Integer] :page Specifies the page of results to retrieve.
def direct_messages_sent(options = {})
perform_with_objects(:get, '/1.1/direct_messages/sent.json', options, Twitter::DirectMessage)
get_with_objects('/1.1/direct_messages/sent.json', options, Twitter::DirectMessage)
end

# Returns a direct message
Expand All @@ -57,7 +57,7 @@ def direct_messages_sent(options = {})
# @param options [Hash] A customizable set of options.
def direct_message(id, options = {})
options[:id] = id
perform_with_object(:get, '/1.1/direct_messages/show.json', options, Twitter::DirectMessage)
get_with_object('/1.1/direct_messages/show.json', options, Twitter::DirectMessage)
end

# @note This method requires an access token with RWD (read, write & direct message) permissions. Consult The Application Permission Model for more information.
Expand Down Expand Up @@ -127,7 +127,7 @@ def destroy_direct_message(*args)
def create_direct_message(user, text, options = {})
merge_user!(options, user)
options[:text] = text
perform_with_object(:post, '/1.1/direct_messages/new.json', options, Twitter::DirectMessage)
post_with_object('/1.1/direct_messages/new.json', options, Twitter::DirectMessage)
end
alias_method :d, :create_direct_message
alias_method :m, :create_direct_message
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/rest/favorites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module Favorites
def favorites(*args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop) if arguments.last
perform_with_objects(:get, '/1.1/favorites/list.json', arguments.options, Twitter::Tweet)
get_with_objects('/1.1/favorites/list.json', arguments.options, Twitter::Tweet)
end

# Un-favorites the specified Tweets as the authenticating user
Expand Down Expand Up @@ -70,7 +70,7 @@ def favorite(*args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |tweet|
begin
perform_with_object(:post, '/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet)
post_with_object('/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet)
rescue Twitter::Error::AlreadyFavorited, Twitter::Error::NotFound
next
end
Expand All @@ -97,7 +97,7 @@ def favorite(*args)
def favorite!(*args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |tweet|
perform_with_object(:post, '/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet)
post_with_object('/1.1/favorites/create.json', arguments.options.merge(:id => extract_id(tweet)), Twitter::Tweet)
end
end
alias_method :create_favorite!, :favorite!
Expand Down
12 changes: 6 additions & 6 deletions lib/twitter/rest/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def follower_ids(*args)
def friendships(*args)
arguments = Twitter::Arguments.new(args)
merge_users!(arguments.options, arguments)
perform_with_objects(:get, '/1.1/friendships/lookup.json', arguments.options, Twitter::User)
get_with_objects('/1.1/friendships/lookup.json', arguments.options, Twitter::User)
end

# Returns an array of numeric IDs for every user who has a pending request to follow the authenticating user
Expand All @@ -75,7 +75,7 @@ def friendships(*args)
# @return [Twitter::Cursor]
# @param options [Hash] A customizable set of options.
def friendships_incoming(options = {})
perform_with_cursor(:get, '/1.1/friendships/incoming.json', options, :ids)
get_with_cursor('/1.1/friendships/incoming.json', options, :ids)
end

# Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
Expand All @@ -87,7 +87,7 @@ def friendships_incoming(options = {})
# @return [Twitter::Cursor]
# @param options [Hash] A customizable set of options.
def friendships_outgoing(options = {})
perform_with_cursor(:get, '/1.1/friendships/outgoing.json', options, :ids)
get_with_cursor('/1.1/friendships/outgoing.json', options, :ids)
end

# Allows the authenticating user to follow the specified users, unless they are already followed
Expand Down Expand Up @@ -132,7 +132,7 @@ def follow(*args)
def follow!(*args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |user|
perform_with_object(:post, '/1.1/friendships/create.json', merge_user(arguments.options, user), Twitter::User)
post_with_object('/1.1/friendships/create.json', merge_user(arguments.options, user), Twitter::User)
end.compact
end
alias_method :create_friendship!, :follow!
Expand Down Expand Up @@ -169,7 +169,7 @@ def unfollow(*args)
# @option options [Boolean] :retweets Enable/disable retweets from the target user.
def friendship_update(user, options = {})
merge_user!(options, user)
perform_with_object(:post, '/1.1/friendships/update.json', options, Twitter::Relationship)
post_with_object('/1.1/friendships/update.json', options, Twitter::Relationship)
end

# Returns detailed information about the relationship between two users
Expand All @@ -187,7 +187,7 @@ def friendship(source, target, options = {})
options[:source_id] = options.delete(:source_user_id) unless options[:source_user_id].nil?
merge_user!(options, target, 'target')
options[:target_id] = options.delete(:target_user_id) unless options[:target_user_id].nil?
perform_with_object(:get, '/1.1/friendships/show.json', options, Twitter::Relationship)
get_with_object('/1.1/friendships/show.json', options, Twitter::Relationship)
end
alias_method :friendship_show, :friendship
alias_method :relationship, :friendship
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/rest/help.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Help
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Twitter::Configuration] Twitter's configuration.
def configuration(options = {})
perform_with_object(:get, '/1.1/help/configuration.json', options, Twitter::Configuration)
get_with_object('/1.1/help/configuration.json', options, Twitter::Configuration)
end

# Returns the list of languages supported by Twitter
Expand All @@ -27,7 +27,7 @@ def configuration(options = {})
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [Array<Twitter::Language>]
def languages(options = {})
perform_with_objects(:get, '/1.1/help/languages.json', options, Twitter::Language)
get_with_objects('/1.1/help/languages.json', options, Twitter::Language)
end

# Returns {https://twitter.com/privacy Twitter's Privacy Policy}
Expand Down
30 changes: 15 additions & 15 deletions lib/twitter/rest/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def list_timeline(*args)
arguments = Twitter::Arguments.new(args)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
perform_with_objects(:get, '/1.1/lists/statuses.json', arguments.options, Twitter::Tweet)
get_with_objects('/1.1/lists/statuses.json', arguments.options, Twitter::Tweet)
end

# Removes the specified member from the list
Expand All @@ -81,7 +81,7 @@ def list_timeline(*args)
# @param user_to_remove [Integer, String] The user id or screen name of the list member to remove.
# @param options [Hash] A customizable set of options.
def remove_list_member(*args)
list_from_response_with_user(:post, '/1.1/lists/members/destroy.json', args)
list_from_response_with_user('/1.1/lists/members/destroy.json', args)
end
deprecate_alias :list_remove_member, :remove_list_member

Expand Down Expand Up @@ -121,7 +121,7 @@ def memberships(*args)
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
# @param options [Hash] A customizable set of options.
def list_subscribers(*args)
cursor_from_response_with_list(:get, '/1.1/lists/subscribers.json', args)
cursor_from_response_with_list('/1.1/lists/subscribers.json', args)
end

# Make the authenticated user follow the specified list
Expand Down Expand Up @@ -204,7 +204,7 @@ def list_unsubscribe(*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 add_list_members(*args)
list_from_response_with_users(:post, '/1.1/lists/members/create_all.json', args)
list_from_response_with_users('/1.1/lists/members/create_all.json', args)
end
deprecate_alias :list_add_members, :add_list_members

Expand Down Expand Up @@ -245,7 +245,7 @@ def list_member?(*args)
# @param list [Integer, String, Twitter::List] A Twitter list ID, slug, URI, or object.
# @param options [Hash] A customizable set of options.
def list_members(*args)
cursor_from_response_with_list(:get, '/1.1/lists/members.json', args)
cursor_from_response_with_list('/1.1/lists/members.json', args)
end

# Add a member to a list
Expand All @@ -267,7 +267,7 @@ def list_members(*args)
# @param user_to_add [Integer, String] The user id or screen name to add to the list.
# @param options [Hash] A customizable set of options.
def add_list_member(*args)
list_from_response_with_user(:post, '/1.1/lists/members/create.json', args)
list_from_response_with_user('/1.1/lists/members/create.json', args)
end
deprecate_alias :list_add_member, :add_list_member

Expand Down Expand Up @@ -328,7 +328,7 @@ def list_update(*args)
# @option options [String] :mode ('public') Whether your list is public or private. Values can be 'public' or 'private'.
# @option options [String] :description The description to give the list.
def create_list(name, options = {})
perform_with_object(:post, '/1.1/lists/create.json', options.merge(:name => name), Twitter::List)
post_with_object('/1.1/lists/create.json', options.merge(:name => name), Twitter::List)
end
deprecate_alias :list_create, :create_list

Expand Down Expand Up @@ -386,7 +386,7 @@ def subscriptions(*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 remove_list_members(*args)
list_from_response_with_users(:post, '/1.1/lists/members/destroy_all.json', args)
list_from_response_with_users('/1.1/lists/members/destroy_all.json', args)
end
deprecate_alias :list_remove_members, :remove_list_members

Expand Down Expand Up @@ -420,14 +420,14 @@ def list_from_response(request_method, path, args)
arguments = Twitter::Arguments.new(args)
merge_list!(arguments.options, arguments.pop)
merge_owner!(arguments.options, arguments.pop)
perform_with_object(request_method, path, arguments.options, Twitter::List)
request_with_object(request_method, path, arguments.options, Twitter::List)
end

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

def list_user?(request_method, path, args)
Expand All @@ -441,22 +441,22 @@ def list_user?(request_method, path, args)
false
end

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

def list_from_response_with_users(request_method, path, args)
def list_from_response_with_users(path, args)
arguments = args.dup
options = arguments.last.is_a?(::Hash) ? arguments.pop : {}
members = arguments.pop
merge_list!(options, arguments.pop)
merge_owner!(options, arguments.pop)
pmap(members.each_slice(MAX_USERS_PER_REQUEST)) do |users|
perform_with_object(request_method, path, merge_users(options, users), Twitter::List)
post_with_object(path, merge_users(options, users), Twitter::List)
end.last
end

Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/rest/oauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module OAuth
def token(options = {})
options[:bearer_token_request] = true
options[:grant_type] ||= 'client_credentials'
perform_with_object(:post, '/oauth2/token', options, Twitter::Token)
post_with_object('/oauth2/token', options, Twitter::Token)
end
alias_method :bearer_token, :token

Expand All @@ -42,7 +42,7 @@ def token(options = {})
def invalidate_token(access_token, options = {})
access_token = access_token.access_token if access_token.is_a?(Twitter::Token)
options[:access_token] = access_token
perform_with_object(:post, '/oauth2/invalidate_token', options, Twitter::Token)
post_with_object('/oauth2/invalidate_token', options, Twitter::Token)
end

# Allows a registered application to revoke an issued OAuth 2 Bearer Token by presenting its client credentials.
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/rest/places_and_geo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module PlacesAndGeo
# @param options [Hash] A customizable set of options.
# @return [Twitter::Place] The requested place.
def place(place_id, options = {})
perform_with_object(:get, "/1.1/geo/id/#{place_id}.json", options, Twitter::Place)
get_with_object("/1.1/geo/id/#{place_id}.json", options, Twitter::Place)
end

# Searches for up to 20 places that can be used as a place_id
Expand All @@ -36,7 +36,7 @@ def place(place_id, options = {})
# @option options [Integer] :max_results A hint as to the number of results to return. This does not guarantee that the number of results returned will equal max_results, but instead informs how many "nearby" results to return. Ideally, only pass in the number of places you intend to display to the user here.
# @return [Array<Twitter::Place>]
def reverse_geocode(options = {})
perform_with_object(:get, '/1.1/geo/reverse_geocode.json', options, Twitter::GeoResults)
get_with_object('/1.1/geo/reverse_geocode.json', options, Twitter::GeoResults)
end

# Search for places that can be attached to a {Twitter::REST::Tweets#update}
Expand All @@ -57,7 +57,7 @@ def reverse_geocode(options = {})
# @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
# @return [Array<Twitter::Place>]
def geo_search(options = {})
perform_with_object(:get, '/1.1/geo/search.json', options, Twitter::GeoResults)
get_with_object('/1.1/geo/search.json', options, Twitter::GeoResults)
end
alias_method :places_nearby, :geo_search

Expand All @@ -76,7 +76,7 @@ def geo_search(options = {})
# @option options [String] :"attribute:street_address" This option searches for places which have this given street address. There are other well-known and application-specific attributes available. Custom attributes are also permitted.
# @return [Array<Twitter::Place>]
def similar_places(options = {})
perform_with_object(:get, '/1.1/geo/similar_places.json', options, Twitter::GeoResults)
get_with_object('/1.1/geo/similar_places.json', options, Twitter::GeoResults)
end
alias_method :places_similar, :similar_places
end
Expand Down
8 changes: 4 additions & 4 deletions lib/twitter/rest/saved_searches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module SavedSearches
def saved_searches(*args)
arguments = Twitter::Arguments.new(args)
if arguments.empty?
perform_with_objects(:get, '/1.1/saved_searches/list.json', arguments.options, Twitter::SavedSearch)
get_with_objects('/1.1/saved_searches/list.json', arguments.options, Twitter::SavedSearch)
else
pmap(arguments) do |id|
saved_search(id, arguments.options)
Expand All @@ -51,7 +51,7 @@ def saved_searches(*args)
# @param id [Integer] The ID of the saved search.
# @param options [Hash] A customizable set of options.
def saved_search(id, options = {})
perform_with_object(:get, "/1.1/saved_searches/show/#{id}.json", options, Twitter::SavedSearch)
get_with_object("/1.1/saved_searches/show/#{id}.json", options, Twitter::SavedSearch)
end

# Creates a saved search for the authenticated user
Expand All @@ -64,7 +64,7 @@ def saved_search(id, options = {})
# @param query [String] The query of the search the user would like to save.
# @param options [Hash] A customizable set of options.
def create_saved_search(query, options = {})
perform_with_object(:post, '/1.1/saved_searches/create.json', options.merge(:query => query), Twitter::SavedSearch)
post_with_object('/1.1/saved_searches/create.json', options.merge(:query => query), Twitter::SavedSearch)
end
deprecate_alias :saved_search_create, :create_saved_search

Expand All @@ -84,7 +84,7 @@ def create_saved_search(query, options = {})
def destroy_saved_search(*args)
arguments = Twitter::Arguments.new(args)
pmap(arguments) do |id|
perform_with_object(:post, "/1.1/saved_searches/destroy/#{id}.json", arguments.options, Twitter::SavedSearch)
post_with_object("/1.1/saved_searches/destroy/#{id}.json", arguments.options, Twitter::SavedSearch)
end
end
deprecate_alias :saved_search_destroy, :destroy_saved_search
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/rest/suggested_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ module SuggestedUsers
def suggestions(*args)
arguments = Twitter::Arguments.new(args)
if arguments.last
perform_with_object(:get, "/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion)
get_with_object("/1.1/users/suggestions/#{arguments.pop}.json", arguments.options, Twitter::Suggestion)
else
perform_with_objects(:get, '/1.1/users/suggestions.json', arguments.options, Twitter::Suggestion)
get_with_objects('/1.1/users/suggestions.json', arguments.options, Twitter::Suggestion)
end
end

Expand All @@ -42,7 +42,7 @@ def suggestions(*args)
# @param options [Hash] A customizable set of options.
# @return [Array<Twitter::User>]
def suggest_users(slug, options = {})
perform_with_objects(:get, "/1.1/users/suggestions/#{slug}/members.json", options, Twitter::User)
get_with_objects("/1.1/users/suggestions/#{slug}/members.json", options, Twitter::User)
end
end
end
Expand Down
Loading

0 comments on commit 2b1ccec

Please sign in to comment.