lib/pesapal/oauth.rb in pesapal-1.8.0 vs lib/pesapal/oauth.rb in pesapal-2.0.0

- old
+ new

@@ -46,11 +46,11 @@ # @return [String] generated random nonce. def self.generate_nonce(length) chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ0123456789' nonce = '' length.times { nonce << chars[rand(chars.size)] } - "#{nonce}" + nonce end # Generate the oAuth signature using HMAC-SHA1 algorithm. # # The signature is calculated by passing the signature base string and @@ -114,16 +114,14 @@ # # @return [String] valid signature base string. def self.generate_signature_base_string(http_method, absolute_url, params) # step 1: convert the http method to uppercase http_method = http_method.upcase - # step 2: percent encode the url url_encoded = parameter_encode(normalized_request_uri(absolute_url)) - # step 3: percent encode the parameter string - parameter_string_encoded = parameter_encode(generate_signable_encoded_params_query_string params) + parameter_string_encoded = parameter_encode(generate_signable_encoded_params_query_string(params)) "#{http_method}&#{url_encoded}&#{parameter_string_encoded}" end # Generate signing key @@ -174,18 +172,22 @@ # # @param absolute_url [String] URL to be normalized. # # @return [String] valid constructed URL as per the spec. def self.normalized_request_uri(absolute_url) - u = URI.parse(absolute_url) + uri = URI.parse(absolute_url) - scheme = u.scheme.downcase - host = u.host.downcase - path = u.path - port = u.port + scheme = uri.scheme.downcase + host = uri.host.downcase + path = uri.path + port = uri.port - port = (scheme == 'http' && port != 80) || (scheme == 'https' && port != 443) ? ":#{port}" : '' - path = (path && path != '') ? path : '/' + non_standard_http = scheme == 'http' && port != 80 + non_standard_https = scheme == 'https' && port != 443 + uri_with_path = path && (path != '') + + port = non_standard_http || non_standard_https ? ":#{port}" : '' + path = uri_with_path ? path : '/' "#{scheme}://#{host}#{port}#{path}" end # Encodes parameter name or values.