lib/intacctrb/base.rb in intacctrb-0.2.1pre vs lib/intacctrb/base.rb in intacctrb-0.3pre

- old
+ new

@@ -12,11 +12,14 @@ after_send_xml :set_date_time attr_accessor :response, :data, :sent_xml, :intacct_action def initialize *params - params[0] = OpenStruct.new(params[0]) if params[0].is_a? Hash + if params[0].is_a? Hash + json_data = params[0].to_json + params[0] = JSON.parse(json_data, object_class: OpenStruct) + end params[0] ||= OpenStruct.new() super(*params) end def intacct_id @@ -105,8 +108,28 @@ if %w(create update delete).include? type if object.respond_to? :"intacct_#{type}d_at" object.send("intacct_#{type}d_at=", DateTime.now) end end + end + + def filter_xml(xml, options) + if options[:filters] + xml.filter { + options[:filters].each do |filter| + xml.expression do + xml.field(filter[:field]) + xml.operator(filter[:operator] || '=') + xml.value(filter[:value]) + end + end + } + end + end + + def date_xml(xml, date) + xml.year date.to_date.strftime("%Y") + xml.month date.to_date.strftime("%m") + xml.day date.to_date.strftime("%d") end end end