Skip to content

Commit fafb689

Browse files
Merge pull request #111 from avasachinbaijal/ErbUtilIssue
Addressing issue with Util.Encode
2 parents 72bb879 + aba5a4c commit fafb689

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/avatax/request.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
require 'faraday'
22
require 'json'
3+
require "erb"
4+
35

46
module AvaTax
57
module Request
@@ -24,9 +26,9 @@ def request(method, path, model, options={})
2426
response = connection.send(method) do |request|
2527
case method
2628
when :get, :delete
27-
request.url("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
29+
request.url("#{encode_path(path)}?#{URI.encode_www_form(options)}")
2830
when :post, :put
29-
request.url("#{URI.encode(path)}?#{URI.encode_www_form(options)}")
31+
request.url("#{encode_path(path)}?#{URI.encode_www_form(options)}")
3032
request.headers['Content-Type'] = 'application/json'
3133
request.body = model.to_json unless model.empty?
3234
end
@@ -38,5 +40,11 @@ def request(method, path, model, options={})
3840
response.body
3941
end
4042
end
43+
44+
private
45+
46+
def encode_path(path)
47+
path.split('/').map { |part| ERB::Util.url_encode(part) }.join('/')
48+
end
4149
end
42-
end
50+
end

0 commit comments

Comments
 (0)