lib/convert_api/client.rb in convert_api-2.0.0 vs lib/convert_api/client.rb in convert_api-3.0.0
- old
+ new
@@ -28,19 +28,19 @@
'Accept' => 'application/json'
}
def get(path, params = {}, options = {})
handle_response do
- request = Net::HTTP::Get.new(request_uri(path, params), DEFAULT_HEADERS)
+ request = Net::HTTP::Get.new(request_uri(path, params), headers_with_auth)
http(options).request(request)
end
end
def post(path, params, options = {})
handle_response do
- request = Net::HTTP::Post.new(request_uri(path), DEFAULT_HEADERS)
+ request = Net::HTTP::Post.new(request_uri(path), headers_with_auth)
request.form_data = build_form_data(params)
http(options).request(request)
end
end
@@ -99,16 +99,11 @@
# http.set_debug_output $stderr
http
end
def request_uri(path, params = {})
- raise(AuthenticationError, 'API secret or Token not configured') if authentication.nil?
-
- params_with_authentication = params.merge(authentication)
- query = URI.encode_www_form(params_with_authentication)
-
- base_uri.path + path + '?' + query
+ base_uri.path + path + '?' + URI.encode_www_form(params)
end
def build_form_data(params)
data = {}
@@ -121,14 +116,19 @@
end
data
end
- def authentication
- return { Secret: config.api_secret } unless config.api_secret.nil?
- return { Token: config.token } unless config.token.nil?
+ def headers_with_auth
+ DEFAULT_HEADERS.merge(auth_headers)
+ end
- nil
+ def auth_headers
+ { 'Authorization' => "Bearer #{api_credentials}" }
+ end
+
+ def api_credentials
+ config.api_credentials || raise(AuthenticationError, 'API credentials not configured')
end
def base_uri
config.base_uri
end