Class: Intacct::Response

Inherits:
Object
  • Object
show all
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.

Examples:

Parse a response

response = Intacct::Response.new(http_response)
if response.successful?
  result = response.get_function_result("my-control-id")
  puts result.data
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Initialize a new Response from an HTTP response

Parameters:

  • http_response (Net::HTTPResponse)

    the HTTP response from Intacct API

Raises:

  • (Net::HTTPError)

    if the response status is not 2xx



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_bodyNokogiri::XML::Document (readonly)

Returns the parsed XML response body.

Returns:

  • (Nokogiri::XML::Document)

    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_resultAuthenticationResult

Get the authentication result from the response

Returns:



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

Parameters:

  • control_id (String, Symbol)

    the control ID of the function

Returns:



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

Returns:

  • (Boolean)

    true if the response control status is "success"



36
37
38
# File 'lib/intacct/response.rb', line 36

def successful?
  @response_body.xpath("//response/control/status").text == "success"
end