Skip to content

Commit bb2c6a1

Browse files
committed
replace deprecated URI.encode
URI.encode has been deprecated in ruby and is displaying warnings in ruby 2.7
1 parent a707a26 commit bb2c6a1

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

lib/woocommerce_api.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def add_query_params endpoint, data
9797

9898
endpoint += "?" unless endpoint.include? "?"
9999
endpoint += "&" unless endpoint.end_with? "?"
100-
endpoint + URI.encode(flatten_hash(data).join("&"))
100+
endpoint + URI.encode_www_form(flatten_hash(data))
101101
end
102102

103103
# Internal: Get URL for requests
@@ -189,12 +189,12 @@ def flatten_hash hash
189189
case value
190190
when Hash
191191
value.map do |inner_key, inner_value|
192-
"#{key}[#{inner_key}]=#{inner_value}"
192+
["#{key}[#{inner_key}]", "#{inner_value}"]
193193
end
194194
when Array
195-
value.map { |inner_value| "#{key}[]=#{inner_value}" }
195+
value.map { |inner_value| ["#{key}[]", "#{inner_value}"] }
196196
else
197-
"#{key}=#{value}"
197+
[["#{key}", "#{value}"]]
198198
end
199199
end
200200
end

lib/woocommerce_api/oauth.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_oauth_url
4242
params["oauth_timestamp"] = Time.new.to_i
4343
params["oauth_signature"] = CGI::escape(generate_oauth_signature(params, url))
4444

45-
query_string = URI::encode(params.map{|key, value| "#{key}=#{value}"}.join("&"))
45+
query_string = URI.encode_www_form(params)
4646

4747
"#{url}?#{query_string}"
4848
end

test/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ def test_oauth_delete
175175

176176
def test_adding_query_params
177177
url = @oauth.send(:add_query_params, 'foo.com', filter: { sku: '123' }, order: 'created_at')
178-
assert_equal url, URI.encode('foo.com?filter[sku]=123&order=created_at')
178+
assert_equal url, 'foo.com?filter%5Bsku%5D=123&order=created_at'
179179
end
180180

181181
def test_invalid_signature_method

0 commit comments

Comments
 (0)