From 38c9dd0a720ea857ff6220b28f66db4c780a7fda Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Tue, 22 Feb 2011 09:14:44 -0500 Subject: [PATCH] Remove clean_screen_name! utility method --- lib/twitter/client/favorites.rb | 1 - lib/twitter/client/list.rb | 8 -------- lib/twitter/client/list_members.rb | 5 ----- lib/twitter/client/list_subscribers.rb | 4 ---- lib/twitter/client/user.rb | 1 - lib/twitter/client/utils.rb | 10 ---------- spec/twitter/client/user_spec.rb | 21 ++------------------- 7 files changed, 2 insertions(+), 48 deletions(-) diff --git a/lib/twitter/client/favorites.rb b/lib/twitter/client/favorites.rb index 7b100bc55..3ff9dd153 100644 --- a/lib/twitter/client/favorites.rb +++ b/lib/twitter/client/favorites.rb @@ -27,7 +27,6 @@ module Favorites def favorites(*args) options = args.last.is_a?(Hash) ? args.pop : {} user = args.first - clean_screen_name!(user) response = get(['favorites', user].compact.join('/'), options) format.to_s.downcase == 'xml' ? response['statuses'] : response end diff --git a/lib/twitter/client/list.rb b/lib/twitter/client/list.rb index e9f2f7b1a..20eca5621 100644 --- a/lib/twitter/client/list.rb +++ b/lib/twitter/client/list.rb @@ -24,7 +24,6 @@ def list_create(*args) options = args.last.is_a?(Hash) ? args.pop : {} name = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = post("#{screen_name}/lists", options.merge(:name => name)) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -48,7 +47,6 @@ def list_update(*args) options = args.last.is_a?(Hash) ? args.pop : {} name = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = put("#{screen_name}/lists/#{name}", options) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -77,7 +75,6 @@ def lists(*args) options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {}) screen_name = args.first if screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/lists", options) else response = get('lists', options) @@ -103,7 +100,6 @@ def list(*args) options = args.last.is_a?(Hash) ? args.pop : {} id = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/lists/#{id}", options) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -126,7 +122,6 @@ def list_delete(*args) options = args.last.is_a?(Hash) ? args.pop : {} id = args.pop screen_name = args.pop || get_screeen_name - clean_screen_name!(screen_name) response = delete("#{screen_name}/lists/#{id}", options) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -153,7 +148,6 @@ def list_timeline(*args) options = args.last.is_a?(Hash) ? args.pop : {} name = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/lists/#{name}/statuses", options) format.to_s.downcase == 'xml' ? response['statuses'] : response end @@ -174,7 +168,6 @@ def list_timeline(*args) def memberships(*args) options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {}) screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/lists/memberships", options) format.to_s.downcase == 'xml' ? response['lists_list'] : response end @@ -195,7 +188,6 @@ def memberships(*args) def subscriptions(*args) options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {}) screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/lists/subscriptions", options) format.to_s.downcase == 'xml' ? response['lists_list'] : response end diff --git a/lib/twitter/client/list_members.rb b/lib/twitter/client/list_members.rb index 63ab32e47..7ed8e2a33 100644 --- a/lib/twitter/client/list_members.rb +++ b/lib/twitter/client/list_members.rb @@ -23,7 +23,6 @@ def list_members(*args) options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {}) list_id = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/#{list_id}/members", options) format.to_s.downcase == 'xml' ? response['users_list'] : response end @@ -47,7 +46,6 @@ def list_add_member(*args) options = args.last.is_a?(Hash) ? args.pop : {} id, list_id = args.pop, args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = post("#{screen_name}/#{list_id}/members", options.merge(:id => id)) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -71,7 +69,6 @@ def list_add_members(*args) options = args.last.is_a?(Hash) ? args.pop : {} users, list_id = args.pop, args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) merge_users_into_options!(Array(users), options) response = post("#{screen_name}/#{list_id}/create_all", options) format.to_s.downcase == 'xml' ? response['list'] : response @@ -95,7 +92,6 @@ def list_remove_member(*args) options = args.last.is_a?(Hash) ? args.pop : {} id, list_id = args.pop, args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = delete("#{screen_name}/#{list_id}/members", options.merge(:id => id)) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -118,7 +114,6 @@ def is_list_member?(*args) options = args.last.is_a?(Hash) ? args.pop : {} id, list_id = args.pop, args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) begin get("#{screen_name}/#{list_id}/members/#{id}", options) true diff --git a/lib/twitter/client/list_subscribers.rb b/lib/twitter/client/list_subscribers.rb index d2effec56..92cc5a3ef 100644 --- a/lib/twitter/client/list_subscribers.rb +++ b/lib/twitter/client/list_subscribers.rb @@ -23,7 +23,6 @@ def list_subscribers(*args) options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {}) list_id = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = get("#{screen_name}/#{list_id}/subscribers", options) format.to_s.downcase == 'xml' ? response['users_list'] : response end @@ -45,7 +44,6 @@ def list_subscribe(*args) options = args.last.is_a?(Hash) ? args.pop : {} list_id = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = post("#{screen_name}/#{list_id}/subscribers", options) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -67,7 +65,6 @@ def list_unsubscribe(*args) options = args.last.is_a?(Hash) ? args.pop : {} list_id = args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) response = delete("#{screen_name}/#{list_id}/subscribers", options) format.to_s.downcase == 'xml' ? response['list'] : response end @@ -90,7 +87,6 @@ def is_subscriber?(*args) options = args.last.is_a?(Hash) ? args.pop : {} id, list_id = args.pop, args.pop screen_name = args.pop || get_screen_name - clean_screen_name!(screen_name) begin get("#{screen_name}/#{list_id}/subscribers/#{id}", options) true diff --git a/lib/twitter/client/user.rb b/lib/twitter/client/user.rb index 7790364cb..e7858c8fb 100644 --- a/lib/twitter/client/user.rb +++ b/lib/twitter/client/user.rb @@ -110,7 +110,6 @@ def suggestions(*args) def profile_image(*args) options = args.last.is_a?(Hash) ? args.pop : {} screen_name = args.first || get_screen_name - clean_screen_name!(screen_name) get("users/profile_image/#{screen_name}", options, true).headers['location'] end diff --git a/lib/twitter/client/utils.rb b/lib/twitter/client/utils.rb index 72c4bd817..98f2132a7 100644 --- a/lib/twitter/client/utils.rb +++ b/lib/twitter/client/utils.rb @@ -12,14 +12,6 @@ def get_screen_name @screen_name ||= self.verify_credentials.screen_name end - # Remove @ signs from screen names - # - # @param screen_name [String] A Twitter screen name. - # @return [String] The Twitter screen name minus the @ sign. - def clean_screen_name!(screen_name) - screen_name.gsub!(/[@@]/, '') if screen_name - end - # Take a single user ID or screen name and merge it into an options hash with the correct key # # @param user_id_or_screen_name [Integer, String] A Twitter user ID or screen_name. @@ -30,7 +22,6 @@ def merge_user_into_options!(user_id_or_screen_name, options={}) when Fixnum options[:user_id] = user_id_or_screen_name when String - clean_screen_name!(user_id_or_screen_name) options[:screen_name] = user_id_or_screen_name end options @@ -48,7 +39,6 @@ def merge_users_into_options!(user_ids_or_screen_names, options={}) when Fixnum user_ids << user_id_or_screen_name when String - clean_screen_name!(user_id_or_screen_name) screen_names << user_id_or_screen_name end end diff --git a/spec/twitter/client/user_spec.rb b/spec/twitter/client/user_spec.rb index eee5f41f6..61ece9665 100644 --- a/spec/twitter/client/user_spec.rb +++ b/spec/twitter/client/user_spec.rb @@ -35,14 +35,14 @@ before do stub_get("users/show.#{format}"). - with(:query => {:screen_name => "sferik"}). + with(:query => {:screen_name => "@sferik"}). to_return(:body => fixture("sferik.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"}) end it "should get the correct resource" do @client.user("@sferik") a_get("users/show.#{format}"). - with(:query => {:screen_name => "sferik"}). + with(:query => {:screen_name => "@sferik"}). should have_been_made end @@ -127,23 +127,6 @@ end - context "with screen names including '@' passed" do - - before do - stub_get("users/lookup.#{format}"). - with(:query => {:screen_name => "sferik,pengwynn"}). - to_return(:body => fixture("users.#{format}"), :headers => {:content_type => "application/#{format}; charset=utf-8"}) - end - - it "should get the correct resource" do - @client.users("@sferik", "@pengwynn") - a_get("users/lookup.#{format}"). - with(:query => {:screen_name => "sferik,pengwynn"}). - should have_been_made - end - - end - context "with numeric screen names passed" do before do