Skip to content

Commit

Permalink
URL encode everything
Browse files Browse the repository at this point in the history
  • Loading branch information
jmortlock committed Nov 14, 2017
1 parent ce7af01 commit 391eaa2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/quick_travel/adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'quick_travel/config'
require 'quick_travel/adapter_error'
require 'quick_travel/init_from_hash'
require 'uri'

module QuickTravel
class Adapter
Expand Down Expand Up @@ -284,7 +285,7 @@ def self.call_and_validate(http_method, path, query = {}, opts = {})
http_params[:follow_redirects] = false

begin
response = self.send(http_method, path, http_params)
response = self.send(http_method, URI.escape(path), http_params)
rescue Errno::ECONNREFUSED
raise ConnectionError.new('Connection refused')
rescue SocketError
Expand Down
4 changes: 1 addition & 3 deletions lib/quick_travel/booking.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require 'quick_travel/payment'
require 'quick_travel/payment_type'
require 'quick_travel/price_changes'
require 'uri'

module QuickTravel
class Booking < Adapter
Expand All @@ -13,8 +12,7 @@ def self.api_base
end

def self.find_by_reference(reference)
uri = URI.escape("#{api_base}/reference/#{reference}.json")
find_all!(uri).first
find_all!("#{api_base}/reference/#{reference}.json").first
end

def documents(regenerate = false)
Expand Down
9 changes: 9 additions & 0 deletions spec/adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@
allow(QuickTravel::Api).to receive(:post).and_return(response)
end

context 'when the query needs to be url encoded' do
let(:url) { 'http://test.quicktravel.com.au/ blah' }
before do
QuickTravel::Adapter.post_and_validate(url, {})
end
let(:expected_url) { 'http://test.quicktravel.com.au/%20blah' }
specify { expect(QuickTravel::Api).to have_received(:post).with(expected_url, instance_of(Hash)) }
end

context 'when the query contains empty arrays' do
let(:url) { 'http://test.quicktravel.com.au' }
let(:query) {
Expand Down

0 comments on commit 391eaa2

Please sign in to comment.