express_pigeon 1.0.2 → 1.0.3

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.
@@ -0,0 +1,10 @@
1
+ project_name: ep
2
+ project_root: ~/projects/express_pigeon-rb
3
+ socket_name: express_pigeon-rb
4
+ rvm: ruby-1.9.3-perf@express_pigeon
5
+ tabs:
6
+ - editor:
7
+ layout: main-vertical
8
+ panes:
9
+ - vim
10
+ - clear; bundle exec rspec spec/
@@ -1,3 +1,3 @@
1
1
  module ExpressPigeon
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  end
@@ -4,8 +4,78 @@ require 'curb-fu'
4
4
  require 'active_model/validations/date_format_validator'
5
5
 
6
6
  module ExpressPigeon
7
+ module WebFormValidations
8
+ def self.included(base)
9
+
10
+ base.validates :guid, :presence => true
11
+ base.validates :email, :presence => true, :length => 3..50, :allow_blank => false
12
+
13
+ # TODO check the actual form to see whether a field is required.
14
+ #
15
+ # The functionality to check whether a field is actually required
16
+ # hasn't been implemented yet. Go ahead and just assume they're not
17
+ # required and just check bounds.
18
+ base.validates :address1, :length => 0..255, :allow_blank => true
19
+ base.validates :address2, :length => 0..255, :allow_blank => true
20
+ base.validates :city, :length => 0..128, :allow_blank => true
21
+ base.validates :company, :length => 0..128, :allow_blank => true
22
+ base.validates :country, :length => 0..128, :allow_blank => true
23
+
24
+ # now sure why we can put 255 chars into date of birth but that's what it is.
25
+ # TODO validate and require date format, submit as MM/DD/YYYY
26
+ base.validates :date_of_birth, :length => 0..255, :allow_blank => true, :date_format => true
27
+
28
+ # will email_form be a submittable field?
29
+ base.validates :first_name, :length => 0..50, :allow_blank => true
30
+ base.validates :last_name, :length => 0..50, :allow_blank => true
31
+ base.validates :phone, :length => 0..30, :allow_blank => true
32
+ base.validates :state, :length => 0..48, :allow_blank => true # state is 48?
33
+ base.validates :title, :length => 0..30, :allow_blank => true
34
+ base.validates :zip, :length => 0..24, :allow_blank => true # zip is 24?
35
+
36
+ # TODO validate state
37
+ # TODO validate field sizes
38
+ end
39
+ end
40
+
41
+ module WebFormPushable
42
+ def push_to_express_pigeon!
43
+ def url; "https://expresspigeon.com/subscription/add_contact"; end
44
+
45
+ params = {
46
+ :address1 => self.address1,
47
+ :address2 => self.address2,
48
+ :city => self.city,
49
+ :company => self.company,
50
+ :country => self.country,
51
+ :date_of_birth => format_date(self.date_of_birth),
52
+ :email => self.email,
53
+ :first_name => self.first_name,
54
+ :guid => self.guid,
55
+ :last_name => self.last_name,
56
+ :phone => self.phone,
57
+ :state => self.state,
58
+ :title => self.title,
59
+ :zip => self.zip,
60
+ }
61
+
62
+ response = CurbFu.post({:url => url}, params)
63
+
64
+ response
65
+ end
66
+
67
+ def format_date(date)
68
+ return "" if date.blank?
69
+
70
+ Chronic.parse(date).strftime("%m/%d/%Y")
71
+ end
72
+ end
73
+
74
+
7
75
  class WebForm
8
76
  include ActiveModel::Validations
77
+ include WebFormValidations
78
+ include WebFormPushable
9
79
 
10
80
  include ActiveModel::Dirty
11
81
 
@@ -28,35 +98,6 @@ module ExpressPigeon
28
98
 
29
99
  # TODO after submitting the form try to capture the response for errors?
30
100
 
31
- validates :guid, :presence => true
32
- validates :email, :presence => true, :length => 3..50, :allow_blank => false
33
-
34
- # TODO check the actual form to see whether a field is required.
35
- #
36
- # The functionality to check whether a field is actually required
37
- # hasn't been implemented yet. Go ahead and just assume they're not
38
- # required and just check bounds.
39
- validates :address1, :length => 0..255, :allow_blank => true
40
- validates :address2, :length => 0..255, :allow_blank => true
41
- validates :city, :length => 0..128, :allow_blank => true
42
- validates :company, :length => 0..128, :allow_blank => true
43
- validates :country, :length => 0..128, :allow_blank => true
44
-
45
- # now sure why we can put 255 chars into date of birth but that's what it is.
46
- # TODO validate and require date format, submit as MM/DD/YYYY
47
- validates :date_of_birth, :length => 0..255, :allow_blank => true, :date_format => true
48
-
49
- # will email_form be a submittable field?
50
- validates :first_name, :length => 0..50, :allow_blank => true
51
- validates :last_name, :length => 0..50, :allow_blank => true
52
- validates :phone, :length => 0..30, :allow_blank => true
53
- validates :state, :length => 0..48, :allow_blank => true # state is 48?
54
- validates :title, :length => 0..30, :allow_blank => true
55
- validates :zip, :length => 0..24, :allow_blank => true # zip is 24?
56
-
57
- # TODO validate state
58
- # TODO validate field sizes
59
-
60
101
  def address1 ; @address1 ; end
61
102
  def address2 ; @address2 ; end
62
103
  def city ; @city ; end
@@ -98,35 +139,5 @@ module ExpressPigeon
98
139
 
99
140
  private
100
141
 
101
- def push_to_express_pigeon!
102
- url = "https://expresspigeon.com/subscription/add_contact"
103
-
104
- params = {
105
- :address1 => self.address1,
106
- :address2 => self.address2,
107
- :city => self.city,
108
- :company => self.company,
109
- :country => self.country,
110
- :date_of_birth => format_date(self.date_of_birth),
111
- :email => self.email,
112
- :first_name => self.first_name,
113
- :guid => self.guid,
114
- :last_name => self.last_name,
115
- :phone => self.phone,
116
- :state => self.state,
117
- :title => self.title,
118
- :zip => self.zip,
119
- }
120
-
121
- response = CurbFu.post({:url => url}, params)
122
-
123
- response
124
- end
125
-
126
- def format_date(date)
127
- return "" if date.blank?
128
-
129
- date.strftime("%m/%d/%Y")
130
- end
131
142
  end
132
143
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: express_pigeon
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-25 00:00:00.000000000 Z
12
+ date: 2012-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -77,6 +77,7 @@ files:
77
77
  - README.md
78
78
  - Rakefile
79
79
  - bin/console
80
+ - express_pigeon-rb.yml
80
81
  - express_pigeon.gemspec
81
82
  - lib/active_model/validations/date_format_validator.rb
82
83
  - lib/express_pigeon.rb