Skip to content

Commit

Permalink
add excluded terms
Browse files Browse the repository at this point in the history
  • Loading branch information
boz committed Mar 11, 2010
1 parent b222f2b commit 2b39d50
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/twitter/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 18 additions & 2 deletions test/twitter/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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'})
Expand Down

0 comments on commit 2b39d50

Please sign in to comment.