From 314ed45aee928bf8be64c8b6e64795a96250c433 Mon Sep 17 00:00:00 2001 From: Kenton White Date: Wed, 13 Mar 2013 16:40:42 -0400 Subject: [PATCH] Added Twitter::SearchResults#next_results Returns a hash of query parameters for accessing the next page of search results Can be merged into the previous search options for easy access --- lib/twitter/search_results.rb | 10 ++++++++++ spec/twitter/search_results_spec.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/twitter/search_results.rb b/lib/twitter/search_results.rb index 02319be82..e5e46153d 100644 --- a/lib/twitter/search_results.rb +++ b/lib/twitter/search_results.rb @@ -53,5 +53,15 @@ def next_results? end alias next_page? next_results? + # Returns a Hash of query parameters for the next result in the search + # + # Returned Hash can be merged into the previous search options list + # to easily access the next page + # + # @return [Hash] + def next_results + Faraday::Utils.parse_nested_query(@attrs[:search_metadata][:next_results][1..-1]).inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo} if next_results? + end + alias next_page next_results end end diff --git a/spec/twitter/search_results_spec.rb b/spec/twitter/search_results_spec.rb index 8c35f6f2a..8d2945771 100644 --- a/spec/twitter/search_results_spec.rb +++ b/spec/twitter/search_results_spec.rb @@ -111,5 +111,20 @@ expect(next_results).to be_false end end + + describe "#next_results" do + let(:next_results) {Twitter::SearchResults.new(:search_metadata => + {:next_results => "?max_id=249279667666817023&q=%23freebandnames&count=4&include_entities=1&result_type=mixed" + }).next_results + } + + it "returns a hash of query parameters" do + expect(next_results).to be_a Hash + end + + it "returns a max_id" do + expect(next_results[:max_id]).to eq "249279667666817023" + end + end end