class Adyen::API::Response
The base class of all responses returned by API
calls to Adyen
.
Attributes
@return [Net::HTTPResponse] The response object returned by Net::HTTP.
Public Class Methods
@param [Net::HTTPResponse] http_response
The response object returned by Net::HTTP.
# File lib/adyen/api/response.rb 16 def initialize(http_response) 17 @http_response = http_response 18 end
Defines shortcut accessor methods, to {Response#params}, for the given parameters.
# File lib/adyen/api/response.rb 6 def self.response_attrs(*attrs) 7 attrs.each do |attr| 8 define_method(attr) { params[attr] } 9 end 10 end
Public Instance Methods
@return [String] The raw body of the response object.
# File lib/adyen/api/response.rb 21 def body 22 @http_response.body 23 end
@return [String,nil] The SOAP failure message, if there is one.
# File lib/adyen/api/response.rb 53 def fault_message 54 @fault_message ||= begin 55 message = xml_querier.text('//soap:Fault/faultstring') 56 message unless message.empty? 57 end 58 end
@return [Boolean] Whether or not the HTTP request was a success.
# File lib/adyen/api/response.rb 31 def http_failure? 32 !@http_response.is_a?(Net::HTTPSuccess) 33 end
@return [Hash] Subclasses return the parsed response body.
# File lib/adyen/api/response.rb 48 def params 49 raise "The Adyen::API::Response#params method should be overridden in a subclass." 50 end
@return [Boolean] Whether or not the SOAP request itself was a success. Adyen
returns a 500 status code for e.g. failed CC validation and in this case, we don't want to throw a server error but rather treat it as something normal.
# File lib/adyen/api/response.rb 38 def server_error? 39 @http_response.is_a?(Net::HTTPServerError) && fault_message.nil? 40 end
@return [Boolean] Whether or not the request was successful.
# File lib/adyen/api/response.rb 26 def success? 27 !http_failure? 28 end
@return [XMLQuerier] The response body wrapped in a XMLQuerier
.
# File lib/adyen/api/response.rb 43 def xml_querier 44 @xml_querier ||= XMLQuerier.xml(@http_response.body) 45 end