wufoo 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History ADDED
@@ -0,0 +1,8 @@
1
+ == 0.2.0 2008-16-08
2
+ * 1 major enhancement
3
+ * Refactored to use client and submission and allow for gem growth
4
+
5
+ == 0.1.0 2008-16-08
6
+ * 1 major enhancement
7
+ * Initial release
8
+
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2007 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ examples/submission.rb
2
+ History
3
+ lib/wufoo/client.rb
4
+ lib/wufoo/submission.rb
5
+ lib/wufoo/version.rb
6
+ lib/wufoo.rb
7
+ Manifest
8
+ MIT-LICENSE
9
+ Rakefile
10
+ README
11
+ test/test_client.rb
12
+ test/test_helper.rb
13
+ test/test_submission.rb
14
+ test/test_wufoo.rb
data/README ADDED
@@ -0,0 +1,17 @@
1
+ = wufoo
2
+
3
+ == DESCRIPTION:
4
+
5
+ Currently it wraps the wufoo form submission api. Feel free to make additions to help it wrap their entire api.
6
+
7
+ == EXAMPLES:
8
+
9
+ See http://github.com/jnunemaker/wufoo/tree/master/examples
10
+
11
+ == REQUIREMENTS:
12
+
13
+ * HTTParty
14
+
15
+ == INSTALL:
16
+
17
+ * sudo gem install jnunemaker-wufoo --source http://gems.github.com
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+ require 'lib/wufoo/version'
5
+
6
+ Echoe.new('wufoo', Wufoo::Version) do |p|
7
+ p.description = 'simple wrapper for the wufoo api'
8
+ p.author = 'John Nunemaker'
9
+ p.email = 'nunemaker@gmail.com'
10
+ p.extra_deps = [['httparty', '0.2.2']]
11
+ end
12
+
13
+ desc 'Preps the gem for a new release'
14
+ task :prepare do
15
+ %w[manifest build_gemspec].each do |task|
16
+ Rake::Task[task].invoke
17
+ end
18
+ end
@@ -0,0 +1,32 @@
1
+ require 'yaml'
2
+ require File.dirname(__FILE__) + '/../lib/wufoo'
3
+ config = YAML::load(File.read(ENV['HOME'] + '/.wufoo'))
4
+
5
+ client = Wufoo::Client.new('http://orderedlist.wufoo.com', config['api_key'])
6
+ submission = Wufoo::Submission.new(client, 'orderedlistcom-project-request')
7
+
8
+ response = submission.add_params({
9
+ '1' => 'John Nunemaker',
10
+ '12' => 'nunemaker@gmail.com',
11
+ '4' => '1231231234',
12
+ '5' => 'http://addictedtonew.com',
13
+ '6' => 'ASAP!',
14
+ '10' => '1,000,000',
15
+ '11' => 'My cool project!',
16
+ }).process
17
+
18
+ if response.success?
19
+ puts response.message
20
+ else
21
+ # Something was wrong with the request
22
+ # (missing api key, invalid form, etc)
23
+ if response.fail?
24
+ puts response.error
25
+ end
26
+
27
+ # validation errors
28
+ unless response.valid?
29
+ errors = response.errors.collect { |e| "#{e.field_id} (#{e.code}): #{e.message}" }
30
+ puts errors * "\n"
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'rubygems'
4
+ gem 'httparty', '0.2.2'
5
+ require 'httparty'
6
+
7
+ require 'wufoo/client'
8
+ require 'wufoo/submission'
9
+ require 'wufoo/version'
@@ -0,0 +1,18 @@
1
+ module Wufoo
2
+ class Client
3
+ include HTTParty
4
+
5
+ attr_accessor :url, :api_key
6
+
7
+ def initialize(url, api_key)
8
+ @url, @api_key = url, api_key
9
+ end
10
+
11
+ def post(path, data)
12
+ data.merge!({
13
+ :w_api_key => api_key,
14
+ })
15
+ self.class.post("#{@url}#{path}", :query => data, :format => :json)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,81 @@
1
+ module Wufoo
2
+ class Submission
3
+ attr_accessor :client, :form, :params
4
+
5
+ def initialize(client, form, params={})
6
+ @client = client
7
+ @form = form
8
+ @params = {}.merge(params || {})
9
+ end
10
+
11
+ def add_params(new_params)
12
+ @params.merge!(new_params)
13
+ self
14
+ end
15
+
16
+ def process
17
+ Response.new(@client.post('/api/insert/', params.merge({:w_form => form})))
18
+ end
19
+
20
+ class Response
21
+ attr_accessor :data
22
+
23
+ def initialize(data)
24
+ @data = data
25
+ populate
26
+ end
27
+
28
+ def success?
29
+ return false if data.nil? || data == {}
30
+ data['wufoo_submit'].first['success'] == 'true'
31
+ end
32
+
33
+ def fail?
34
+ return true if data.nil? || data == {}
35
+ error.size > 0
36
+ end
37
+
38
+ def valid?
39
+ errors.size == 0
40
+ end
41
+
42
+ def error
43
+ @error || ''
44
+ end
45
+
46
+ def errors
47
+ @errors || []
48
+ end
49
+
50
+ def message
51
+ @message || ''
52
+ end
53
+
54
+ def entry_id
55
+ @entry_id
56
+ end
57
+
58
+ private
59
+ def populate
60
+ @message = data['wufoo_submit'].first['confirmation_message']
61
+ @entry_id = data['wufoo_submit'].first['entry_id']
62
+ @error = data['wufoo_submit'].first['error']
63
+ @raw_errors = data['wufoo_submit'].first['field_errors']
64
+
65
+ if @raw_errors && @raw_errors.size > 0
66
+ @errors = @raw_errors.inject([]) { |acc, error| acc << FieldError.new(error) }
67
+ end
68
+ end
69
+ end
70
+
71
+ class FieldError
72
+ attr_accessor :field_id, :code, :message
73
+
74
+ def initialize(attrs)
75
+ @field_id = attrs['field_id']
76
+ @code = attrs['error_code']
77
+ @message = attrs['error_message']
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Wufoo
2
+ Version = '0.2.0'
3
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TestClient < Test::Unit::TestCase
4
+ test 'initialize' do
5
+ client = Wufoo::Client.new('http://foobar.wufoo.com', 'somecrazyapikey')
6
+ assert_equal('http://foobar.wufoo.com', client.url)
7
+ assert_equal('somecrazyapikey', client.api_key)
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'context'
4
+ require 'stump'
5
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'wufoo')
6
+
7
+ def successful_response_data
8
+ {"wufoo_submit" => [{
9
+ "confirmation_message" => "Success! Thanks for filling out my form!",
10
+ "entry_id" => "1025",
11
+ "success" => "true"
12
+ }]}
13
+ end
14
+
15
+ def error_response_data
16
+ {"wufoo_submit" => [{
17
+ "error" => "The supplied form URL was not found.",
18
+ "field_errors" => [],
19
+ "success" => "false"
20
+ }]}
21
+ end
22
+
23
+ def field_error_response_data
24
+ {"wufoo_submit" => [{
25
+ "error" => "",
26
+ "field_errors" => [
27
+ {"field_id" => "field0", "error_message" => "Invalid email address.", "error_code" => "2"},
28
+ {"field_id" => "field1", "error_message" => "Field is required.", "error_code" => "0"},
29
+ ],
30
+ "success" => "false"
31
+ }]}
32
+ end
@@ -0,0 +1,129 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TestSubmission < Test::Unit::TestCase
4
+ before do
5
+ @client = Wufoo::Client.new('http://foobar.wufoo.com', 'somecrazyapikey')
6
+ end
7
+
8
+ test 'initialize' do
9
+ submission = Wufoo::Submission.new(@client, 'my-crazy-form')
10
+ assert_equal(@client, submission.client)
11
+ assert_equal('my-crazy-form', submission.form)
12
+ assert_equal({}, submission.params)
13
+ end
14
+
15
+ test 'initialize with params' do
16
+ submission = Wufoo::Submission.new(@client, 'my-crazy-form', {'0' => 'Foo'})
17
+ assert_equal({'0' => 'Foo'}, submission.params)
18
+ end
19
+
20
+ test 'add_params' do
21
+ submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params('0' => 'Foo')
22
+ assert_equal({'0' => 'Foo'}, submission.params)
23
+ end
24
+
25
+ test 'add_params returns self' do
26
+ assert_kind_of(Wufoo::Submission, Wufoo::Submission.new(@client, 'my-crazy-form').add_params('0' => 'Foo'))
27
+ end
28
+
29
+ context 'processing response that was successful' do
30
+ before do
31
+ @client.stub!(:post, :return => successful_response_data)
32
+ submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params({'0' => 'Foobar!'})
33
+ @response = submission.process
34
+ end
35
+
36
+ test 'should have data' do
37
+ assert_equal(successful_response_data, @response.data)
38
+ end
39
+
40
+ test 'should be success?' do
41
+ assert @response.success?
42
+ end
43
+
44
+ test 'should not be fail?' do
45
+ assert ! @response.fail?
46
+ end
47
+
48
+ test 'should be valid?' do
49
+ assert @response.valid?
50
+ end
51
+
52
+ test 'should have message' do
53
+ assert_equal('Success! Thanks for filling out my form!', @response.message)
54
+ end
55
+
56
+ test 'should have entry_id' do
57
+ assert_equal('1025', @response.entry_id)
58
+ end
59
+
60
+ test 'should not have error' do
61
+ assert_equal('', @response.error)
62
+ end
63
+
64
+ test 'should not have errors' do
65
+ assert_equal([], @response.errors)
66
+ end
67
+ end
68
+
69
+ context 'processing a response that failed' do
70
+ before do
71
+ @client.stub!(:post, :return => error_response_data)
72
+ submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params({'0' => 'Foobar!'})
73
+ @response = submission.process
74
+ end
75
+
76
+ test 'should have data' do
77
+ assert_equal(error_response_data, @response.data)
78
+ end
79
+
80
+ test 'should not be success?' do
81
+ assert ! @response.success?
82
+ end
83
+
84
+ test 'should be a fail?' do
85
+ assert @response.fail?
86
+ end
87
+
88
+ test 'should be valid?' do
89
+ assert @response.valid?
90
+ end
91
+
92
+ test 'should have error' do
93
+ assert_equal('The supplied form URL was not found.', @response.error)
94
+ end
95
+ end
96
+
97
+ context 'processing a response with field errors' do
98
+ before do
99
+ @client.stub!(:post, :return => field_error_response_data)
100
+ submission = Wufoo::Submission.new(@client, 'my-crazy-form').add_params({'0' => 'Foobar!'})
101
+ @response = submission.process
102
+ end
103
+
104
+ test 'should have data' do
105
+ assert_equal(field_error_response_data, @response.data)
106
+ end
107
+
108
+ test 'should not be success?' do
109
+ assert ! @response.success?
110
+ end
111
+
112
+ test 'should not be fail?' do
113
+ assert ! @response.fail?
114
+ end
115
+
116
+ test 'should not be valid?' do
117
+ assert ! @response.valid?
118
+ end
119
+
120
+ test 'should have errors' do
121
+ field_ids = ['field0', 'field1']
122
+ messages = ['Invalid email address.', 'Field is required.']
123
+ codes = ['2', '0']
124
+ assert_equal(field_ids, @response.errors.collect { |e| e.field_id })
125
+ assert_equal(messages, @response.errors.collect { |e| e.message })
126
+ assert_equal(codes, @response.errors.collect { |e| e.code })
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class TestWufoo < Test::Unit::TestCase
4
+ test 'should have version' do
5
+ assert_not_nil Wufoo::Version
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{wufoo}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["John Nunemaker"]
9
+ s.date = %q{2008-12-17}
10
+ s.description = %q{simple wrapper for the wufoo api}
11
+ s.email = %q{nunemaker@gmail.com}
12
+ s.extra_rdoc_files = ["lib/wufoo/client.rb", "lib/wufoo/submission.rb", "lib/wufoo/version.rb", "lib/wufoo.rb", "README"]
13
+ s.files = ["examples/submission.rb", "History", "lib/wufoo/client.rb", "lib/wufoo/submission.rb", "lib/wufoo/version.rb", "lib/wufoo.rb", "Manifest", "MIT-LICENSE", "Rakefile", "README", "test/test_client.rb", "test/test_helper.rb", "test/test_submission.rb", "test/test_wufoo.rb", "wufoo.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Wufoo", "--main", "README"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{wufoo}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{simple wrapper for the wufoo api}
21
+ s.test_files = ["test/test_client.rb", "test/test_helper.rb", "test/test_submission.rb", "test/test_wufoo.rb"]
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 2
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<httparty>, ["= 0.2.2"])
29
+ s.add_development_dependency(%q<echoe>, [">= 0"])
30
+ else
31
+ s.add_dependency(%q<httparty>, ["= 0.2.2"])
32
+ s.add_dependency(%q<echoe>, [">= 0"])
33
+ end
34
+ else
35
+ s.add_dependency(%q<httparty>, ["= 0.2.2"])
36
+ s.add_dependency(%q<echoe>, [">= 0"])
37
+ end
38
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wufoo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - John Nunemaker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-17 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - "="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.2.2
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: echoe
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: simple wrapper for the wufoo api
36
+ email: nunemaker@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - lib/wufoo/client.rb
43
+ - lib/wufoo/submission.rb
44
+ - lib/wufoo/version.rb
45
+ - lib/wufoo.rb
46
+ - README
47
+ files:
48
+ - examples/submission.rb
49
+ - History
50
+ - lib/wufoo/client.rb
51
+ - lib/wufoo/submission.rb
52
+ - lib/wufoo/version.rb
53
+ - lib/wufoo.rb
54
+ - Manifest
55
+ - MIT-LICENSE
56
+ - Rakefile
57
+ - README
58
+ - test/test_client.rb
59
+ - test/test_helper.rb
60
+ - test/test_submission.rb
61
+ - test/test_wufoo.rb
62
+ - wufoo.gemspec
63
+ has_rdoc: true
64
+ homepage: ""
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --line-numbers
68
+ - --inline-source
69
+ - --title
70
+ - Wufoo
71
+ - --main
72
+ - README
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ version:
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: "1.2"
86
+ version:
87
+ requirements: []
88
+
89
+ rubyforge_project: wufoo
90
+ rubygems_version: 1.3.1
91
+ signing_key:
92
+ specification_version: 2
93
+ summary: simple wrapper for the wufoo api
94
+ test_files:
95
+ - test/test_client.rb
96
+ - test/test_helper.rb
97
+ - test/test_submission.rb
98
+ - test/test_wufoo.rb