twilio_contactable 0.7.5 → 0.7.6

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/README.markdown CHANGED
@@ -1,19 +1,31 @@
1
- Twilo Contactable
1
+ Twilio Contactable
2
2
  =====
3
3
 
4
- Twilo makes voice and SMS interactions easy. But if you want to be able to seamlessly validate your user's phone numbers for
4
+ Twilio makes voice and SMS interactions easy. But if you want to be able to seamlessly validate your user's phone numbers for
5
5
  both voice and text there's a lot of work you'll have to do in your Rails app. Unless you use this gem.
6
6
 
7
- Why bother?
8
- =====
7
+ Don't Write Twilio Ruby Code Like It's PHP
8
+ ==
9
9
 
10
- Unless you're programming Ruby like it's PHP you don't enjoy passing strings around and writing all procedural code. This gem lets you
11
- ask for a phone number from your users, confirm their ownership of it via SMS or Voice or both, and keep track of whether the number is
12
- still validated when they edit it.
10
+ You don't want to be passing strings around and writing procedural code in your Ruby app. This gem lets you ask for a phone number from your users (or any ActiveRecord model), confirm their ownership of it via SMS or Voice or both, and keep track of whether the number is still validated whenever the number is edited.
13
11
 
14
12
 
15
- Setting Up Your Model
16
- =====
13
+ Install It
14
+ ==
15
+
16
+ Install TwilioContactable as a gem:
17
+
18
+ gem install twilio_contactable
19
+ # then add this gem to your project in .gems or in environment.rb
20
+
21
+ Or as a Plugin:
22
+
23
+ ruby script/plugin install git://github.com/JackDanger/twilio_contactable.git
24
+
25
+
26
+ Connect This Code To Your App
27
+ ==
28
+
17
29
 
18
30
  Include Twilio::Contactable into your User class or whatever you're using to represent an entity with a phone number.
19
31
 
@@ -21,20 +33,20 @@ Include Twilio::Contactable into your User class or whatever you're using to rep
21
33
  twilio_contactable
22
34
  end
23
35
 
24
- You can also specify which attributes you'd like to use instead of the defaults
36
+ If you're using custom column names you can easily overwrite any of them:
25
37
 
26
38
  class User < ActiveRecord::Base
27
39
  twilio_contactable do |config|
28
- config.phone_number_column :mobile_number
29
- config.formatted_phone_number_column :formatted_mobile_number
30
- config.sms_blocked_column :should_we_not_txt_this_user
31
- config.sms_confirmation_code_column :the_sms_confirmation_code
32
- config.sms_confirmation_attempted_column :when_was_the_sms_confirmation_attempted
33
- config.sms_confirmed_phone_number_column :the_mobile_number_thats_been_confirmed_for_sms
34
- config.voice_blocked_column :should_we_not_call_this_user
35
- config.voice_confirmation_code_column :the_voice_confirmation_code
36
- config.voice_confirmation_attempted_column :when_was_the_voice_confirmation_attempted
37
- config.voice_confirmed_phone_number_column :the_mobile_number_thats_been_confirmed_for_voice
40
+ config.phone_number_column = :mobile_number
41
+ config.formatted_phone_number_column = :formatted_mobile_number
42
+ config.sms_blocked_column = :should_we_not_txt_this_user
43
+ config.sms_confirmation_code_column = :the_sms_confirmation_code
44
+ config.sms_confirmation_attempted_column = :when_was_the_sms_confirmation_attempted
45
+ config.sms_confirmed_phone_number_column = :the_mobile_number_thats_been_confirmed_for_sms
46
+ config.voice_blocked_column = :should_we_not_call_this_user
47
+ config.voice_confirmation_code_column = :the_voice_confirmation_code
48
+ config.voice_confirmation_attempted_column = :when_was_the_voice_confirmation_attempted
49
+ config.voice_confirmed_phone_number_column = :the_mobile_number_thats_been_confirmed_for_voice
38
50
 
39
51
  # Defaults to the name on the left (minus the '_column' at the end)
40
52
  # e.g., the sms_blocked_column is 'sms_blocked'
@@ -42,47 +54,84 @@ You can also specify which attributes you'd like to use instead of the defaults
42
54
  # You don't need all those columns, omit any that you're sure you won't want.
43
55
  end
44
56
 
45
- Turning the thing on
46
- ---
47
57
 
48
- Because it can be expensive to send TXTs or make calls accidentally, it's required that you manually configure TwilioContactable in your app. Put this line in config/environments/production.rb or anything that loads _only_ in your production environment:
58
+ You'll need to add those columns to your database table using a migration that looks something like this:
49
59
 
50
- TwilioContactable.mode = :live
60
+ change_table :users do |t|
61
+ t.string :phone_number
62
+ t.string :formatted_phone_number
63
+ t.boolean :sms_blocked, :default => false, :null => false
64
+ t.string :sms_confirmation_code
65
+ t.datetime :sms_confirmation_attempted
66
+ t.string :sms_confirmed_phone_number
67
+ t.boolean :voice_blocked, :default => false, :null => false
68
+ t.string :voice_confirmation_code
69
+ t.datetime :voice_confirmation_attempted
70
+ t.string :voice_confirmed_phone_number
71
+ end
51
72
 
