Skip to content

Commit

Permalink
Fixed that search was ignoring many options when making request. Stup…
Browse files Browse the repository at this point in the history
…id mistake. Changed the tests to test stuff farther down the chain so this doesn't happen again.
  • Loading branch information
jnunemaker committed Apr 9, 2009
1 parent 2da4913 commit 096d56e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
7 changes: 6 additions & 1 deletion examples/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@
search.each { |result| pp result }

puts '*'*50, 'Second Run', '*'*50
search.each { |result| pp result }
search.each { |result| pp result }

puts '*'*50, 'Parameter Check', '*'*50
pp Twitter::Search.new('#austineats').fetch().results.first
pp Twitter::Search.new('#austineats').page(2).fetch().results.first
pp Twitter::Search.new('#austineats').since(1412737343).fetch().results.first
4 changes: 3 additions & 1 deletion lib/twitter/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ def clear

def fetch(force=false)
if @fetch.nil? || force
response = self.class.get('http://search.twitter.com/search.json', :query => {:q => @query[:q].dup.join(' ')}, :format => :json)
query = @query.dup
query[:q] = query[:q].join(' ')
response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json)
@fetch = Mash.new(response)
end

Expand Down
20 changes: 15 additions & 5 deletions test/twitter/search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,33 @@ class SearchTest < Test::Unit::TestCase
end

should "should be able to specify the language" do
@search.lang('en').query[:lang].should == 'en'
@search.lang('en')
@search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:lang => 'en', :q => ''}, :format => :json).returns({'foo' => 'bar'})
@search.fetch()
end

should "should be able to specify the number of results per page" do
@search.per_page(25).query[:rpp].should == 25
@search.per_page(25)
@search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:rpp => 25, :q => ''}, :format => :json).returns({'foo' => 'bar'})
@search.fetch()
end

should "should be able to specify the page number" do
@search.page(20).query[:page].should == 20
@search.page(20)
@search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:page => 20, :q => ''}, :format => :json).returns({'foo' => 'bar'})
@search.fetch()
end

should "should be able to specify only returning results greater than an id" do
@search.since(1234).query[:since_id].should == 1234
@search.since(1234)
@search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:since_id => 1234, :q => ''}, :format => :json).returns({'foo' => 'bar'})
@search.fetch()
end

should "should be able to specify geo coordinates" do
@search.geocode('40.757929', '-73.985506', '25mi').query[:geocode].should == '40.757929,-73.985506,25mi'
@search.geocode('40.757929', '-73.985506', '25mi')
@search.class.expects(:get).with('http://search.twitter.com/search.json', :query => {:geocode => '40.757929,-73.985506,25mi', :q => ''}, :format => :json).returns({'foo' => 'bar'})
@search.fetch()
end

should "should be able to clear the filters set" do
Expand Down

2 comments on commit 096d56e

@larrywright
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tested the pagination of search results much? Unless I’m missing something, the twitter search functionality you have ignores the data that comes back from Twitter about the next_page and since_id you need to request next.

@jnunemaker
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t assume how you are going to use the pagination information. I return it and you can use that for another search but I haven’t taken the time to actually implement next page and such. Doesn’t seem like it would be super hard.

Please sign in to comment.