class IntacctRuby::Function
a function to be sent to Intacct. Defined by a function type (e.g. :create), an object type, (e.g. :customer), and arguments.
Constants
- ALLOWED_TYPES
Public Class Methods
new(function_type, object_type, arguments = {})
click to toggle source
# File lib/intacct_ruby/function.rb, line 17 def initialize(function_type, object_type, arguments = {}) @function_type = function_type.to_s @object_type = object_type.to_s @arguments = arguments validate_type! end
Public Instance Methods
to_xml()
click to toggle source
# File lib/intacct_ruby/function.rb, line 25 def to_xml xml = Builder::XmlMarkup.new xml.function controlid: controlid do xml.tag!(@function_type) do xml.tag!(@object_type.upcase) do xml << argument_xml(@arguments) end end end xml.target! end
Private Instance Methods
argument_value_as_xml(value)
click to toggle source
# File lib/intacct_ruby/function.rb, line 63 def argument_value_as_xml(value) case value when Hash argument_xml(value) # recursive case when Array argument_value_list_xml(value) # recursive case else value.to_s # end case end end
argument_value_list_xml(array_of_hashes)
click to toggle source
# File lib/intacct_ruby/function.rb, line 74 def argument_value_list_xml(array_of_hashes) xml = Builder::XmlMarkup.new array_of_hashes.each do |argument_hash| xml << argument_xml(argument_hash) end xml.target! end
argument_xml(arguments_to_convert)
click to toggle source
# File lib/intacct_ruby/function.rb, line 49 def argument_xml(arguments_to_convert) xml = Builder::XmlMarkup.new arguments_to_convert.each do |key, value| argument_key = key.to_s.upcase xml.tag!(argument_key) do xml << argument_value_as_xml(value) end end xml.target! end
controlid()
click to toggle source
# File lib/intacct_ruby/function.rb, line 45 def controlid "#{@function_type}-#{@object_type}-#{timestamp}" end
timestamp()
click to toggle source
# File lib/intacct_ruby/function.rb, line 41 def timestamp @timestamp ||= Time.now.utc.to_s end
validate_type!()
click to toggle source
# File lib/intacct_ruby/function.rb, line 84 def validate_type! unless ALLOWED_TYPES.include?(@function_type) raise Exceptions::UnknownFunctionType, "Type #{@object_type} not recognized. Function Type must be " \ "one of #{ALLOWED_TYPES}." end end