Skip to content

Commit

Permalink
Use different method to encode uri components
Browse files Browse the repository at this point in the history
  • Loading branch information
scarhand committed May 10, 2022
1 parent f89ee69 commit 050c47b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/laposta/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,19 +107,18 @@ def delete(path, body)

private
def format_query(params)
p = URI::Parser.new
res = []
if params.is_a?(Hash)
res << params.map do |k, v|
case v
when Hash
v.map { |nk, nv| "#{k}[#{nk}]=#{p.escape(nv.to_s)}" }.join("&")
v.map { |nk, nv| "#{k}[#{nk}]=#{URI.encode_www_form_component(nv.to_s)}" }.join("&")
when Symbol, String
"#{k}=#{p.escape(v)}"
"#{k}=#{URI.encode_www_form_component(v)}"
when Array then
v.map { |c| "#{k}[]=#{p.escape(c.to_s)}" }.join("&")
v.map { |c| "#{k}[]=#{URI.encode_www_form_component(c.to_s)}" }.join("&")
else
"#{k}=#{p.escape(v.to_s)}"
"#{k}=#{URI.encode_www_form_component(v.to_s)}"
end
end
end
Expand Down

0 comments on commit 050c47b

Please sign in to comment.