twilio_contactable 0.8.3 → 0.8.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.3
1
+ 0.8.4
data/lib/controller.rb CHANGED
@@ -42,29 +42,46 @@ module TwilioContactable
42
42
 
43
43
  def start_voice_confirmation
44
44
  render :xml => (Twilio::Response.new.tap do |response|
45
- response.addGather(
46
- :action => url_for(
47
- :action => 'receive_voice_confirmation',
48
- :contactable_type => params[:contactable_type],
49
- :contactable_id => params[:contactable_id]
50
- )
51
- ).tap do |gather|
52
- gather.addSay "Please type the numbers that appear on your screen, followed by the pound sign"
53
- end
45
+ gather(response)
54
46
  end.respond)
55
47
  end
56
48
 
57
49
  def receive_voice_confirmation
58
50
  @contactable = params[:contactable_type].constantize.find(params[:contactable_id])
59
- @contactable.voice_confirm_with(params['Digits'])
60
- render :xml => (Twilio::Response.new.tap do |response|
61
- response.addSay "Thank you, please return to the website and continue"
62
- response.addHangup
63
- end.respond)
51
+ if @contactable.voice_confirm_with(params['Digits'])
52
+ render :xml => (Twilio::Response.new.tap do |response|
53
+ response.addSay "Thank you, please return to the website and continue"
54
+ response.addHangup
55
+ end.respond)
56
+ else
57
+ render :xml => (Twilio::Response.new.tap do |response|
58
+ response.addSay "Sorry, those aren't the correct numbers."
59
+ gather(response)
60
+ end.respond)
61
+ end
64
62
  end
65
63
 
66
64
  protected
67
65
 
66
+ def gather(response)
67
+ tries = (params[:tries] ||= '0').succ!
68
+ if tries.to_i > 4
69
+ response.addSay "We're sorry, this doesn't seem to be working. Please contact technical support."
70
+ response.addHangup
71
+ else
72
+ response.addGather(
73
+ :action => url_for(
74
+ :action => 'receive_voice_confirmation',
75
+ :contactable_type => params[:contactable_type],
76
+ :contactable_id => params[:contactable_id],
77
+ :tries => tries
78
+ )
79
+ ).tap do |gather|
80
+ gather.addSay "Please type the numbers that appear on your screen, followed by the pound sign"
81
+ end
82
+ end
83
+ end
84
+
68
85
  def find_contactable_by_phone_number(number)
69
86
  [number, number.sub(/^\+/,''), number.sub(/^\+1/,'')].uniq.compact.each do |possible_phone_number|
70
87
  @@contactable_classes.each do |klass|
@@ -23,8 +23,8 @@ module TwilioContactable
23
23
  end
24
24
 
25
25
  def generate_confirmation_code
26
- chars = (0..9).to_a + ('A'..'Z').to_a
27
- (0...6).collect { chars[Kernel.rand(chars.length)] }.join
26
+ nums = (0..9).to_a
27
+ (0...4).collect { nums[Kernel.rand(nums.length)] }.join
28
28
  end
29
29
  end
30
30
  end
@@ -103,23 +103,6 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
103
103
  end
104
104
  end
105
105
  end
106
- context "calling sms_confirm_with(right code, wrong case)" do
107
- setup {
108
- @downcased_code = @user._TC_sms_confirmation_code.downcase
109
- @worked = @user.sms_confirm_with(@downcased_code)
110
- }
111
- should "have good test data" do
112
- assert_not_equal @downcased_code,
113
- @user._TC_sms_confirmation_code
114
- end
115
- should "work" do
116
- assert @worked
117
- end
118
- should "save the phone number into the confirmed attribute" do
119
- assert_equal @user._TC_sms_confirmed_phone_number,
120
- @user._TC_formatted_phone_number
121
- end
122
- end
123
106
  context "calling sms_confirm_with(wrong_code)" do
124
107
  setup { @worked = @user.sms_confirm_with('wrong_code') }
125
108
  should "not work" do
@@ -220,23 +203,6 @@ class TwilioContactableContactableTest < ActiveSupport::TestCase
220
203
  end
221
204
  end
222
205
  end
223
- context "calling voice_confirm_with(right code, wrong case)" do
224
- setup {
225
- @downcased_code = @user._TC_voice_confirmation_code.downcase
226
- @worked = @user.voice_confirm_with(@downcased_code)
227
- }
228
- should "have good test data" do
229
- assert_not_equal @downcased_code,
230
- @user._TC_voice_confirmation_code
231
- end
232
- should "work" do
233
- assert @worked
234
- end
235
- should "save the phone number into the confirmed attribute" do
236
- assert_equal @user._TC_voice_confirmed_phone_number,
237
- @user._TC_formatted_phone_number
238
- end
239
- end
240
206
  context "calling voice_confirm_with(wrong_code)" do
241
207
  setup { @worked = @user.voice_confirm_with('wrong_code') }
242
208
  should "not work" do
@@ -83,7 +83,7 @@ class TwilioContactableControllerTest < ActionController::TestCase
83
83
  assert_dom_equal %q{
84
84
  <response>
85
85
  <gather
86
- action="http://test.host/twilio_contactable/receive_voice_confirmation?contactable_id=1&amp;contactable_type=User"
86
+ action="http://test.host/twilio_contactable/receive_voice_confirmation?contactable_id=1&amp;contactable_type=User&amp;tries=1"
87
87
  >
88
88
  <say>
89
89
  Please type the numbers that appear on your screen, followed by the pound sign
@@ -39,8 +39,8 @@ class TwilioContactableModuleTest < ActiveSupport::TestCase
39
39
 
40
40
  context "generating codes" do
41
41
  setup { @code = TwilioContactable.generate_confirmation_code }
42
- should "be 6 digits" do
43
- assert_equal 6, @code.length
42
+ should "be 4 digits" do
43
+ assert_equal 4, @code.length
44
44
  end
45
45
  end
46
46
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twilio_contactable}
8
- s.version = "0.8.3"
8
+ s.version = "0.8.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jack Danger Canty"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twilio_contactable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 55
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 8
9
- - 3
10
- version: 0.8.3
9
+ - 4
10
+ version: 0.8.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jack Danger Canty