Skip to content

Commit

Permalink
Added methods retweeted and not_retweeted, allowing to filter tweets …
Browse files Browse the repository at this point in the history
…that have RT or not. It adds 'rt' or '-rt' to the query. (@levycarneiro)
  • Loading branch information
sferik committed Sep 23, 2010
1 parent 60a7cb1 commit 9ef83ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/twitter/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
12 changes: 10 additions & 2 deletions test/twitter/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 9ef83ac

Please sign in to comment.