twilio_contactable 0.8.5 → 0.8.7
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/VERSION +1 -1
- data/lib/contactable.rb +6 -20
- data/lib/gateway.rb +12 -8
- data/lib/twilio_contactable.rb +14 -1
- data/test/twilio_contactable_contactable_test.rb +17 -11
- data/twilio_contactable.gemspec +1 -1
- metadata +8 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.8.
|
1
|
+
0.8.7
|
data/lib/contactable.rb
CHANGED
@@ -89,14 +89,7 @@ module TwilioContactable
|
|
89
89
|
return false if _TC_phone_number.blank?
|
90
90
|
|
91
91
|
format_phone_number
|
92
|
-
confirmation_code =
|
93
|
-
if sms_confirmation_attempted &&
|
94
|
-
sms_confirmation_code &&
|
95
|
-
sms_confirmation_attempted > Time.now.utc - 60*5
|
96
|
-
sms_confirmation_code
|
97
|
-
else
|
98
|
-
TwilioContactable.generate_confirmation_code
|
99
|
-
end
|
92
|
+
confirmation_code = TwilioContactable.confirmation_code(self, :sms)
|
100
93
|
|
101
94
|
# Use this class' confirmation_message method if it
|
102
95
|
# exists, otherwise use the generic message
|
@@ -112,9 +105,9 @@ module TwilioContactable
|
|
112
105
|
|
113
106
|
if response.success?
|
114
107
|
update_twilio_contactable_sms_confirmation confirmation_code
|
115
|
-
else
|
116
|
-
false
|
117
108
|
end
|
109
|
+
|
110
|
+
response
|
118
111
|
end
|
119
112
|
|
120
113
|
# Begins a phone call to the user where they'll need to type
|
@@ -125,22 +118,15 @@ module TwilioContactable
|
|
125
118
|
return false if _TC_phone_number.blank?
|
126
119
|
|
127
120
|
format_phone_number
|
128
|
-
confirmation_code =
|
129
|
-
if voice_confirmation_attempted &&
|
130
|
-
voice_confirmation_code &&
|
131
|
-
voice_confirmation_attempted > Time.now.utc - 60*5
|
132
|
-
voice_confirmation_code
|
133
|
-
else
|
134
|
-
TwilioContactable.generate_confirmation_code
|
135
|
-
end
|
121
|
+
confirmation_code = TwilioContactable.confirmation_code(self, :voice)
|
136
122
|
|
137
123
|
response = TwilioContactable::Gateway.initiate_voice_call(self, _TC_formatted_phone_number)
|
138
124
|
|
139
125
|
if response.success?
|
140
126
|
update_twilio_contactable_voice_confirmation confirmation_code
|
141
|
-
else
|
142
|
-
false
|
143
127
|
end
|
128
|
+
|
129
|
+
response
|
144
130
|
end
|
145
131
|
|
146
132
|
# Compares user-provided code with the stored confirmation
|
data/lib/gateway.rb
CHANGED
@@ -17,16 +17,20 @@ module TwilioContactable
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
class Response
|
20
|
-
def initialize(
|
21
|
-
@
|
20
|
+
def initialize(response = nil)
|
21
|
+
@response = response
|
22
22
|
end
|
23
|
-
|
23
|
+
end
|
24
|
+
class Success < Response
|
25
|
+
def success?
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
class Error < Response
|
24
30
|
def success?
|
25
|
-
|
31
|
+
false
|
26
32
|
end
|
27
33
|
end
|
28
|
-
Success = Response.new(:status => :success)
|
29
|
-
Error = Response.new(:status => :error)
|
30
34
|
|
31
35
|
API_VERSION = '2010-04-01'
|
32
36
|
|
@@ -88,8 +92,8 @@ module TwilioContactable
|
|
88
92
|
response = post service, data
|
89
93
|
|
90
94
|
Net::HTTPCreated == response.code_type ?
|
91
|
-
TwilioContactable::Gateway::Success :
|
92
|
-
TwilioContactable::Gateway::Error
|
95
|
+
TwilioContactable::Gateway::Success.new(response) :
|
96
|
+
TwilioContactable::Gateway::Error.new(response)
|
93
97
|
end
|
94
98
|
|
95
99
|
def post(service, data = {})
|
data/lib/twilio_contactable.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
module TwilioContactable
|
2
|
+
CONFIRMATION_CODE_LENGTH = 4
|
2
3
|
class << self
|
3
4
|
def numerize(numberish)
|
4
5
|
numberish.to_s.scan(/\d+/).join
|
@@ -20,9 +21,21 @@ module TwilioContactable
|
|
20
21
|
"Code: #{confirmation_code} Enter code on web to verify phone. Msg&data rates may apply. Freq set by u. T&C & support on web site. Txt HELP for help"
|
21
22
|
end
|
22
23
|
|
24
|
+
def confirmation_code(record, type)
|
25
|
+
attempted = record.send("_TC_#{type}_confirmation_attempted")
|
26
|
+
current_code = record.send("_TC_#{type}_confirmation_code")
|
27
|
+
if !attempted.blank? &&
|
28
|
+
attempted > Time.now.utc - 60*5 &&
|
29
|
+
current_code.to_s.size == CONFIRMATION_CODE_LENGTH
|
30
|
+
current_code
|
31
|
+
else
|
32
|
+
generate_confirmation_code
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
23
36
|
def generate_confirmation_code
|
24
37
|
nums = (0..9).to_a
|
25
|
-
(0...
|
38
|
+
(0...CONFIRMATION_CODE_LENGTH).collect { nums[Kernel.rand(nums.length)] }.join
|
26
39
|
end
|
27
40
|
end
|
28
41
|
end
|
@@ -2,8 +2,8 @@ require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
|
2
2
|
|
3
3
|
class TwilioContactableContactableTest < ActiveSupport::TestCase
|
4
4
|
|
5
|
-
Success = TwilioContactable::Gateway::
|
6
|
-
Error = TwilioContactable::Gateway::
|
5
|
+
Success = TwilioContactable::Gateway::Success.new
|
6
|
+
Error = TwilioContactable::Gateway::Error.new
|
7
7
|
|
8
8
|
context "configuration" do
|
9
9
|
TwilioContactable::Contactable::Attributes.each do |attr|
|
@@ -98,7 +98,8 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
|
|
98
98
|
}
|
99
99
|
should "work" do assert @worked end
|
100
100
|
should "save confirmation number in proper attribute" do
|
101
|
-
assert @user._TC_sms_confirmation_code
|
101
|
+
assert @user._TC_sms_confirmation_code.length ==
|
102
|
+
TwilioContactable::CONFIRMATION_CODE_LENGTH
|
102
103
|
end
|
103
104
|
should "set confirmation attempted time" do
|
104
105
|
assert @user._TC_sms_confirmation_attempted > 3.minutes.ago
|
@@ -151,7 +152,7 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
|
|
151
152
|
end
|
152
153
|
end
|
153
154
|
end
|
154
|
-
context "
|
155
|
+
context "with a custom short code" do
|
155
156
|
context "with expectations" do
|
156
157
|
setup {
|
157
158
|
message = "long message blah blah MYCODE blah"
|
@@ -171,12 +172,14 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
|
|
171
172
|
end
|
172
173
|
end
|
173
174
|
end
|
174
|
-
context "
|
175
|
+
context "when the confirmation fails for some reason" do
|
175
176
|
setup {
|
176
177
|
TwilioContactable::Gateway.stubs(:deliver).returns(Error)
|
177
|
-
@
|
178
|
+
@response = @user.send_sms_confirmation!
|
178
179
|
}
|
179
|
-
should "not work" do
|
180
|
+
should "not work" do
|
181
|
+
assert !@response.success?
|
182
|
+
end
|
180
183
|
should "not save confirmation number" do
|
181
184
|
assert @user._TC_sms_confirmation_code.blank?
|
182
185
|
end
|
@@ -192,11 +195,12 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
|
|
192
195
|
class TestController < ActionController::Base
|
193
196
|
include TwilioContactable::Controller
|
194
197
|
twilio_contactable User
|
195
|
-
self
|
196
198
|
end
|
197
|
-
@
|
199
|
+
@response = @user.send_voice_confirmation!
|
198
200
|
}
|
199
|
-
should "work" do
|
201
|
+
should "work" do
|
202
|
+
assert @response.success?
|
203
|
+
end
|
200
204
|
should "save confirmation number in proper attribute" do
|
201
205
|
assert @user._TC_voice_confirmation_code
|
202
206
|
end
|
@@ -210,7 +214,9 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
|
|
210
214
|
assert !@user.voice_confirmed?
|
211
215
|
end
|
212
216
|
context "calling voice_confirm_with(right_code)" do
|
213
|
-
setup {
|
217
|
+
setup {
|
218
|
+
@worked = @user.voice_confirm_with(@user._TC_voice_confirmation_code)
|
219
|
+
}
|
214
220
|
should "work" do
|
215
221
|
assert @worked
|
216
222
|
end
|
data/twilio_contactable.gemspec
CHANGED
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twilio_contactable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 49
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 8
|
8
|
-
-
|
9
|
-
version: 0.8.
|
9
|
+
- 7
|
10
|
+
version: 0.8.7
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Jack Danger Canty
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 5
|
28
30
|
segments:
|
29
31
|
- 2
|
30
32
|
- 0
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ">="
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
43
46
|
segments:
|
44
47
|
- 0
|
45
48
|
version: "0"
|
@@ -53,6 +56,7 @@ dependencies:
|
|
53
56
|
requirements:
|
54
57
|
- - ">="
|
55
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
56
60
|
segments:
|
57
61
|
- 0
|
58
62
|
version: "0"
|
@@ -98,6 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
102
|
requirements:
|
99
103
|
- - ">="
|
100
104
|
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
101
106
|
segments:
|
102
107
|
- 0
|
103
108
|
version: "0"
|
@@ -106,6 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
111
|
requirements:
|
107
112
|
- - ">="
|
108
113
|
- !ruby/object:Gem::Version
|
114
|
+
hash: 3
|
109
115
|
segments:
|
110
116
|
- 0
|
111
117
|
version: "0"
|