Class: Intacct::Response
- Inherits:
-
Object
- Object
- Intacct::Response
- Defined in:
- lib/intacct/response.rb
Overview
Parses and provides access to Intacct API XML responses.
Wraps the HTTP response from Intacct and provides convenient methods to check status and extract function results.
Instance Attribute Summary collapse
-
#response_body ⇒ Nokogiri::XML::Document
readonly
The parsed XML response body.
Instance Method Summary collapse
-
#get_authentication_result ⇒ AuthenticationResult
Get the authentication result from the response.
-
#get_function_result(control_id) ⇒ FunctionResult?
Get the function result for a specific control ID.
-
#initialize(http_response) ⇒ Response
constructor
Initialize a new Response from an HTTP response.
-
#successful? ⇒ Boolean
Check if the overall response was successful.
Constructor Details
#initialize(http_response) ⇒ Response
Initialize a new Response from an HTTP response
26 27 28 29 30 31 |
# File 'lib/intacct/response.rb', line 26 def initialize(http_response) @response_body = Nokogiri::XML(http_response.body) # raises an error unless the response is in the 2xx range. http_response.value end |
Instance Attribute Details
#response_body ⇒ Nokogiri::XML::Document (readonly)
Returns the parsed XML response body.
20 21 22 |
# File 'lib/intacct/response.rb', line 20 def response_body @response_body end |
Instance Method Details
#get_authentication_result ⇒ AuthenticationResult
Get the authentication result from the response
52 53 54 |
# File 'lib/intacct/response.rb', line 52 def get_authentication_result Intacct::AuthenticationResult.new(@response_body.xpath("//response/operation/authentication")) end |
#get_function_result(control_id) ⇒ FunctionResult?
Get the function result for a specific control ID
44 45 46 47 |
# File 'lib/intacct/response.rb', line 44 def get_function_result(control_id) @function_results ||= build_function_results @function_results[control_id.to_s] end |
#successful? ⇒ Boolean
Check if the overall response was successful
36 37 38 |
# File 'lib/intacct/response.rb', line 36 def successful? @response_body.xpath("//response/control/status").text == "success" end |