lib/payu_api/request.rb in payu_api-0.1.0 vs lib/payu_api/request.rb in payu_api-0.1.1
- old
+ new
@@ -1,32 +1,46 @@
module PayuAPI
class Request
- extend Dry::Initializer::Mixin
-
- param :client
- param :method
- param :url
- param :params, default: proc { nil }
-
API_URL = 'https://secure.payu.com/'.freeze
API_SANDBOX_URL = 'https://secure.snd.payu.com/'.freeze
# rubocop:disable Metrics/AbcSize
- def send
+ def call
connection = Faraday::Connection.new(api_url)
connection.public_send(method.to_s.downcase) do |request|
request.url url
- request.headers['Content-Type'] = 'application/json'
- request.headers['Authorization'] = "Bearer #{client.auth_token}"
- request.body = JSON.generate(params) if params
+ request.body = body if body
+ headers.each do |key, value|
+ request.headers[key] = value
+ end
end
rescue Faraday::Error => e
raise RequestError, e.message
end
private
def api_url
- client.sandbox ? API_SANDBOX_URL : API_URL
+ sandbox? ? API_SANDBOX_URL : API_URL
+ end
+
+ def sandbox?
+ raise NotImplementedError
+ end
+
+ def method
+ raise NotImplementedError
+ end
+
+ def url
+ raise NotImplementedError
+ end
+
+ def headers
+ {}
+ end
+
+ def body
+ nil
end
end
end