Skip to content

Commit 9e21b3b

Browse files
Merge pull request #11 from xiaoboa/array-query-params
fix: Allow for multiple values for a parameter
2 parents d0519ca + 20bd5d5 commit 9e21b3b

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/ruby_http_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def add_version(url = nil)
9090
# - The url string with the query parameters appended
9191
#
9292
def build_query_params(url, query_params)
93-
params = query_params.map { |key, value| "#{key}=#{value}" }.join('&')
93+
params = URI.encode_www_form(query_params)
9494
url.concat("?#{params}")
9595
end
9696

test/test_ruby_http_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ def test_add_version
6161

6262
def test_build_query_params
6363
url = ''
64-
query_params = { 'limit' => 100, 'offset' => 0 }
64+
query_params = { 'limit' => 100, 'offset' => 0, 'categories' => ['category1', 'category2'] }
6565
url = @client.build_query_params(url, query_params)
66-
assert_equal('?limit=100&offset=0', url)
66+
assert_equal('?limit=100&offset=0&categories=category1&categories=category2', url)
6767
end
6868

6969
def test_build_url

0 commit comments

Comments
 (0)