Skip to content
Browse files

Added methods retweeted and not_retweeted, allowing to filter tweets …

…that have RT or not. It adds 'rt' or '-rt' to the query. (@levycarneiro)
  • Loading branch information...
1 parent 60a7cb1 commit 9ef83acdcbe682a8b5a325f89d566f7ef97fffc2 @sferik committed Sep 23, 2010
Showing with 20 additions and 2 deletions.
  1. +10 −0 lib/twitter/search.rb
  2. +10 −2 test/twitter/search_test.rb
View
10 lib/twitter/search.rb
@@ -42,6 +42,16 @@ def containing(word, exclude=false)
end
alias :contains :containing
+ def retweeted
+ @query[:q] << "rt"
+ self
+ end
+
+ def not_retweeted
+ @query[:q] << "-rt"
+ self
+ end
+
# adds filtering based on hash tag ie: #twitter
def hashed(tag, exclude=false)
@query[:q] << "#{exclude ? "-" : ""}\##{tag}"
View
12 test/twitter/search_test.rb
@@ -65,6 +65,14 @@ class SearchTest < Test::Unit::TestCase
@search.contains('milk').query[:q].should include('milk')
end
+ should "should be able to specify retweeted" do
+ @search.retweeted.query[:q].should include('rt')
+ end
+
+ should "should be able to specify not_retweeted" do
+ @search.not_retweeted.query[:q].should include('-rt')
+ end
+
should "should be able to specify hashed" do
@search.hashed('twitter').query[:q].should include('#twitter')
end
@@ -139,8 +147,8 @@ class SearchTest < Test::Unit::TestCase
end
should "should be able to chain methods together" do
- @search.from('jnunemaker').to('oaknd1').referencing('orderedlist').containing('milk').hashed('twitter').lang('en').per_page(20).since(1234).geocode('40.757929', '-73.985506', '25mi')
- @search.query[:q].should == ['from:jnunemaker', 'to:oaknd1', '@orderedlist', 'milk', '#twitter']
+ @search.from('jnunemaker').to('oaknd1').referencing('orderedlist').containing('milk').retweeted.hashed('twitter').lang('en').per_page(20).since(1234).geocode('40.757929', '-73.985506', '25mi')
+ @search.query[:q].should == ['from:jnunemaker', 'to:oaknd1', '@orderedlist', 'milk', 'rt', '#twitter']
@search.query[:lang].should == 'en'
@search.query[:rpp].should == 20
@search.query[:since_id].should == 1234

0 comments on commit 9ef83ac

Please sign in to comment.
Something went wrong with that request. Please try again.