Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Make Status#screen_name return from_user attribute and vice versa

  • Loading branch information...
commit 82afc66a342c51258f80d1ba26959358be1a9c73 1 parent 72b58a3
@sferik authored
Showing with 44 additions and 0 deletions.
  1. +10 −0 lib/twitter/status.rb
  2. +34 −0 spec/twitter/status_spec.rb
View
10 lib/twitter/status.rb
@@ -38,6 +38,11 @@ def expanded_urls
urls.map(&:expanded_url) unless urls.nil?
end
+ # @return [String]
+ def from_user
+ @attrs['from_user'] || @attrs['screen_name']
+ end
+
# @return [Twitter::Point, Twitter::Polygon]
def geo
@geo ||= Twitter::GeoFactory.new(@attrs['geo']) unless @attrs['geo'].nil?
@@ -90,6 +95,11 @@ def retweeted_status
@retweeted_status ||= self.class.new(@attrs['retweeted_status']) unless @attrs['retweeted_status'].nil?
end
+ # @return [String]
+ def screen_name
+ @attrs['screen_name'] || @attrs['from_user']
+ end
+
# @note Must include entities in your request for this method to work
# @return [Array<Twitter::Entity::Url>]
def urls
View
34 spec/twitter/status_spec.rb
@@ -57,6 +57,23 @@
end
end
+ describe "#from_user" do
+ it "should return a screen name when from_user is set" do
+ status = Twitter::Status.new('from_user' => 'sferik')
+ status.from_user.should be_a String
+ status.from_user.should == "sferik"
+ end
+ it "should return a screen name when screen_name is set" do
+ status = Twitter::Status.new('screen_name' => 'sferik')
+ status.from_user.should be_a String
+ status.from_user.should == "sferik"
+ end
+ it "should return nil when not set" do
+ status = Twitter::Status.new
+ status.from_user.should be_nil
+ end
+ end
+
describe "#geo" do
it "should return a Twitter::Point when set" do
status = Twitter::Status.new('geo' => {'type' => 'Point'})
@@ -166,6 +183,23 @@
end
end
+ describe "#screen_name" do
+ it "should return a screen name when screen_name is set" do
+ status = Twitter::Status.new('screen_name' => 'sferik')
+ status.screen_name.should be_a String
+ status.screen_name.should == "sferik"
+ end
+ it "should return a screen name when from_user is set" do
+ status = Twitter::Status.new('from_user' => 'sferik')
+ status.screen_name.should be_a String
+ status.screen_name.should == "sferik"
+ end
+ it "should return nil when not set" do
+ status = Twitter::Status.new
+ status.screen_name.should be_nil
+ end
+ end
+
describe "#urls" do
it "should return an Array of Entity::Url when entities are set" do
urls_hash = [{'url' => 'http://example.com/t.co',
Please sign in to comment.
Something went wrong with that request. Please try again.