Skip to content

Commit

Permalink
Remove Kernel#calling_method
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Dec 20, 2012
1 parent df33df9 commit 045d6e1
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
14 changes: 7 additions & 7 deletions lib/twitter/api/friends_and_followers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module FriendsAndFollowers
# Twitter.friend_ids('sferik')
# Twitter.friend_ids(7505382) # Same as above
def friend_ids(*args)
ids_from_response(:get, "/1.1/friends/ids.json", args)
ids_from_response(:get, "/1.1/friends/ids.json", args, :friend_ids)
end

# @see https://dev.twitter.com/docs/api/1.1/get/followers/ids
Expand All @@ -56,7 +56,7 @@ def friend_ids(*args)
# Twitter.follower_ids('sferik')
# Twitter.follower_ids(7505382) # Same as above
def follower_ids(*args)
ids_from_response(:get, "/1.1/followers/ids.json", args)
ids_from_response(:get, "/1.1/followers/ids.json", args, :follower_ids)
end

# Returns the relationship of the authenticating user to the comma separated list of up to 100 screen_names or user_ids provided. Values for connections can be: following, following_requested, followed_by, none.
Expand Down Expand Up @@ -94,7 +94,7 @@ def friendships(*args)
# Twitter.friendships_incoming
def friendships_incoming(options={})
merge_default_cursor!(options)
cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options)
cursor_from_response(:ids, nil, :get, "/1.1/friendships/incoming.json", options, :friendships_incoming)
end

# Returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request
Expand All @@ -110,7 +110,7 @@ def friendships_incoming(options={})
# Twitter.friendships_outgoing
def friendships_outgoing(options={})
merge_default_cursor!(options)
cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options)
cursor_from_response(:ids, nil, :get, "/1.1/friendships/outgoing.json", options, :friendships_outgoing)
end

# Allows the authenticating user to follow the specified users, unless they are already followed
Expand Down Expand Up @@ -282,7 +282,7 @@ def friendship?(source, target, options={})
# Twitter.followers('sferik')
# Twitter.followers(7505382) # Same as above
def followers(*args)
friends_or_followers_from_response(:get, "/1.1/followers/list.json", args)
friends_or_followers_from_response(:get, "/1.1/followers/list.json", args, :followers)
end

# Returns a cursored collection of user objects for every user the specified user is following (otherwise known as their "friends").
Expand Down Expand Up @@ -313,7 +313,7 @@ def followers(*args)
# Twitter.friends('sferik')
# Twitter.friends(7505382) # Same as above
def friends(*args)
friends_or_followers_from_response(:get, "/1.1/friends/list.json", args)
friends_or_followers_from_response(:get, "/1.1/friends/list.json", args, :friends)
end
alias following friends

Expand All @@ -323,7 +323,7 @@ def friends(*args)
# @param path [String]
# @param args [Array]
# @return [Array<Integer>]
def friends_or_followers_from_response(request_method, path, args)
def friends_or_followers_from_response(request_method, path, args, calling_method)
options = extract_options!(args)
merge_default_cursor!(options)
merge_user!(options, args.pop || screen_name) unless options[:user_id] || options[:screen_name]
Expand Down
12 changes: 6 additions & 6 deletions lib/twitter/api/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def list_remove_member(*args)
# Twitter.memberships('sferik')
# Twitter.memberships(7505382)
def memberships(*args)
lists_from_response(:get, "/1.1/lists/memberships.json", args)
lists_from_response(:get, "/1.1/lists/memberships.json", args, :memberships)
end

# Returns the subscribers of the specified list
Expand All @@ -147,7 +147,7 @@ def memberships(*args)
# Twitter.list_subscribers('sferik', 8863586)
# Twitter.list_subscribers(7505382, 'presidents')
def list_subscribers(*args)
list_users(:get, "/1.1/lists/subscribers.json", args)
list_users(:get, "/1.1/lists/subscribers.json", args, :list_subscribers)
end

