Class: PayWithAmazon::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/pay_with_amazon/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.

Parameters:

  • response (String)

9
10
11
# File 'lib/pay_with_amazon/response.rb', line 9

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject


13
14
15
# File 'lib/pay_with_amazon/response.rb', line 13

def body
  @response.body
end

#codeObject


29
30
31
# File 'lib/pay_with_amazon/response.rb', line 29

def code
  @response.code
end

#get_element(xpath, xml_element) ⇒ Object


21
22
23
24
25
26
27
# File 'lib/pay_with_amazon/response.rb', line 21

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

#successObject


33
34
35
36
37
38
39
# File 'lib/pay_with_amazon/response.rb', line 33

def success
 if @response.code.eql? '200'
    return true
 else
    return false
 end
end

#to_xmlObject


17
18
19
# File 'lib/pay_with_amazon/response.rb', line 17

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