Skip to content

Commit

Permalink
Make Status#screen_name return from_user attribute and vice versa
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed May 6, 2012
1 parent 72b58a3 commit 82afc66
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/twitter/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions spec/twitter/status_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'})
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 82afc66

Please sign in to comment.