Class: AmazonFlexPay::API::BaseRequest::BaseResponse

Inherits:
Model
  • Object
show all
Defined in:
lib/amazon_flex_pay/api/base_request.rb

Class Method Summary collapse

Methods inherited from Model

attribute, attribute_names, collection_attribute, complex_attribute, enumerated_attribute, #initialize, #to_hash

Constructor Details

This class inherits a constructor from AmazonFlexPay::Model

Class Method Details

.from_xml(xml) ⇒ Object

Parses Amazon’s XML response to REST requests and instantiates the response.



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/amazon_flex_pay/api/base_request.rb', line 39

def self.from_xml(xml)
  response = MultiXml.parse(xml)

  response_key = response.keys.find{|k| k.match(/Response$/)}
  hash = response[response_key]['ResponseMetadata']

  result_key = response[response_key].keys.find{|k| k.match(/Result$/)}
  hash.merge!(response[response_key][result_key]) if response[response_key][result_key] # not all APIs have a result object

  new(hash)
end