class Adyen::REST::Response

The Response class models the HTTP response that is the result of a API call to Adyen's REST webservice.

Some API calls may respond with an instance of a subclass, to make dealing with the response easier.

@!attribute http_response [r]

The underlying net/http response.
@return [Net::HTTPResponse]

@!attribute prefix [r]

The prefix to use when reading attributes from the response
@return [String]

@see Adyen::REST::Client @see Adyen::REST::Request

Attributes

attributes[R]
http_response[R]
prefix[R]

Public Class Methods

new(http_response, options = {}) click to toggle source
   # File lib/adyen/rest/response.rb
24 def initialize(http_response, options = {})
25   @http_response = http_response
26   @prefix = options.key?(:prefix) ? options[:prefix].to_s : nil
27   @attributes = parse_response_attributes
28 end

Public Instance Methods

[](name) click to toggle source

Looks up an attribute in the response. @return [String, nil] The value of the attribute if it was included in the response.

   # File lib/adyen/rest/response.rb
32 def [](name)
33   attributes[canonical_name(name)]
34 end
has_attribute?(name) click to toggle source
   # File lib/adyen/rest/response.rb
36 def has_attribute?(name)
37   attributes.has_key?(canonical_name(name))
38 end
psp_reference() click to toggle source
   # File lib/adyen/rest/response.rb
40 def psp_reference
41   Integer(self[:psp_reference])
42 end

Protected Instance Methods

apply_prefix(name) click to toggle source
   # File lib/adyen/rest/response.rb
69 def apply_prefix(name)
70   prefix ? name.to_s.sub(/\A(?!#{Regexp.quote(prefix)}\.)/, "#{prefix}.") : name.to_s
71 end
canonical_name(name) click to toggle source
   # File lib/adyen/rest/response.rb
65 def canonical_name(name)
66   Adyen::Util.camelize(apply_prefix(name))
67 end
map_response_list(response_prefix, mapped_attributes) click to toggle source
   # File lib/adyen/rest/response.rb
46 def map_response_list(response_prefix, mapped_attributes)
47   list  = []
48   index = 0
49 
50   loop do
51     response = {}
52     mapped_attributes.each do |key, value|
53       new_value = attributes["#{response_prefix}.#{index.to_s}.#{value}"]
54       response[key] = new_value unless new_value.empty?
55     end
56 
57     index += 1
58     break unless response.any?
59     list << response
60   end
61 
62   list
63 end
parse_response_attributes() click to toggle source
   # File lib/adyen/rest/response.rb
73 def parse_response_attributes
74   attributes = CGI.parse(http_response.body)
75   attributes.each { |key, values| attributes[key] = values.first }
76   attributes
77 end