4info 1.2.1 → 1.2.2
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/4info.gemspec +1 -1
- data/README.markdown +12 -2
- data/VERSION +1 -1
- data/lib/contactable.rb +3 -1
- data/lib/four_info.rb +9 -1
- data/lib/request.rb +13 -9
- data/test/four_info_contactable_test.rb +7 -1
- data/test/test_helper.rb +7 -8
- metadata +1 -1
data/4info.gemspec
CHANGED
data/README.markdown
CHANGED
@@ -28,13 +28,22 @@ You can also specify which attributes you'd like to use instead of the defaults
|
|
28
28
|
# Defaults to the name on the left (minus the '_column' at the end)
|
29
29
|
end
|
30
30
|
|
31
|
+
Turning the thing on
|
32
|
+
---
|
33
|
+
|
34
|
+
Because it can be expensive to send TXTs accidentally it's required that you manually configure FourInfo in your app. Put this line in config/initializers/sms.rb or config/environment.rb or anything that loads when the app starts:
|
35
|
+
|
36
|
+
FourInfo.mode = :live
|
37
|
+
|
38
|
+
Skipping this step (or adding any other value) will prevent TXTs from actually being sent.
|
39
|
+
|
31
40
|
Phone number formatting
|
32
41
|
---
|
33
42
|
|
34
43
|
Whatever is stored in the sms_phone_number_column will be subject to normalized formatting:
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
user = User.create :sms_phone_number => '(206) 555-1234'
|
46
|
+
user.sms_phone_number # => 2065551234
|
38
47
|
|
39
48
|
If you want to preserve the format of the number exactly as the user entered it you'll want
|
40
49
|
to save it in a different attribute.
|
@@ -47,6 +56,7 @@ You can manage the user's SMS state like so:
|
|
47
56
|
|
48
57
|
@user = User.create(:sms_phone_number => '5552223333')
|
49
58
|
@user.send_sms_confirmation!
|
59
|
+
@user.sms_confirmed? # => false
|
50
60
|
|
51
61
|
then ask the user for the confirmation code off their phone and pass it in to sms_confirm_with:
|
52
62
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.2
|
data/lib/contactable.rb
CHANGED
@@ -99,7 +99,7 @@ module FourInfo
|
|
99
99
|
response = FourInfo::Request.new.unblock(four_info_sms_phone_number)
|
100
100
|
if response.success?
|
101
101
|
self.four_info_sms_blocked = 'false'
|
102
|
-
save
|
102
|
+
save
|
103
103
|
else
|
104
104
|
false
|
105
105
|
end
|
@@ -113,6 +113,8 @@ module FourInfo
|
|
113
113
|
# save the phone number into the 'confirmed phone number' attribute
|
114
114
|
self.four_info_sms_confirmed_phone_number = four_info_sms_phone_number
|
115
115
|
save
|
116
|
+
else
|
117
|
+
false
|
116
118
|
end
|
117
119
|
end
|
118
120
|
|
data/lib/four_info.rb
CHANGED
@@ -3,12 +3,20 @@ module FourInfo
|
|
3
3
|
|
4
4
|
class << self
|
5
5
|
def mode
|
6
|
-
@@mode ||= :
|
6
|
+
@@mode ||= :test
|
7
7
|
end
|
8
8
|
def mode=(new_mode)
|
9
9
|
@@mode = new_mode
|
10
10
|
end
|
11
11
|
|
12
|
+
def log(msg)
|
13
|
+
if defined?(Rails)
|
14
|
+
Rails.logger.info msg
|
15
|
+
else
|
16
|
+
STDOUT.puts msg
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
12
20
|
def numerize(numberish)
|
13
21
|
numberish.to_s.scan(/\d+/).join
|
14
22
|
end
|
data/lib/request.rb
CHANGED
@@ -18,9 +18,9 @@ module FourInfo
|
|
18
18
|
attr_accessor :message
|
19
19
|
|
20
20
|
def initialize
|
21
|
-
config_file = :
|
22
|
-
@@
|
23
|
-
@@
|
21
|
+
config_file = :live == FourInfo.mode.to_sym ?
|
22
|
+
@@likely_config_files.detect {|f| File.exist?(f) } :
|
23
|
+
@@test_mode_config_file
|
24
24
|
|
25
25
|
raise "Missing config File! Please add sms.yml to ./config or the 4info directory" unless config_file
|
26
26
|
|
@@ -58,12 +58,16 @@ module FourInfo
|
|
58
58
|
end
|
59
59
|
|
60
60
|
def perform(body)
|
61
|
-
|
62
|
-
http
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
61
|
+
if :live == FourInfo.mode
|
62
|
+
start do |http|
|
63
|
+
http.post(
|
64
|
+
FourInfo::Gateway.path,
|
65
|
+
body,
|
66
|
+
{'Content-Type' => 'text/xml'}
|
67
|
+
).read_body
|
68
|
+
end
|
69
|
+
else
|
70
|
+
FourInfo.log "Would have sent to 4info.net: #{body}"
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
@@ -102,6 +102,9 @@ class FourInfoContactableTest < ActiveSupport::TestCase
|
|
102
102
|
end
|
103
103
|
context "calling sms_confirm_with(right_code)" do
|
104
104
|
setup { @user.sms_confirm_with(@user.four_info_sms_confirmation_code) }
|
105
|
+
should "work" do
|
106
|
+
assert @worked
|
107
|
+
end
|
105
108
|
should "save the phone number into the confirmed attribute" do
|
106
109
|
assert_equal @user.four_info_sms_confirmed_phone_number,
|
107
110
|
@user.four_info_sms_phone_number
|
@@ -111,7 +114,10 @@ class FourInfoContactableTest < ActiveSupport::TestCase
|
|
111
114
|
end
|
112
115
|
end
|
113
116
|
context "calling sms_confirm_with(wrong_code)" do
|
114
|
-
setup { @user.sms_confirm_with('wrong_code') }
|
117
|
+
setup { @worked = @user.sms_confirm_with('wrong_code') }
|
118
|
+
should "not work" do
|
119
|
+
assert !@worked
|
120
|
+
end
|
115
121
|
should "not save the phone number into the confirmed attribute" do
|
116
122
|
assert_not_equal @user.four_info_sms_confirmed_phone_number,
|
117
123
|
@user.four_info_sms_phone_number
|
data/test/test_helper.rb
CHANGED
@@ -30,11 +30,10 @@ class User < ActiveRecord::Base
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# kill all network access
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
# end
|
33
|
+
module FourInfo
|
34
|
+
class Request
|
35
|
+
def start
|
36
|
+
raise "You forgot to stub out your net requests!"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|