Class: IntacctRuby::Request

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

Overview

An outgoing request to the Intacct API. Can have multiple functions. Complete with send method that gets (and wraps) response from Intacct.

Constant Summary collapse

DEFAULTS =
{
  uniqueid: false,
  dtdversion: 3.0,
  includewhitespace: false,
  transaction: true
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Request

Returns a new instance of Request.



18
19
20
21
22
23
24
25
26
27
# File 'lib/intacct_ruby/request.rb', line 18

def initialize(*args)
  @opts = DEFAULTS.dup

  # `args` should be a list of Intacct::Function objects, with the last
  # argument optionally providing overrides to request defaults
  @opts.merge!(args.pop) if args.last.is_a? Hash

  # If a hash is provided + popped, the remaining attrs are functions
  @functions = args
end

Instance Method Details

#send(api = nil) ⇒ Object



39
40
41
42
43
# File 'lib/intacct_ruby/request.rb', line 39

def send(api = nil)
  api ||= Api.new

  Response.new api.send(self)
end

#to_xmlObject



29
30
31
32
33
34
35
36
37
# File 'lib/intacct_ruby/request.rb', line 29

def to_xml
  @request = Builder::XmlMarkup.new

  request.instruct!
  request.request do
    control_block
    operation_block
  end
end