Browse files

Replace get_screen_name with current_user

  • Loading branch information...
1 parent 23b613f commit 00e94d7d97580235c4c122e29bd0387fedbd4c07 @sferik committed Oct 30, 2011
View
7 lib/twitter/client.rb
@@ -92,5 +92,12 @@ def initialize(attrs={})
end
end
+ # Returns the configured screen name or the screen name of the authenticated user
+ #
+ # @return [Twitter::User]
+ def current_user
+ @current_user ||= Twitter::User.new(self.verify_credentials)
+ end
+
end
end
View
35 lib/twitter/client/lists.rb
@@ -73,7 +73,7 @@ def list_timeline(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
get("/1/lists/statuses.json", options).map do |status|
Twitter::Status.new(status)
@@ -113,7 +113,7 @@ def list_remove_member(*args)
options.merge_user!(user_to_remove)
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = post("/1/lists/members/destroy.json", options)
Twitter::List.new(list)
@@ -180,7 +180,7 @@ def list_subscribers(*args)
options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {})
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
cursor = get("/1/lists/subscribers.json", options)
Twitter::Cursor.new(cursor, 'users', Twitter::User)
@@ -243,7 +243,7 @@ def list_subscribe(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = post("/1/lists/subscribers/create.json", options)
Twitter::List.new(list)
@@ -283,7 +283,7 @@ def list_subscriber?(*args)
options.merge_user!(user_to_check)
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
get("/1/lists/subscribers/show.json", options, :raw => true)
true
@@ -318,7 +318,7 @@ def list_unsubscribe(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = post("/1/lists/subscribers/destroy.json", options)
Twitter::List.new(list)
@@ -359,7 +359,7 @@ def list_add_members(*args)
options.merge_users!(Array(users_to_add))
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = post("/1/lists/members/create_all.json", options)
Twitter::List.new(list)
@@ -396,7 +396,7 @@ def list_member?(*args)
options.merge_user!(user_to_check)
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
get("/1/lists/members/show.json", options, :raw => true)
true
@@ -436,7 +436,7 @@ def list_members(*args)
options = {:cursor => -1}.merge(args.last.is_a?(Hash) ? args.pop : {})
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
cursor = get("/1/lists/members.json", options)
Twitter::Cursor.new(cursor, 'users', Twitter::User)
@@ -475,7 +475,7 @@ def list_add_member(*args)
options.merge_user!(user_to_add)
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = post("/1/lists/members/create.json", options)
Twitter::List.new(list)
@@ -510,7 +510,7 @@ def list_destroy(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = delete("/1/lists/destroy.json", options)
Twitter::List.new(list)
@@ -548,7 +548,7 @@ def list_update(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = post("/1/lists/update.json", options)
Twitter::List.new(list)
@@ -632,21 +632,12 @@ def list(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
list = args.pop
options.merge_list!(list)
- owner = args.pop || get_screen_name
+ owner = args.pop || self.current_user.screen_name
options.merge_owner!(owner)
list = get("/1/lists/show.json", options)
Twitter::List.new(list)
end
- private
-
- # Returns the configured screen name or the screen name of the authenticated user
- #
- # @return [String]
- def get_screen_name
- @screen_name ||= self.verify_credentials.screen_name
- end
-
end
end
end
View
17 lib/twitter/client/users.rb
@@ -46,7 +46,7 @@ def users(*args)
# @return [String] The URL for the requested user's profile image.
def profile_image(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
- screen_name = args.pop || get_screen_name
+ screen_name = args.pop || self.current_user.screen_name
get("/1/users/profile_image/#{screen_name}", options, :raw => true).headers['location']
end
@@ -85,7 +85,7 @@ def user_search(query, options={})
# Twitter.user(7505382) # Same as above
def user(*args)
options = args.last.is_a?(Hash) ? args.pop : {}
- user = args.pop || get_screen_name
+ user = args.pop || self.current_user.screen_name
options.merge_user!(user)
user = get("/1/users/show.json", options)
Twitter::User.new(user)
@@ -134,7 +134,7 @@ def user?(user, options={})
def contributees(*args)
options = {}
options.merge!(args.last.is_a?(Hash) ? args.pop : {})
- user = args.pop || get_screen_name
+ user = args.pop || self.current_user.screen_name
options.merge_user!(user)
get("/1/users/contributees.json", options).map do |user|
Twitter::User.new(user)
@@ -167,7 +167,7 @@ def contributees(*args)
def contributors(*args)
options = {}
options.merge!(args.last.is_a?(Hash) ? args.pop : {})
- user = args.pop || get_screen_name
+ user = args.pop || self.current_user.screen_name
options.merge_user!(user)
get("/1/users/contributors.json", options).map do |user|
Twitter::User.new(user)
@@ -193,15 +193,6 @@ def recommendations(options={})
end
end
- private
-
- # Returns the configured screen name or the screen name of the authenticated user
- #
- # @return [String]
- def get_screen_name
- @screen_name ||= self.verify_credentials.screen_name
- end
-
end
end
end
View
45 spec/twitter/client/lists_spec.rb
@@ -28,6 +28,8 @@
end
context "without a screen name passed" do
before do
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/all.json").
to_return(:body => fixture("all.json"), :headers => {:content_type => "application/json; charset=utf-8"})
end
@@ -61,7 +63,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/statuses.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
to_return(:body => fixture("statuses.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -161,7 +164,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/members/destroy.json").
with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -198,6 +202,8 @@
end
context "without a screen name passed" do
before do
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/memberships.json").
with(:query => {:cursor => "-1"}).
to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -273,7 +279,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/subscribers.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -310,6 +317,8 @@
end
context "without a screen name passed" do
before do
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/subscriptions.json").
with(:query => {:cursor => "-1"}).
to_return(:body => fixture("lists.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -383,7 +392,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/subscribers/create.json").
with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -470,7 +480,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/subscribers/show.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -531,7 +542,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/subscribers/destroy.json").
with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -605,7 +617,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/members/create_all.json").
with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286,18755393"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -692,7 +705,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/members/show.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => '813286'}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/.json; charset=utf-8"})
@@ -742,7 +756,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/members.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents', :cursor => "-1"}).
to_return(:body => fixture("users_list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -803,7 +818,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/members/create.json").
with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :user_id => "813286"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -838,7 +854,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_delete("/1/lists/destroy.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -899,7 +916,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_post("/1/lists/update.json").
with(:body => {:owner_screen_name => 'sferik', :slug => 'presidents', :description => "Presidents of the United States of America"}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -1042,7 +1060,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/lists/show.json").
with(:query => {:owner_screen_name => 'sferik', :slug => 'presidents'}).
to_return(:body => fixture("list.json"), :headers => {:content_type => "application/json; charset=utf-8"})
View
14 spec/twitter/client/users_spec.rb
@@ -83,7 +83,8 @@
end
context "without a screen name passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/users/profile_image/sferik").
to_return(fixture("profile_image.text"))
end
@@ -177,7 +178,8 @@
end
context "without a screen name or user ID passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/users/show.json").
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -238,7 +240,8 @@
end
context "without arguments passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/users/contributees.json").
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("contributees.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -261,6 +264,8 @@
describe ".contributors" do
context "with a screen name passed" do
before do
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/users/contributors.json").
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"})
@@ -280,7 +285,8 @@
end
context "without arguments passed" do
before do
- @client.stub!(:get_screen_name).and_return('sferik')
+ stub_get("/1/account/verify_credentials.json").
+ to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
stub_get("/1/users/contributors.json").
with(:query => {:screen_name => "sferik"}).
to_return(:body => fixture("contributors.json"), :headers => {:content_type => "application/json; charset=utf-8"})
View
4 spec/twitter/client_spec.rb
@@ -12,10 +12,10 @@
stub_get("/1/account/verify_credentials.json").
to_return(:body => fixture("sferik.json"), :headers => {:content_type => "application/json; charset=utf-8"})
client1 = Twitter::Client.new(:oauth_token => 'ot1', :oauth_token_secret => 'ots1')
- client1.send(:get_screen_name).should == "sferik"
+ client1.current_user.screen_name.should == 'sferik'
stub_get("/1/account/verify_credentials.json").
to_return(:body => fixture("pengwynn.json"), :headers => {:content_type => "application/json; charset=utf-8"})
client2 = Twitter::Client.new(:oauth_token => 'ot2', :oauth_token_secret => 'ots2')
- client2.send(:get_screen_name).should == "pengwynn"
+ client2.current_user.screen_name.should == 'pengwynn'
end
end

0 comments on commit 00e94d7

Please sign in to comment.