class CloudPayments::Client
Constants
- ERRORS
- GATEWAY_ERRORS
- HTTP_STATUSES
- REASON_CODES
Attributes
config[R]
connection[R]
Public Class Methods
new(config = nil)
click to toggle source
# File lib/cloud_payments/client.rb, line 13 def initialize(config = nil) @config = config || CloudPayments.config @connection = build_connection end
Public Instance Methods
perform_request(path, params = nil)
click to toggle source
# File lib/cloud_payments/client.rb, line 18 def perform_request(path, params = nil) connection.basic_auth(config.public_key, config.secret_key) response = connection.post(path, (params ? convert_to_json(params) : nil), headers) Response.new(response.status, response.body, response.headers).tap do |response| raise_transport_error(response) if response.status.to_i >= 300 end end
Private Instance Methods
build_connection()
click to toggle source
# File lib/cloud_payments/client.rb, line 47 def build_connection Faraday::Connection.new(config.host, config.connection_options, &config.connection_block) end
convert_to_json(data)
click to toggle source
# File lib/cloud_payments/client.rb, line 29 def convert_to_json(data) config.serializer.dump(data) end
headers()
click to toggle source
# File lib/cloud_payments/client.rb, line 33 def headers { 'Content-Type' => 'application/json' } end
logger()
click to toggle source
# File lib/cloud_payments/client.rb, line 37 def logger config.logger end
raise_transport_error(response)
click to toggle source
# File lib/cloud_payments/client.rb, line 41 def raise_transport_error(response) logger.fatal "[#{response.status}] #{response.origin_body}" if logger error = ERRORS[response.status] || ServerError raise error.new "[#{response.status}] #{response.origin_body}" end