wuparty 1.1.2 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README.rdoc +1 -1
  2. data/lib/wuparty.rb +31 -16
  3. data/test/wuparty_test.rb +7 -7
  4. metadata +8 -8
data/README.rdoc CHANGED
@@ -96,7 +96,7 @@ Make the name field required. Then run:
96
96
  WUFOO_ACCOUNT=accountname \
97
97
  WUFOO_API_KEY=AAAA-BBBB-CCCC-DDDD \
98
98
  WUFOO_FORM_ID=test-form \
99
- ruby -rrubygems test/wuparty_test.rb
99
+ rake test
100
100
 
101
101
  == License
102
102
 
data/lib/wuparty.rb CHANGED
@@ -270,25 +270,40 @@ class WuParty
270
270
 
271
271
  # Return entries already submitted to the form.
272
272
  #
273
- # If you need to filter entries, pass an array as the first argument:
274
- # entries([[field_id, operator, value], ...])
275
- # e.g.:
276
- # entries([['EntryId', 'Is_after', 12], ['EntryId', 'Is_before', 17]])
277
- # entries([['Field1', 'Is_equal', 'Tim']])
278
- # The second arg is the match parameter (AND/OR) and defaults to 'AND', e.g.
279
- # entries([['Field2', 'Is_equal', 'Morgan'], ['Field2', 'Is_equal', 'Smith']], 'OR')
273
+ # Supports:
274
+ # - filtering:
275
+ # entries(:filters => [['Field1', 'Is_equal_to', 'Tim']])
276
+ # entries(:filters => [['Field1', 'Is_equal_to', 'Tim'], ['Field2', 'Is_equal_to', 'Morgan']], :filter_match => 'OR')
277
+ #
278
+ # - sorting:
279
+ # entries(:sort => 'EntryId DESC')
280
+ #
281
+ # - limiting:
282
+ # entries(:limit => 5)
283
+ #
280
284
  # See http://wufoo.com/docs/api/v3/entries/get/#filter for details
281
- def entries(filters=[], filter_match='AND')
282
- if filters.any?
283
- options = {'match' => filter_match}
284
- filters.each_with_index do |filter, index|
285
- options["Filter#{index+1}"] = filter.join(' ')
285
+ def entries(options={})
286
+ query = {}
287
+
288
+ if options[:filters]
289
+ query['match'] = options[:filter_match] || 'AND'
290
+ options[:filters].each_with_index do |filter, index|
291
+ query["Filter#{ index + 1 }"] = filter.join(' ')
286
292
  end
287
- options = {:query => options}
288
- else
289
- options = {}
290
293
  end
291
- @party.get("forms/#{@id}/entries", options)['Entries']
294
+
295
+ if options[:limit]
296
+ query[:pageSize] = options[:limit]
297
+ query[:pageStart] = 0
298
+ end
299
+
300
+ if options[:sort]
301
+ field, direction = options[:sort].split(' ')
302
+ query[:sort] = field
303
+ query[:sortDirection] = direction || 'ASC'
304
+ end
305
+
306
+ @party.get("forms/#{@id}/entries", :query => query)['Entries']
292
307
  end
293
308
 
294
309
  # Submit form data to the form.
data/test/wuparty_test.rb CHANGED
@@ -1,4 +1,4 @@
1
- require File.dirname(__FILE__) + '/../lib/wuparty'
1
+ require './lib/wuparty'
2
2
  require 'test/unit'
3
3
 
4
4
  class WuPartyTest < Test::Unit::TestCase
@@ -55,8 +55,8 @@ class WuPartyTest < Test::Unit::TestCase
55
55
  def test_form_fields
56
56
  form = @wufoo.form(@form_id)
57
57
  field_names = form.fields.map { |f| f['Title'] }
58
- assert field_names.include?('Name')
59
- assert field_names.include?('Address')
58
+ assert field_names.include?('Name'), 'Name field not found in #fields'
59
+ assert field_names.include?('Address'), 'Address field not found in #fields'
60
60
  end
61
61
 
62
62
  def test_form_submit
@@ -86,17 +86,17 @@ class WuPartyTest < Test::Unit::TestCase
86
86
  def test_entries
87
87
  form = @wufoo.form(@form_id)
88
88
  form.submit('Field1' => 'Tim', 'Field2' => 'Morgan')
89
- assert form.entries.last['Field1'].any?
89
+ assert_equal 'Tim', form.entries.last['Field1']
90
90
  end
91
91
 
92
92
  def test_filtering_entries
93
93
  form = @wufoo.form(@form_id)
94
94
  form.submit('Field1' => 'Tim', 'Field2' => 'Morgan')
95
95
  id = form.submit('Field1' => 'Jane', 'Field2' => 'Smith')['EntryId']
96
- assert form.entries([['Field2', 'Is_equal_to', 'Morgan']]).any?
97
- assert_equal 1, form.entries([['EntryId', 'Is_equal_to', id]]).length
96
+ assert form.entries(:filters => [['Field2', 'Is_equal_to', 'Morgan']]).any?
97
+ assert_equal 1, form.entries(:filters => [['EntryId', 'Is_equal_to', id]]).length
98
98
  end
99
-
99
+
100
100
  def test_add_webhook
101
101
  # test with optional parameters
102
102
  response = @wufoo.add_webhook(@form_id, "http://#{ENV['WUFOO_ACCOUNT']}.com/#{@form_id}", true, "handshakeKey01")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wuparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-06 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
16
- requirement: &5541100 !ruby/object:Gem::Requirement
16
+ requirement: &8964580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.6.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *5541100
24
+ version_requirements: *8964580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: multipart-post
27
- requirement: &5540580 !ruby/object:Gem::Requirement
27
+ requirement: &9022120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *5540580
35
+ version_requirements: *9022120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mime-types
38
- requirement: &5539960 !ruby/object:Gem::Requirement
38
+ requirement: &9021640 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '1.16'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *5539960
46
+ version_requirements: *9021640
47
47
  description:
48
48
  email: tim@timmorgan.org
49
49
  executables: []