Class: IntacctRuby::Request
- Inherits:
-
Object
- Object
- IntacctRuby::Request
- 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
- REQUIRED_AUTHENTICATION_KEYS =
[ :senderid, :sender_password, :userid, :companyid, :user_password ].freeze
Instance Method Summary collapse
-
#initialize(*functions, request_params) ⇒ Request
constructor
A new instance of Request.
- #send(api = nil) ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(*functions, request_params) ⇒ Request
Returns a new instance of Request.
29 30 31 32 33 34 35 36 |
# File 'lib/intacct_ruby/request.rb', line 29 def initialize(*functions, request_params) # request_params should contain all req'd authentication information. If # not, an error will be thrown on #send @opts = DEFAULTS.dup.merge request_params # If a hash is provided + popped, the remaining attrs are functions @functions = functions end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object (private)
63 64 65 66 67 68 |
# File 'lib/intacct_ruby/request.rb', line 63 def method_missing(method_name, *arguments, &block) super unless Function::ALLOWED_TYPES.include? method_name.to_s # object_type must be the first argument in arguments @functions << Function.new(method_name, arguments.shift, *arguments) end |
Instance Method Details
#send(api = nil) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/intacct_ruby/request.rb', line 50 def send(api = nil) api ||= Api.new validate_keys! validate_functions! Response.new api.send(self) end |
#to_xml ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/intacct_ruby/request.rb', line 38 def to_xml @to_xml ||= begin @request = Builder::XmlMarkup.new request.instruct! request.request do control_block operation_block end end end |