Skip to content

Commit

Permalink
Merge pull request #365 from KentonWhite/next_results
Browse files Browse the repository at this point in the history
Add Twitter::SearchResults methods for handling next results
  • Loading branch information
sferik committed Apr 22, 2013
2 parents 6df3d85 + 314ed45 commit c890e7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/twitter/search_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 15 additions & 0 deletions spec/twitter/search_results_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c890e7d

Please sign in to comment.