4info 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/4info.gemspec +1 -1
- data/README.markdown +2 -2
- data/VERSION +1 -1
- data/lib/contactable.rb +14 -7
- data/lib/response.rb +1 -1
- data/test/four_info_contactable_test.rb +7 -4
- data/test/test_helper.rb +1 -1
- metadata +1 -1
data/4info.gemspec
CHANGED
data/README.markdown
CHANGED
@@ -23,7 +23,7 @@ You can also specify which attributes you'd like to use instead of the defaults
|
|
23
23
|
sms_blocked_column :is_sms_blocked
|
24
24
|
sms_confirmation_code_column :the_sms_confirmation_code
|
25
25
|
sms_confirmation_attempted_column :when_was_the_sms_confirmation_attempted
|
26
|
-
|
26
|
+
sms_confirmed_phone_number_column :the_mobile_number_thats_been_confirmed
|
27
27
|
|
28
28
|
# Defaults to the name on the left (minus the word '_column')
|
29
29
|
end
|
@@ -34,7 +34,7 @@ You can manage the user's SMS state like so:
|
|
34
34
|
@user.confirm_sms!
|
35
35
|
# then ask the user for the confirmation code and
|
36
36
|
# compare it to @user.sms_confirmation_code
|
37
|
-
@user.update_attributes(:
|
37
|
+
@user.update_attributes(:sms_confirmed_phone_number => @user.sms_phone_number)
|
38
38
|
@user.send_sms!("Hi! This is a text message.")
|
39
39
|
# Then maybe the user will reply with 'BLOCK' by accident
|
40
40
|
@user.unblock_sms!
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0
|
1
|
+
1.1.0
|
data/lib/contactable.rb
CHANGED
@@ -5,7 +5,7 @@ module FourInfo
|
|
5
5
|
:sms_blocked,
|
6
6
|
:sms_confirmation_code,
|
7
7
|
:sms_confirmation_attempted,
|
8
|
-
:
|
8
|
+
:sms_confirmed_phone_number ]
|
9
9
|
|
10
10
|
def self.included(model)
|
11
11
|
gem 'haml'
|
@@ -27,8 +27,8 @@ module FourInfo
|
|
27
27
|
# provide a helper method to access the right value
|
28
28
|
# no matter which column it's stored in
|
29
29
|
#
|
30
|
-
# e.g.: @user.
|
31
|
-
#
|
30
|
+
# e.g.: @user.four_info_sms_confirmation_code
|
31
|
+
# == @user.send(User.sms_confirmation_code_column)
|
32
32
|
model.class_eval "
|
33
33
|
def four_info_#{attribute}(value = nil)
|
34
34
|
value ?
|
@@ -41,12 +41,19 @@ module FourInfo
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
def current_phone_number_confirmed_for_sms?
|
45
|
+
return false if four_info_sms_confirmed_phone_number.blank?
|
46
|
+
four_info_sms_confirmed_phone_number == four_info_sms_phone_number
|
47
|
+
end
|
48
|
+
|
44
49
|
def send_sms!(msg, allow_multiple = false)
|
45
50
|
if msg.to_s.size > 160 && !allow_multiple
|
46
51
|
raise ArgumentError, "SMS Message is too long. Either specify that you want multiple messages or shorten the string."
|
47
52
|
end
|
48
|
-
return false if msg.to_s.strip.blank? || four_info_sms_blocked?
|
53
|
+
return false if msg.to_s.strip.blank? || four_info_sms_blocked?
|
54
|
+
return false unless current_phone_number_confirmed_for_sms?
|
49
55
|
|
56
|
+
# split into pieces that fit as individual messages.
|
50
57
|
msg.to_s.scan(/.{1,160}/m).map do |text|
|
51
58
|
FourInfo::Request.new.deliver_message(text, four_info_sms_phone_number).success?
|
52
59
|
end
|
@@ -54,13 +61,13 @@ module FourInfo
|
|
54
61
|
|
55
62
|
def confirm_sms!
|
56
63
|
return false if four_info_sms_blocked?
|
57
|
-
return true if
|
64
|
+
return true if current_phone_number_confirmed_for_sms?
|
58
65
|
return false if four_info_sms_phone_number.blank?
|
59
66
|
|
60
67
|
response = FourInfo::Request.new.confirm(four_info_sms_phone_number)
|
61
68
|
if response.success?
|
62
|
-
self.four_info_sms_confirmation_code
|
63
|
-
self.four_info_sms_confirmation_attempted
|
69
|
+
self.four_info_sms_confirmation_code response.confirmation_code
|
70
|
+
self.four_info_sms_confirmation_attempted Time.now
|
64
71
|
save
|
65
72
|
else
|
66
73
|
# "Confirmation Failed: #{response['message'].inspect}"
|
data/lib/response.rb
CHANGED
@@ -86,13 +86,16 @@ class FourInfoContactableTest < ActiveSupport::TestCase
|
|
86
86
|
}
|
87
87
|
should "work" do assert @worked end
|
88
88
|
should "save confirmation number in proper attribute" do
|
89
|
-
|
89
|
+
assert_equal '123abc', @user.four_info_sms_confirmation_code
|
90
|
+
end
|
91
|
+
should "set confirmation attempted time" do
|
92
|
+
assert @user.four_info_sms_confirmation_attempted > 3.minutes.ago
|
90
93
|
end
|
91
94
|
should_change "stored code" do
|
92
95
|
@user.four_info_sms_confirmation_code
|
93
96
|
end
|
94
|
-
should "not
|
95
|
-
assert !@user.
|
97
|
+
should "not have number confirmed yet" do
|
98
|
+
assert !@user.current_phone_number_confirmed_for_sms?
|
96
99
|
end
|
97
100
|
end
|
98
101
|
context "confirming phone number when the confirmation fails for some reason" do
|
@@ -136,7 +139,7 @@ class FourInfoContactableTest < ActiveSupport::TestCase
|
|
136
139
|
context "when the number is confirmed" do
|
137
140
|
setup {
|
138
141
|
FourInfo::Request.any_instance.stubs(:perform).returns(SendMsgSuccess)
|
139
|
-
@user.
|
142
|
+
@user.stubs(:current_phone_number_confirmed_for_sms?).returns(true)
|
140
143
|
}
|
141
144
|
context "sending a message" do
|
142
145
|
setup { @result = @user.send_sms!('message') }
|
data/test/test_helper.rb
CHANGED
@@ -16,7 +16,7 @@ ActiveRecord::Base.establish_connection(config[ENV['DB'] || 'sqlite3'])
|
|
16
16
|
ActiveRecord::Schema.define(:version => 1) do
|
17
17
|
create_table :users do |t|
|
18
18
|
t.column :sms_phone_number, :string
|
19
|
-
t.column :
|
19
|
+
t.column :sms_confirmed_phone_number, :string
|
20
20
|
t.column :sms_blocked, :boolean
|
21
21
|
t.column :sms_confirmation_attempted, :datetime
|
22
22
|
t.column :sms_confirmation_code, :string
|