Skip to content
Browse files

Merge branch 'master' of git://github.com/abozanich/twitter into sear…

…ch_exclusions
  • Loading branch information...
2 parents 0180592 + 2b39d50 commit cb05e77adb2d771170d731ad2e55ba17bcb13766 @pengwynn pengwynn committed Mar 20, 2010
Showing with 28 additions and 12 deletions.
  1. +10 −10 lib/twitter/search.rb
  2. +18 −2 test/twitter/search_test.rb
View
20 lib/twitter/search.rb
@@ -15,32 +15,32 @@ def user_agent
@options[:user_agent] || 'Ruby Twitter Gem'
end
- def from(user)
- @query[:q] << "from:#{user}"
+ def from(user,exclude=false)
+ @query[:q] << "#{exclude ? '-' : ''}from:#{user}"
self
end
- def to(user)
- @query[:q] << "to:#{user}"
+ def to(user,exclude=false)
+ @query[:q] << "#{exclude ? '-' : ''}to:#{user}"
self
end
- def referencing(user)
- @query[:q] << "@#{user}"
+ def referencing(user,exclude=false)
+ @query[:q] << "#{exclude ? '-' : ''}@#{user}"
self
end
alias :references :referencing
alias :ref :referencing
- def containing(word)
- @query[:q] << "#{word}"
+ def containing(word,exclude=false)
+ @query[:q] << "#{exclude ? '-' : ''}#{word}"
self
end
alias :contains :containing
# adds filtering based on hash tag ie: #twitter
- def hashed(tag)
- @query[:q] << "##{tag}"
+ def hashed(tag,exclude=false)
+ @query[:q] << "#{exclude ? '-' : ''}\##{tag}"
self
end
View
20 test/twitter/search_test.rb
@@ -29,12 +29,20 @@ class SearchTest < Test::Unit::TestCase
@search.from('jnunemaker').query[:q].should include('from:jnunemaker')
end
+ should "should be able to specify not from" do
+ @search.from('jnunemaker',true).query[:q].should include('-from:jnunemaker')
+ end
+
should "should be able to specify to" do
@search.to('jnunemaker').query[:q].should include('to:jnunemaker')
end
- should "should be able to specify referencing" do
- @search.referencing('jnunemaker').query[:q].should include('@jnunemaker')
+ should "should be able to specify not to" do
+ @search.to('jnunemaker',true).query[:q].should include('-to:jnunemaker')
+ end
+
+ should "should be able to specify not referencing" do
+ @search.referencing('jnunemaker',true).query[:q].should include('-@jnunemaker')
end
should "should alias references to referencing" do
@@ -49,6 +57,10 @@ class SearchTest < Test::Unit::TestCase
@search.containing('milk').query[:q].should include('milk')
end
+ should "should be able to specify not containing" do
+ @search.containing('milk',true).query[:q].should include('-milk')
+ end
+
should "should alias contains to containing" do
@search.contains('milk').query[:q].should include('milk')
end
@@ -57,6 +69,10 @@ class SearchTest < Test::Unit::TestCase
@search.hashed('twitter').query[:q].should include('#twitter')
end
+ should "should be able to specify not hashed" do
+ @search.hashed('twitter',true).query[:q].should include('-#twitter')
+ end
+
should "should be able to specify the language" do
@search.lang('en')
@search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:lang => 'en', :q => ''}, :format => :json, :headers => {'User-Agent' => 'Ruby Twitter Gem'}).returns({'foo' => 'bar'})

0 comments on commit cb05e77

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