Method: Adyen::REST::Response#http_response
- Defined in:
-
lib/adyen/rest/response.rb,
lib/adyen/rest/response.rb
The underlying net/http response.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/adyen/rest/response.rb', line 21 class Response attr_reader :http_response, :prefix, :attributes def initialize(http_response, = {}) @http_response = http_response @prefix = .key?(:prefix) ? [:prefix].to_s : nil @attributes = parse_response_attributes end # Looks up an attribute in the response. # @return [String, nil] The value of the attribute if it was included in the response. def [](name) attributes[canonical_name(name)] end def has_attribute?(name) attributes.has_key?(canonical_name(name)) end def psp_reference Integer(self[:psp_reference]) end protected def map_response_list(response_prefix, mapped_attributes) list = [] index = 0 loop do response = {} mapped_attributes.each do |key, value| new_value = attributes["#{response_prefix}.#{index.to_s}.#{value}"] response[key] = new_value unless new_value.empty? end index += 1 break unless response.any? list << response end list end def canonical_name(name) Adyen::Util.camelize(apply_prefix(name)) end def apply_prefix(name) prefix ? name.to_s.sub(/\A(?!#{Regexp.quote(prefix)}\.)/, "#{prefix}.") : name.to_s end def parse_response_attributes attributes = CGI.parse(http_response.body) attributes.each { |key, values| attributes[key] = values.first } attributes end end |