lib/qbxml/request.rb
# This is where the magic happens to convert a request object into xml worthy of quickbooks.
This is where the magic happens to convert a request object into xml worthy of quickbooks.
This is where the magic happens to convert a request object into xml worthy of quickbooks .
def to_xml(as_set=true)
      return (RequestSet.new(self)).to_xml if as_set 
      req = Builder::XmlMarkup.new(:indent => 2)
      request_root, container = case
      when @type.is_one_of?(:query)
        ["#{@klass.class_leaf_name}QueryRq", nil]
      when @type == :add
        ["#{@klass.class_leaf_name}AddRq", "#{@klass.class_leaf_name}Add"]
      when @type == :mod
        ["#{@klass.class_leaf_name}ModRq", "#{@klass.class_leaf_name}Mod"]
      when @type == :delete
        ["#{@klass.ListOrTxn}DelRq", nil]
      when @type == :deleted
        ["#{@klass.ListOrTxn}DeletedQueryRq", nil]
      else
        raise RuntimeError, "Could not convert this request to qbxml!\n#{self.inspect}"
      end
      inner_stuff = lambda {
        deep_tag = lambda {|k,v|
          if v.is_a?(Hash)
            if k == ''
              v.each { |k,v|
                deep_tag.call(k,v)
              }
            else
              req.tag!(k.camelize) { v.each { |k,v| deep_tag.call(k,v) } }
            end
          else
            req.tag!(k.camelize,uncast(v))
          end
        }
        if @type.is_one_of?(:add, :mod)
          if @type == :mod
            req.tag!(@klass.ListOrTxn + 'ID', @object.send("#{@klass.ListOrTxn}Id".underscore))
            req.tag!('EditSequence', @object.send(:edit_sequence))
          end
          deep_tag.call('',@object.to_dirty_hash) 
        elsif @type == :query && @object.class == @klass
          req.tag!(@klass.ListOrTxn + 'ID', @object.send("#{@klass.ListOrTxn}Id".underscore))
          deep_tag.call('', @filters)
        elsif @type == :delete
          req.tag!(@klass.ListOrTxn + 'DelType', @klass.class_leaf_name)
          req.tag!(@klass.ListOrTxn + 'ID', @object.send("#{@klass.ListOrTxn}Id".underscore))
        else
          deep_tag.call('', @filters)
        end
        @ret_elements.each { |r| req.tag!('IncludeRetElement', r) } if @ret_elements.is_a?(Array) && @ret_elements.length > 0
      }
      req.tag!(request_root, :requestID => self.class.next_request_id) {
        if container
          req.tag!(container) {
            inner_stuff.call
          }
        else
          inner_stuff.call
        end
      }
      req.target! 
    end
def to_xml ( as_set = true ) return ( RequestSet . new ( self ) ) . to_xml if as_set req = Builder :: XmlMarkup . new ( :indent => 2 ) request_root , container = case when @type . is_one_of? ( :query ) [ "#{@klass.class_leaf_name}QueryRq" , nil ] when @type == :add [ "#{@klass.class_leaf_name}AddRq" , "#{@klass.class_leaf_name}Add" ] when @type == :mod [ "#{@klass.class_leaf_name}ModRq" , "#{@klass.class_leaf_name}Mod" ] when @type == :delete [ "#{@klass.ListOrTxn}DelRq" , nil ] when @type == :deleted [ "#{@klass.ListOrTxn}DeletedQueryRq" , nil ] else raise RuntimeError , "Could not convert this request to qbxml!\n#{self.inspect}" end inner_stuff = lambda { deep_tag = lambda { | k , v | if v . is_a? ( Hash ) if k == '' v . each { | k , v | deep_tag . call ( k , v ) } else req . tag! ( k . camelize ) { v . each { | k , v | deep_tag . call ( k , v ) } } end else req . tag! ( k . camelize , uncast ( v ) ) end } if @type . is_one_of? ( :add , :mod ) if @type == :mod req . tag! ( @klass . ListOrTxn + 'ID' , @object . send ( "#{@klass.ListOrTxn}Id" . underscore ) ) req . tag! ( 'EditSequence' , @object . send ( :edit_sequence ) ) end deep_tag . call ( '' , @object . to_dirty_hash ) elsif @type == :query && @object . class == @klass req . tag! ( @klass . ListOrTxn + 'ID' , @object . send ( "#{@klass.ListOrTxn}Id" . underscore ) ) deep_tag . call ( '' , @filters ) elsif @type == :delete req . tag! ( @klass . ListOrTxn + 'DelType' , @klass . class_leaf_name ) req . tag! ( @klass . ListOrTxn + 'ID' , @object . send ( "#{@klass.ListOrTxn}Id" . underscore ) ) else deep_tag . call ( '' , @filters ) end @ret_elements . each { | r | req . tag! ( 'IncludeRetElement' , r ) } if @ret_elements . is_a? ( Array ) && @ret_elements . length > 0 } req . tag! ( request_root , :requestID => self . class . next_request_id ) { if container req . tag! ( container ) { inner_stuff . call } else inner_stuff . call end } req . target! end
This is where the magic happens to convert a request object into xml worthy of quickbooks.
This is where the magic happens to convert a request object into xml worthy of quickbooks .
# Simple call yields xml as a single request in a request set. However, if the xml for the lone request is required, pass false. # Add the specific elements for the respective request type # First the ObjectId: # Second the EditSequence # Then, all the dirty_attributes # (this is an hash statically ordered to the model's qbxml attribute order) # Sent an instance object for a query - we should include the ListId/TxnId (then other filters?) # just filters # Lastly, specify the fields to return, if desired # The xml string
as_set
<not_specific>