class CloudPayments::Namespaces::Base
Attributes
client[R]
parent_path[R]
Public Class Methods
new(client, parent_path = nil)
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 13 def initialize(client, parent_path = nil) @client = client @parent_path = parent_path end
resource_name()
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 8 def resource_name self.name.split('::').last.downcase end
Public Instance Methods
request(path, params = {})
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 18 def request(path, params = {}) response = client.perform_request(resource_path(path), params) raise_gateway_error(response.body) unless response.body[:success] response.body end
Protected Instance Methods
api_exceptions()
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 26 def api_exceptions [::Faraday::ConnectionFailed, ::Faraday::TimeoutError, Client::ServerError, Client::GatewayError] end
raise_gateway_error(body)
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 34 def raise_gateway_error(body) raise_reasoned_gateway_error(body) || raise_raw_gateway_error(body) end
raise_raw_gateway_error(body)
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 42 def raise_raw_gateway_error(body) fail Client::GatewayError.new(body[:message], body) if !body[:message].nil? && !body[:message].empty? end
raise_reasoned_gateway_error(body)
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 38 def raise_reasoned_gateway_error(body) fail Client::GATEWAY_ERRORS[body[:model][:reason_code]].new(body) if reason_present?(body) end
reason_present?(body)
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 46 def reason_present?(body) !body[:model].nil? && !body[:model].empty? && !body[:model][:reason_code].nil? && CloudPayments.config.raise_banking_errors end
resource_path(path = nil)
click to toggle source
# File lib/cloud_payments/namespaces/base.rb, line 30 def resource_path(path = nil) [parent_path, self.class.resource_name, path].flatten.compact.join(?/).squeeze(?/) end