class OpenMarket::Response

Attributes

code[R]
description[R]

Public Class Methods

new(http_response) click to toggle source
# 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