Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add Twitter::Status#all_urls method

  • Loading branch information...
commit b5feeb722c661eec7c75c6cd50d026c5002a3762 1 parent edf2ed4
@seanmoon seanmoon authored
Showing with 24 additions and 1 deletion.
  1. +7 −0 lib/twitter/status.rb
  2. +17 −1 spec/twitter/status_spec.rb
View
7 lib/twitter/status.rb
@@ -22,6 +22,13 @@ def ==(other)
super || (other.class == self.class && other.id == self.id)
end
+ def all_urls
+ @all_urls ||= begin
+ all_urls = [ urls, expanded_urls ].compact.flatten.uniq
+ all_urls.length > 0 ? all_urls : nil
+ end
+ end
+
def expanded_urls
@expanded_urls ||= Array(@attrs['entities']['urls']).map do |url|
url['expanded_url']
View
18 spec/twitter/status_spec.rb
@@ -77,7 +77,7 @@
end
end
- describe "#url" do
+ describe "#urls" do
it "should return urls" do
urls = Twitter::Status.new('text' => "This Tweet contains a http://example.com.").urls
urls.should be_an Array
@@ -102,6 +102,22 @@
end
end
+ describe "#all_urls" do
+ it "should return urls in the text, and in all fields from the entities" do
+ urls = [{'url' => 'http://t.co/example', 'expanded_url' => 'http://example.com'}]
+ status_attributes = { 'text' => "This tweet contains a http://t.co/example.", 'entities' => {'urls' => urls} }
+ all_urls = Twitter::Status.new(status_attributes).all_urls
+ all_urls.should be_an Array
+ all_urls.first.should == "http://t.co/example"
+ all_urls.last.should == "http://example.com"
+ end
+
+ it "should return nil when not set" do
+ all_urls = Twitter::Status.new.all_urls
+ all_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
Please sign in to comment.
Something went wrong with that request. Please try again.