~tim/wuparty

19614658daa890111e774130a5f35c70c4ac4b9d — Drew Delianides 7 years ago b8a5ab2
added the ability to count
1 files changed, 21 insertions(+), 1 deletions(-)

M lib/wuparty.rb
M lib/wuparty.rb => lib/wuparty.rb +21 -1
@@ 309,9 309,29 @@ class WuParty
        query[:sortDirection] = direction || 'ASC'
      end
      
      @party.get("forms/#{@id}/entries/count", :query => query)['Entries']
      @party.get("forms/#{@id}/entries", :query => query)['Entries']
    end

    # Return entries already submitted to the form.
    #
    # Supports:
    # Same as Entries above with filtering.
    # form.count(:filters => [['Field1', 'Is_equal_to', 'Tim']])
    #
    # See http://wufoo.com/docs/api/v3/entries/get/#filter for details
    def count(options={})
      query = {}

      if options[:filters]
        query['match'] = options[:filter_match] || 'AND'
        options[:filters].each_with_index do |filter, index|
          query["Filter#{ index + 1 }"] = filter.join(' ')
        end
      end      
      @party.get("forms/#{@id}/entries/count", :query => query)
    end


    # Submit form data to the form.
    # Pass data as a hash, with field ids as the hash keys, e.g.
    #   submit('Field1' => 'Tim', 'Field2' => 'Morgan')