Permalink
Browse files

Merge pull request #203 from seanmoon/master

Add accessor for expanded_urls from tweet entities
  • Loading branch information...
2 parents 1de9147 + 587668f commit a8c96d9744e70410fefa10107a37d9ad42093468 @sferik committed Oct 18, 2011
Showing with 19 additions and 0 deletions.
  1. +6 −0 lib/twitter/status.rb
  2. +13 −0 spec/twitter/status_spec.rb
View
@@ -22,6 +22,12 @@ def ==(other)
super || (other.class == self.class && other.id == self.id)
end
+ def expanded_urls
+ @expanded_urls ||= Array(@attributes['entities']['urls']).map do |url|
+ url['expanded_url']
+ end unless @attributes['entities'].nil?
+ end
+
def geo
@geo ||= Twitter::GeoFactory.new(@attributes['geo']) unless @attributes['geo'].nil?
end
@@ -89,6 +89,19 @@
end
end
+ describe "#expanded_urls" do
+ it "should return the expanded urls" do
+ urls = [{'expanded_url' => 'http://example.com'}]
+ expanded_urls = Twitter::Status.new('entities' => {'urls' => urls}).expanded_urls
+ expanded_urls.should be_an Array
+ expanded_urls.first.should == "http://example.com"
+ end
+ it "should return nil when not set" do
+ expanded_urls = Twitter::Status.new.expanded_urls
+ expanded_urls.should be_nil
+ end
+ end
+
describe "#user" do
it "should return a User when user is set" do
user = Twitter::Status.new('user' => {}).user

0 comments on commit a8c96d9

Please sign in to comment.