Skip to content

Commit

Permalink
To support Ruby 3.2+, stop using the deprecated URI.encode
Browse files Browse the repository at this point in the history
  • Loading branch information
tinco committed Nov 7, 2024
1 parent 824b352 commit 0a641ae
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/frontapp/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ def format_query(params)
res << q.map do |k, v|
case v
when Symbol, String
"q[#{k}]=#{URI.encode(v)}"
"q[#{k}]=#{URI.encode_uri_component(v)}"
when Array then
v.map { |c| "q[#{k}][]=#{URI.encode(c.to_s)}" }.join("&")
v.map { |c| "q[#{k}][]=#{URI.encode_uri_component(c.to_s)}" }.join("&")
else
"q[#{k}]=#{URI.encode(v.to_s)}"
"q[#{k}]=#{URI.encode_uri_component(v.to_s)}"
end
end
end
res << params.map {|k,v| "#{k}=#{URI.encode(v.to_s)}"}
res << params.map {|k,v| "#{k}=#{URI.encode_uri_component(v.to_s)}"}
res.join("&")
end

Expand Down
7 changes: 7 additions & 0 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,11 @@
expect(results).to eq([result_1, result_2])
end

it "can list with params" do
stub_request(:get, "#{base_url}/conversations?page=2").
with(headers: headers).
to_return(status: 200, body: JSON.generate(response_2))
results = frontapp.conversations(page: 2)
expect(results).to eq([result_2])
end
end

0 comments on commit 0a641ae

Please sign in to comment.