# Make the authenticated user follow the specified list
Expand Down Expand Up @@ -315,7 +315,7 @@ def list_member?(*args)
# Twitter.list_members(7505382, 'presidents')
# Twitter.list_members(7505382, 8863586)
def list_members(*args)
list_users(:get, "/1.1/lists/members.json", args)
list_users(:get, "/1.1/lists/members.json", args, :list_members)
end

# Add a member to a list
Expand Down Expand Up @@ -469,7 +469,7 @@ def list(*args)
# Twitter.subscriptions('sferik')
# Twitter.subscriptions(7505382)
def subscriptions(*args)
lists_from_response(:get, "/1.1/lists/subscriptions.json", args)
lists_from_response(:get, "/1.1/lists/subscriptions.json", args, :subscriptions)
end

# Removes specified members from the list
Expand Down Expand Up @@ -521,14 +521,14 @@ def list_from_response(request_method, path, args)
# @param path [String]
# @param args [Array]
# @return [Array<Twitter::List>]
def lists_from_response(request_method, path, args)
def lists_from_response(request_method, path, args, calling_method)
options = extract_options!(args)
merge_default_cursor!(options)
merge_user!(options, args.pop || screen_name) unless options[:user_id] || options[:screen_name]
cursor_from_response(:lists, Twitter::List, request_method, path, options, calling_method)
end

def list_users(request_method, path, args)
def list_users(request_method, path, args, calling_method)
options = extract_options!(args)
merge_default_cursor!(options)
merge_list!(options, args.pop)
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/api/undocumented.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def following_followers_of(*args)
options = extract_options!(args)
merge_default_cursor!(options)
merge_user!(options, args.pop || screen_name) unless options[:user_id] || options[:screen_name]
cursor_from_response(:users, Twitter::User, :get, "/users/following_followers_of.json", options)
cursor_from_response(:users, Twitter::User, :get, "/users/following_followers_of.json", options, :following_followers_of)
end

# Returns activity summary for a Tweet
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/api/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def update_profile_image(image, options={})
# Twitter.blocking
def blocking(options={})
merge_default_cursor!(options)
cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options)
cursor_from_response(:users, Twitter::User, :get, "/1.1/blocks/list.json", options, :blocking)
end

# Returns an array of numeric user ids the authenticating user is blocking
Expand All @@ -163,7 +163,7 @@ def blocking(options={})
# @overload block(options={})
# @param options [Hash] A customizable set of options.
def blocked_ids(*args)
ids_from_response(:get, "/1.1/blocks/ids.json", args)
ids_from_response(:get, "/1.1/blocks/ids.json", args, :blocked_ids)
end

# Returns true if the authenticating user is blocking a target user
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/api/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def objects_from_response(klass, request_method, path, args)
# @param path [String]
# @param args [Array]
# @return [Array<Integer>]
def ids_from_response(request_method, path, args)
def ids_from_response(request_method, path, args, calling_method)
options = extract_options!(args)
merge_default_cursor!(options)
merge_user!(options, args.pop)
Expand All @@ -68,7 +68,7 @@ def ids_from_response(request_method, path, args)
# @param params [Hash]
# @param method_name [Symbol]
# @return [Twitter::Cursor]
def cursor_from_response(collection_name, klass, request_method, path, params={}, method_name=calling_method)
def cursor_from_response(collection_name, klass, request_method, path, params, method_name)
response = send(request_method.to_sym, path, params)
Twitter::Cursor.from_response(response, collection_name.to_sym, klass, self, method_name, params)
end
Expand Down
4 changes: 0 additions & 4 deletions lib/twitter/core_ext/kernel.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
module Kernel

def calling_method
caller[1][/`([^']*)'/, 1].to_sym
end

# Returns the object's singleton class (exists in Ruby 1.9.2)
def singleton_class; class << self; self; end; end unless method_defined?(:singleton_class)

Expand Down

0 comments on commit 045d6e1

Please sign in to comment.