class IntacctRuby::Response
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.
Attributes
response_body[R]
Public Class Methods
new(xml_response)
click to toggle source
# 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
Public Instance Methods
function_errors()
click to toggle source
# File lib/intacct_ruby/response.rb, line 27 def function_errors @function_errors ||= @response_body.xpath('//error/description2') .map(&:text) end
Private Instance Methods
raise_function_errors()
click to toggle source
# File lib/intacct_ruby/response.rb, line 38 def raise_function_errors raise Exceptions::FunctionFailureException, function_errors.join("\n") end
transaction_successful?()
click to toggle source
# File lib/intacct_ruby/response.rb, line 34 def transaction_successful? function_errors.none? end