52
- Skipping this step (or adding any other value) will prevent TXTs from actually being sent.
73
+ You don't necessarily need all those columns though. Say you have users that are notified by SMS but business locations that
74
+ just need to have their retail phone number validated:
53
75
 
54
- You'll also want to configure your setup with your client_id and client_key. Put this in the same file as above or in a separate initializer if you wish:
76
+ change_table :users do |t|
77
+ t.string :phone_number
78
+ t.string :formatted_phone_number
79
+ t.boolean :sms_blocked, :default => false, :null => false
80
+ t.string :sms_confirmation_code
81
+ t.datetime :sms_confirmation_attempted
82
+ t.string :sms_confirmed_phone_number
83
+ end
84
+ change_table :business_locations do |t|
85
+ t.string :phone_number
86
+ t.string :formatted_phone_number
87
+ t.boolean :voice_blocked, :default => false, :null => false
88
+ t.string :voice_confirmation_code
89
+ t.datetime :voice_confirmation_attempted
90
+ t.string :voice_confirmed_phone_number
91
+ end
55
92
 
56
- TwilioContactable.configure do |config|
57
- # these three are required:
58
- # (replace them with your actual account info)
59
- config.client_id = 12345
60
- config.client_key = 'ABC123'
61
- config.website_address = 'http://myrubyapp.com' # <- Twilio.com needs to be able to find this
62
-
63
- # the rest are optional:
64
- config.short_code = 00001 # if you have a custom short code
65
- config.proxy_address = 'my.proxy.com'
66
- config.proxy_port = '80'
67
- config.proxy_username = 'user'
68
- config.proxy_password = 'password'
93
+ Both the User and the BusinessLocation models are now prepared for SMS and Voice confirmation, respectively.
94
+
95
+ You'll also need to create a controller that is capable of receiving connections from Twilio.com:
96
+
97
+ # app/controllers/twilio_contactable_controller.rb
98
+ class TwilioContactableController < ActionController::Base
99
+ include TwilioContactable::Controller
100
+
101
+ # any models that you want to have phone numbers confirmed for:
102
+ twilio_contactable User, BusinessLocation
69
103
  end
70
104
 
71
- Phone number formatting
72
- ---
73
105
 
74
- Whatever is stored in the phone_number_column will be subject to normalized formatting:
106
+ Configure It With Twilio Account Info
107
+ ==
75
108
 
76
- user = User.create :phone_number => '(206) 555-1234'
77
- user.phone_number # => (206) 555-1234
78
- user.formatted_phone_number # => 12065551234 (defaults to US country code)
109
+ Because it can be expensive to send TXTs or make calls accidentally, it's required that you manually configure TwilioContactable in your app. Put this line in config/environments/production.rb or anything that loads _only_ in your production environment:
79
110
 
80
- If you want to preserve the format of the number exactly as the user entered it you'll want
81
- to save that in a different attribute.
111
+ TwilioContactable.mode = :live
82
112
 
113
+ Skipping this step (or adding any other value) will prevent TXTs or phone calls from actually being sent.
83
114
 
84
- Confirming Phone Number And Sending Messages
85
- ====
115
+ You'll need to add a few pieces of important information. Create a file like the following in config/initializers/
116
+
117
+ # config/initializers/twilio_contactable.rb
118
+ TwilioContactable.configure do |config|
119
+
120
+ # Your Twilio Account Number
121
+ config.client_id = 12345
122
+ # Your Twilio Account Secret Code
123
+ config.client_key = 'ABC123'
124
+ # Twilio.com needs to be able to find your site. Add your
125
+ # complete Ruby app internet address here:
126
+ config.website_address = 'http://myrubyapp.com'
127
+ # And, finally, the Twilio-hosted phone number
128
+ # that you'd like all your calls/txts to come from:
129
+ config.default_from_phone_number = '(206) 555-1234'
130
+
131
+ end
132
+
133
+ Confirming Phone Number For SMS And Sending TXTs
134
+ ==
86
135
 
87
136
  When your users first hand you their number it will be unconfirmed:
88
137
 
@@ -90,11 +139,12 @@ When your users first hand you their number it will be unconfirmed:
90
139
  @user.send_sms_confirmation! # fires off a TXT to the user with a generated confirmation code
91
140
  @user.sms_confirmed? # => false, because we've only started the process
92
141
 
