Skip to content

Commit

Permalink
Remove clean_screen_name! utility method
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Feb 22, 2011
1 parent 50e760b commit 38c9dd0
Show file tree
Hide file tree
Showing 7 changed files with 2 additions and 48 deletions.
1 change: 0 additions & 1 deletion lib/twitter/client/favorites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/twitter/client/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
5 changes: 0 additions & 5 deletions lib/twitter/client/list_members.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/twitter/client/list_subscribers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion lib/twitter/client/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 0 additions & 10 deletions lib/twitter/client/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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
Expand Down
21 changes: 2 additions & 19 deletions spec/twitter/client/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 38c9dd0

Please sign in to comment.