Skip to content

Commit

Permalink
Use (immutable) user ID instead of (mutable) screen name
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 3, 2014
1 parent 3fb0ec0 commit ceeccb0
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 140 deletions.
6 changes: 4 additions & 2 deletions lib/twitter/rest/lists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,12 @@ def merge_list!(hash, list) # rubocop:disable MethodLength
# @param user[Integer, String, Twitter::User] A Twitter user ID, screen_name, or object.
# @return [Hash]
def merge_owner!(hash, user)
unless hash[:owner_id] || hash[:owner_screen_name]
user ||= screen_name
return hash if hash[:owner_id] || hash[:owner_screen_name]
if user
merge_user!(hash, user, 'owner')
hash[:owner_id] = hash.delete(:owner_user_id) unless hash[:owner_user_id].nil?
else
hash[:owner_id] = user_id
end
hash
end
Expand Down
6 changes: 3 additions & 3 deletions lib/twitter/rest/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ def users(*args)
# @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::Arguments.new(args)
if arguments.last || screen_name?
merge_user!(arguments.options, arguments.pop || screen_name)
if arguments.last || user_id?
merge_user!(arguments.options, arguments.pop || user_id)
perform_with_object(:get, '/1.1/users/show.json', arguments.options, Twitter::User)
else
verify_credentials(arguments.options)
Expand Down Expand Up @@ -375,7 +375,7 @@ def update_profile_banner(banner, options = {})
# @param user [Integer, String, Twitter::User] A Twitter user ID, screen name, URI, or object.
def profile_banner(*args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options[:user_id] || arguments.options[:screen_name]
perform_with_object(:get, '/1.1/users/profile_banner.json', arguments.options, Twitter::ProfileBanner)
end
end
Expand Down
12 changes: 6 additions & 6 deletions lib/twitter/rest/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def parallel_user_objects_from_response(request_method, path, args)
# @return [Array<Twitter::User>]
def user_objects_from_response(request_method, path, args)
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options[:user_id] || arguments.options[:screen_name]
perform_with_objects(request_method, path, arguments.options, Twitter::User)
end

Expand Down Expand Up @@ -110,16 +110,16 @@ def parallel_objects_from_response(klass, request_method, path, args)
# @return [Twitter::Cursor]
def cursor_from_response_with_user(collection_name, klass, request_method, path, args) # rubocop:disable ParameterLists
arguments = Twitter::Arguments.new(args)
merge_user!(arguments.options, arguments.pop || screen_name) unless arguments.options[:user_id] || arguments.options[:screen_name]
merge_user!(arguments.options, arguments.pop || user_id) unless arguments.options[:user_id] || arguments.options[:screen_name]
perform_with_cursor(request_method, path, arguments.options, collection_name, klass)
end

def screen_name
@screen_name ||= verify_credentials.screen_name
def user_id
@user_id ||= verify_credentials.id
end

def screen_name?
instance_variable_defined?(:@screen_name)
def user_id?
instance_variable_defined?(:@user_id)
end

def merge_default_cursor!(options)
Expand Down
Loading

0 comments on commit ceeccb0

Please sign in to comment.