93
- then ask the user for the confirmation code off their phone and pass it in to sms_confirm_with:
142
+ The user will read the SMS confirmation code off of their phone and type it into a form on your site (you'll need to build this). When they submit that code to a controller you should pass it in to the user record's sms_confirm_with method:
94
143
 
95
- @user.sms_confirm_with('123XYZ')
144
+ # params[:code] => '123XYZ'
145
+ @user.sms_confirm_with(params[:code])
96
146
 
97
- If the code is right then the user's current phone number will be automatically marked as confirmed. You can check this at any time with:
147
+ If the code is correct then the user's current phone number will be automatically marked as confirmed. You can check this at any time with:
98
148
 
99
149
  @user.sms_confirmed? # => true
100
150
  @user.send_sms!("Hi! This is a text message.")
@@ -105,6 +155,27 @@ If the code is wrong then the user's current phone number will stay unconfirmed.
105
155
  @user.send_sms!("Hi! This is a text message.") # sends nothing
106
156
 
107
157
 
158
+ Confirming Phone Number For Voice
159
+ ==
160
+
161
+ Confirming for Voice is different from confirming for SMS because the user will read the code off your site and enter their Voice confirmation code into the keypad of their phone.
162
+
163
+ @user = User.create(:phone_number => '555-222-3333')
164
+ @user.send_voice_confirmation! # Initiates phone call to user
165
+ @user.voice_confirmed? # false
166
+
167
+ Right after send_voice_confirmation! is called you'll want to display the confirmation code to the user. It's up to you how to do this but you'll probably want to have a screen that shows something like this:
168
+
169
+ <h1>We're calling you on the phone right now!</h1>
170
+ <p>
171
+ When you answer the phone, please type in these numbers:
172
+ <%= @user.voice_confirmation_code %>
173
+ <p>
174
+ <%= link_to "Okay, I've finished the phone call", '/' %>
175
+
176
+ While you display this screen the user will have inputted their voice_confirmation_code to their phone, Twilio.com will have posted that code to your server (defined in config.website_address), and your user will have been updated so that @user.voice_confirmed? is now true!
177
+ If the code is entered incorrectly then the user's current phone number will stay unconfirmed. You'll need to start over and have them enter the code again.
178
+
108
179
  Receiving TXTs and Voice calls
109
180
  ====
110
181
 
@@ -112,30 +183,25 @@ You can also receive data posted to you from Twilio. This is how you'll receive
112
183
  All you need is to create a bare controller and include TwilioContactable::Controller into it. Then specify which Ruby class you're using as a contactable user model (likely User)
113
184
 
114
185
 
115
- class SMSController < ApplicationController
116
- include TwilioContactable::Controller
186
+ class TwilioContactableController < ApplicationController
117
187
 
118
- sms_contactable User # or whichever class you included TwilioContactable::Contactable into
119
- end
120
-
121
- And hook this up in your routes.rb file like so:
188
+ include TwilioContactable::Controller
122
189
 
123
- ActionController::Routing::Routes.draw do |map|
124
- map.route 'twilio', :controller => 'twilio_contactable', :action => :index
190
+ twilio_contactable User # or whichever class you included TwilioContactable::Contactable into
125
191
  end
126
192
 
127
- Now just tell Twilio to POST messages and block notices to you at:
193
+ Make sure Twilio.com knows to POST all SMS messages and block notices to you at:
128
194
 
129
- http://myrubyapp.com/twilio
195
+ http://myrubyapp.com/twilio_contactable/receive_sms_message
130
196
 
131
- Now if your users reply to an SMS with 'STOP' or 'BLOCK' your database will be automatically updated to reflect this.
197
+ This gem will handle all those incoming messages automatically. Now if your users reply to an SMS with 'STOP' or 'BLOCK' the appropriate record in your database will be updated so that sms messages no longer can be sent to them (i.e.: @user.sms_blocked? will be true)
132
198
 
133
- Incoming messages from a user will automatically be sent to that user's record:
199
+ All other incoming TXTs (besides 'BLOCK' and 'STOP') from a user will automatically be sent to that user's record:
134
200
 
135
201
  # If "I love you!" is sent to you from a user with
136
202
  # the phone number "555-111-9999"
137
203
  # then the following will be executed:
138
- User.find_by_phone_number('5551119999').receive_sms("I love you!")
204
+ User.find_by_formatted_phone_number('+15551119999').receive_sms("I love you!")
139
205
 
140
206
  It's up to you to implement the 'receive_sms' method on User.
141
207
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.7.5
1
+ 0.7.6
data/lib/configuration.rb CHANGED
@@ -26,13 +26,8 @@ module TwilioContactable
26
26
 
27
27
  attr_accessor :client_id
28
28
  attr_accessor :client_key
29
- attr_accessor :short_code
30
29
  attr_accessor :website_address
31
30
  attr_accessor :default_from_phone_number
32
- attr_accessor :proxy_address
33
- attr_accessor :proxy_port
34
- attr_accessor :proxy_username
35
- attr_accessor :proxy_password
36
31
 
37
32
  def initialize
38
33
  yield self
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{twilio_contactable}
8
- s.version = "0.7.5"
8
+ s.version = "0.7.6"
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"]
12
- s.date = %q{2010-09-01}
12
+ s.date = %q{2010-09-02}
13
13
  s.description = %q{Does all the hard work with letting you confirm your user's phone numbers for Voice or TXT over the Twilio API}
14
14
  s.email = %q{gitcommit@6brand.com}
15
15
  s.extra_rdoc_files = [
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: 9
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 5
10
- version: 0.7.5
9
+ - 6
10
+ version: 0.7.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jack Danger Canty
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-01 00:00:00 -07:00
18
+ date: 2010-09-02 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency