Permalink
Browse files

Make Status#screen_name return from_user attribute and vice versa

  • Loading branch information...
sferik committed May 6, 2012
1 parent 72b58a3 commit 82afc66a342c51258f80d1ba26959358be1a9c73
Showing with 44 additions and 0 deletions.
  1. +10 −0 lib/twitter/status.rb
  2. +34 −0 spec/twitter/status_spec.rb
View
@@ -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
@@ -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',

0 comments on commit 82afc66

Please sign in to comment.