Class: IntacctRuby::Response

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

Overview

Wraps an XML API response, throwing an exception if the call was unsucessful

This class can be instantiated on its own, but only in cases where the contents of the response (e.g. generated keys, query results) aren’t important.

If, for example, a key returned needs to be extracted from the response, extend this class and add methods that access whatever data is required.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml_response) ⇒ Response

Returns a new instance of Response.



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

def initialize(xml_response)
  @response_body = Nokogiri::XML(xml_response.body)

  # raises an error unless the response is in the 2xx range.
  xml_response.value

  # in case the response is a success, but one of the included functions
  # failed and the transaction was rolled back
  raise_function_errors unless transaction_successful?
end

Instance Attribute Details

#response_bodyObject (readonly)

Returns the value of attribute response_body.



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

def response_body
  @response_body
end

Instance Method Details

#function_errorsObject



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

def function_errors
  @function_errors ||= @response_body.xpath('//error/description2')
                                     .map(&:text)
end