Skip to content

Commit

Permalink
Added Twitter::SearchResults#refresh_url
Browse files Browse the repository at this point in the history
  • Loading branch information
mustafaturan committed Jun 8, 2013
1 parent 54bdde1 commit 6bf08c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/twitter/search_results.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,16 @@ 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

# Returns a Hash of query parameters for the refresh url in the search
#
# Returned Hash can be merged into the previous search options list
# to easily access the refresh page
#
# @return [Hash]
def refresh_url
Faraday::Utils.parse_nested_query(@attrs[:search_metadata][:refresh_url][1..-1]).inject({}) { |memo, (k,v)| memo[k.to_sym] = v; memo}
end
alias refresh_page refresh_url
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 @@ -127,4 +127,19 @@
end
end

describe "#refresh_url" do
let(:refresh_url) {Twitter::SearchResults.new(:search_metadata =>
{:refresh_url => "?since_id=249279667666817023&q=%23freebandnames&count=4&include_entities=1&result_type=recent"
}).refresh_url
}

it "returns a hash of query parameters" do
expect(refresh_url).to be_a Hash
end

it "returns a since_id" do
expect(refresh_url[:since_id]).to eq "249279667666817023"
end
end

end

0 comments on commit 6bf08c0

Please sign in to comment.