Class: IntacctRuby::Response
- Inherits:
-
Object
- Object
- IntacctRuby::Response
- 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
-
#response_body ⇒ Object
readonly
Returns the value of attribute response_body.
Instance Method Summary collapse
- #function_errors ⇒ Object
-
#initialize(xml_response) ⇒ Response
constructor
A new instance of Response.
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_body ⇒ Object (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_errors ⇒ Object
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 |