Skip to content

Commit 2d2bd6d

Browse files
authored
order params for rest calls
1 parent d68bcef commit 2d2bd6d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/cryptomarket/HttpManager.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def getCredential(httpMethod, method, params)
2020
timestamp = Time.now.to_i.to_s
2121
msg = httpMethod + timestamp + @@apiVersion + method
2222
if not params.nil? and params.keys.any?
23-
if httpMethod == 'GET'
23+
if httpMethod.upcase == 'GET' or httpMethod.upcase == 'PUT'
2424
msg += '?'
2525
end
2626
msg += URI.encode_www_form params
@@ -33,11 +33,14 @@ def getCredential(httpMethod, method, params)
3333

3434
def makeRequest(method:, endpoint:, params:nil, public:false)
3535
uri = URI(@@apiUrl + @@apiVersion + endpoint)
36+
if not params.nil?
37+
params = Hash[params.sort_by {|key, val| key.to_s }]
38+
end
3639
headers = Hash.new
3740
if not public
3841
headers['Authorization'] = getCredential(method.upcase, endpoint, params)
3942
end
40-
if method.upcase == 'GET' and not params.nil?
43+
if (method.upcase == 'GET' or method.upcase =='PUT') and not params.nil?
4144
uri.query = URI.encode_www_form params
4245
params = nil
4346
end
@@ -69,4 +72,4 @@ def handleResponse(response)
6972
return parsed_result
7073
end
7174
end
72-
end
75+
end

0 commit comments

Comments
 (0)