Skip to content
Browse files

support search pagination via the next_page value

  • Loading branch information...
1 parent d84366e commit 767ddaa62e8fa9e3872ddd17323f323d9f1393e4 @cyu cyu committed Feb 12, 2010
Showing with 19 additions and 2 deletions.
  1. +19 −2 lib/twitter/search.rb
View
21 lib/twitter/search.rb
@@ -116,8 +116,7 @@ def fetch(force=false)
if @fetch.nil? || force
query = @query.dup
query[:q] = query[:q].join(' ')
- response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json, :headers => {'User-Agent' => user_agent})
- @fetch = Hashie::Mash.new(response)
+ perform_get(query)
end
@fetch
@@ -126,5 +125,23 @@ def fetch(force=false)
def each
fetch()['results'].each { |r| yield r }
end
+
+ def next_page?
+ !!fetch()['next_page']
+ end
+
+ def fetch_next_page
+ if next_page?
+ s = Search.new(nil, :user_agent => user_agent)
+ s.perform_get(fetch()['next_page'][1..-1])
+ s
+ end
+ end
+
+ protected
+ def perform_get(query)
+ response = self.class.get('http://search.twitter.com/search.json', :query => query, :format => :json, :headers => {'User-Agent' => user_agent})
+ @fetch = Hashie::Mash.new(response)
+ end
end
end

0 comments on commit 767ddaa

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