Class: AmazonPay::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon_pay/response.rb

Overview

This class provides helpers to parse the response

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Response

Returns a new instance of Response.



6
7
8
# File 'lib/amazon_pay/response.rb', line 6

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject



10
11
12
# File 'lib/amazon_pay/response.rb', line 10

def body
  @response.body
end

#codeObject



27
28
29
# File 'lib/amazon_pay/response.rb', line 27

def code
  @response.code
end

#get_element(xpath, xml_element) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/amazon_pay/response.rb', line 18

def get_element(xpath, xml_element)
  xml = to_xml
  value = nil
  xml.elements.each(xpath) do |element|
    value = element.elements[xml_element].text
  end
  value
end

#successObject



31
32
33
# File 'lib/amazon_pay/response.rb', line 31

def success
  @response.code.eql? '200'
end

#to_xmlObject



14
15
16
# File 'lib/amazon_pay/response.rb', line 14

def to_xml
  REXML::Document.new(body)
end