Class: OpenMarket::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Returns a new instance of Response.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/open_market/response.rb', line 6

def initialize(http_response)
  (class << self; self; end).class_eval do
    # Defining a member variable for xml would pollute #inspect
    # This solution is inspired by https://github.com/jordansissel/software-patterns/tree/master/dont-log-secrets/ruby
    define_method(:xml) do
      if http_response.respond_to?(:body)
        REXML::Document.new(http_response.body).root
      else
        REXML::Document.new(http_response.to_xml).root.elements["response"]
      end
    end
    private :xml
  end
  error = xml.elements["error"]
  @code = (error.attributes["code"] || error.elements["code"].text).to_i
  @description = error.attributes["description"] || error.elements["description"].text
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/open_market/response.rb', line 5

def code
  @code
end

#descriptionObject (readonly)

Returns the value of attribute description.



5
6
7
# File 'lib/open_market/response.rb', line 5

def description
  @description
end