Class: Adyen::API::Response
- Inherits:
-
Object
- Object
- Adyen::API::Response
- Defined in:
- lib/adyen/api/response.rb
Overview
The base class of all responses returned by API calls to Adyen.
Instance Attribute Summary (collapse)
-
- (Net::HTTPResponse) http_response
readonly
The response object returned by Net::HTTP.
Class Method Summary (collapse)
-
+ (Object) response_attrs(*attrs)
Defines shortcut accessor methods, to #params, for the given parameters.
Instance Method Summary (collapse)
-
- (String) body
The raw body of the response object.
-
- (String?) fault_message
The SOAP failure message, if there is one.
-
- (Boolean) http_failure?
Whether or not the HTTP request was a success.
-
- (Response) initialize(http_response)
constructor
A new instance of Response.
-
- (Hash) params
Subclasses return the parsed response body.
-
- (Boolean) server_error?
Adyen returns a 500 status code for e.g.
-
- (Boolean) success?
Whether or not the request was successful.
-
- (XMLQuerier) xml_querier
The response body wrapped in a XMLQuerier.
Constructor Details
- (Response) initialize(http_response)
A new instance of Response
16 17 18 |
# File 'lib/adyen/api/response.rb', line 16 def initialize(http_response) @http_response = http_response end |
Instance Attribute Details
- (Net::HTTPResponse) http_response (readonly)
The response object returned by Net::HTTP.
13 14 15 |
# File 'lib/adyen/api/response.rb', line 13 def http_response @http_response end |
Class Method Details
+ (Object) response_attrs(*attrs)
Defines shortcut accessor methods, to #params, for the given parameters.
6 7 8 9 10 |
# File 'lib/adyen/api/response.rb', line 6 def self.response_attrs(*attrs) attrs.each do |attr| define_method(attr) { params[attr] } end end |
Instance Method Details
- (String) body
The raw body of the response object.
21 22 23 |
# File 'lib/adyen/api/response.rb', line 21 def body @http_response.body end |
- (String?) fault_message
The SOAP failure message, if there is one.
53 54 55 56 57 58 |
# File 'lib/adyen/api/response.rb', line 53 def @fault_message ||= begin = xml_querier.text('//soap:Fault/faultstring') unless .empty? end end |
- (Boolean) http_failure?
Whether or not the HTTP request was a success.
31 32 33 |
# File 'lib/adyen/api/response.rb', line 31 def http_failure? !@http_response.is_a?(Net::HTTPSuccess) end |
- (Hash) params
Subclasses return the parsed response body.
48 49 50 |
# File 'lib/adyen/api/response.rb', line 48 def params raise "The Adyen::API::Response#params method should be overridden in a subclass." end |
- (Boolean) server_error?
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.
38 39 40 |
# File 'lib/adyen/api/response.rb', line 38 def server_error? @http_response.is_a?(Net::HTTPServerError) && .nil? end |
- (Boolean) success?
Whether or not the request was successful.
26 27 28 |
# File 'lib/adyen/api/response.rb', line 26 def success? !http_failure? end |
- (XMLQuerier) xml_querier
The response body wrapped in a XMLQuerier.
43 44 45 |
# File 'lib/adyen/api/response.rb', line 43 def xml_querier @xml_querier ||= XMLQuerier.new(@http_response.body) end |