txter 2.0.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/MIT-LICENSE +20 -0
- data/README.markdown +125 -0
- data/Rakefile +56 -0
- data/VERSION +1 -0
- data/init.rb +3 -0
- data/lib/4info_templates/confirm.haml +6 -0
- data/lib/4info_templates/deliver.haml +11 -0
- data/lib/4info_templates/unblock.haml +6 -0
- data/lib/configuration.rb +41 -0
- data/lib/contactable.rb +150 -0
- data/lib/controller.rb +62 -0
- data/lib/gateway.rb +45 -0
- data/lib/gateway_4info.rb +114 -0
- data/lib/gateway_twilio.rb +45 -0
- data/lib/txter.rb +50 -0
- data/test/.gitignore +1 -0
- data/test/database.yml +18 -0
- data/test/gateway_4info_test.rb +75 -0
- data/test/gateway_twilio_test.rb +15 -0
- data/test/test_helper.rb +46 -0
- data/test/txter_contactable_test.rb +270 -0
- data/test/txter_controller_test.rb +76 -0
- data/test/txter_module_test.rb +56 -0
- data/txter.gemspec +74 -0
- metadata +102 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
|
+
require 'action_pack'
|
|
3
|
+
require 'action_controller'
|
|
4
|
+
require 'shoulda/action_controller'
|
|
5
|
+
require 'shoulda/action_controller/macros'
|
|
6
|
+
require 'shoulda/action_controller/matchers'
|
|
7
|
+
|
|
8
|
+
class TxterController < ActionController::Base
|
|
9
|
+
include Txter::Controller
|
|
10
|
+
|
|
11
|
+
sms_contactable User
|
|
12
|
+
end
|
|
13
|
+
ActionController::Routing::Routes.draw do |map|
|
|
14
|
+
map.route '*:url', :controller => 'txter', :action => :index
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class UserWithSMSReceiving < User
|
|
18
|
+
def receive_sms(message)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class TxterControllerTest < ActionController::TestCase
|
|
23
|
+
|
|
24
|
+
context "with a user" do
|
|
25
|
+
setup {
|
|
26
|
+
User.delete_all
|
|
27
|
+
@user = User.create! :sms_phone_number => '(206) 335-1596'
|
|
28
|
+
# and we should be able to find @user by this formatted version
|
|
29
|
+
@formatted_phone_number = "2063351596"
|
|
30
|
+
}
|
|
31
|
+
context "receiving BLOCK" do
|
|
32
|
+
setup {
|
|
33
|
+
post :index,
|
|
34
|
+
# this is what an xml request will parse to:
|
|
35
|
+
"request"=>{"block"=>{"recipient"=>{"property"=>{"name"=>"CARRIER", "value"=>"3"}, "id"=>"+1#{@formatted_phone_number}", "type"=>"5"}}, "type" => "BLOCK"}
|
|
36
|
+
}
|
|
37
|
+
should_respond_with :success
|
|
38
|
+
should "block user" do
|
|
39
|
+
assert @user.reload.txter_sms_blocked?
|
|
40
|
+
end
|
|
41
|
+
should_change "user block status" do
|
|
42
|
+
@user.reload.txter_sms_blocked?
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
context "receiving MESSAGE" do
|
|
46
|
+
setup {
|
|
47
|
+
# this is what an xml request will parse to:
|
|
48
|
+
@receive_params = {"request"=>{"message"=>{"id" => "ABCDEFG", "recipient"=>{"type"=> "6", "id"=>"12345"}, "sender" => {"type" => "5", "id" => "+1#{@formatted_phone_number}", "property" => {"name" => "CARRIER", "value" => "5"}}, "text" => "This is a text message."}, "type" => "MESSAGE"}}
|
|
49
|
+
}
|
|
50
|
+
context "when the user is not set up to receive" do
|
|
51
|
+
setup {
|
|
52
|
+
@user.expects(:receive_sms).with("This is a text message.").never
|
|
53
|
+
post :index,
|
|
54
|
+
@receive_params
|
|
55
|
+
}
|
|
56
|
+
should_respond_with :success
|
|
57
|
+
should "not block user" do
|
|
58
|
+
assert !@user.reload.txter_sms_blocked?
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
context "when the user is set up to receive" do
|
|
62
|
+
setup {
|
|
63
|
+
User.delete_all
|
|
64
|
+
@new_user = UserWithSMSReceiving.create!(:sms_phone_number => @user.sms_phone_number)
|
|
65
|
+
UserWithSMSReceiving.any_instance.expects(:receive_sms).with("This is a text message.").once
|
|
66
|
+
post :index,
|
|
67
|
+
@receive_params
|
|
68
|
+
}
|
|
69
|
+
should_respond_with :success
|
|
70
|
+
should "not block user" do
|
|
71
|
+
assert !@new_user.reload.txter_sms_blocked?
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
|
2
|
+
|
|
3
|
+
class TxterModuleTest < ActiveSupport::TestCase
|
|
4
|
+
|
|
5
|
+
context "standardizing numbers" do
|
|
6
|
+
context "to digits" do
|
|
7
|
+
should "remove all but integers" do
|
|
8
|
+
assert_equal '12345', Txter.numerize('1-2-3-4-5')
|
|
9
|
+
assert_equal '12345', Txter.numerize('1 2 3 4 5')
|
|
10
|
+
assert_equal '12345', Txter.numerize('1,2(3)4.5')
|
|
11
|
+
assert_equal '12345', Txter.numerize('1,2(3)4.5')
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
context "to international format" do
|
|
15
|
+
should "add a '+' to all 11 digit numbers" do
|
|
16
|
+
assert_equal '+12345678901', Txter.internationalize('12345678901')
|
|
17
|
+
assert_equal '+72345678901', Txter.internationalize('72345678901')
|
|
18
|
+
end
|
|
19
|
+
should "add a '+1' to any 10 digit number" do
|
|
20
|
+
assert_equal '+12345678901', Txter.internationalize('2345678901')
|
|
21
|
+
assert_equal '+17345678901', Txter.internationalize('7345678901')
|
|
22
|
+
end
|
|
23
|
+
should "leave 12 digit numbers unchanged" do
|
|
24
|
+
[ '+' + ('3'*11),
|
|
25
|
+
'+' + ('8'*11),
|
|
26
|
+
'+' + ('4'*11) ].each do |number|
|
|
27
|
+
assert_equal number, Txter.internationalize(number)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
should "return nil for all bad numbers" do
|
|
31
|
+
assert_equal nil, Txter.internationalize(nil)
|
|
32
|
+
assert_equal nil, Txter.internationalize('nil')
|
|
33
|
+
assert_equal nil, Txter.internationalize('1234')
|
|
34
|
+
assert_equal nil, Txter.internationalize('11111111111111111111111')
|
|
35
|
+
assert_equal nil, Txter.internationalize('what?')
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "generating codes" do
|
|
41
|
+
setup { @code = Txter.generate_confirmation_code }
|
|
42
|
+
should "be 6 digits" do
|
|
43
|
+
assert_equal 6, @code.length
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "confirmation message" do
|
|
48
|
+
setup {
|
|
49
|
+
@code = 'ABC123'
|
|
50
|
+
@message = Txter.confirmation_message(@code)
|
|
51
|
+
}
|
|
52
|
+
should "include code" do
|
|
53
|
+
assert @message.include?(@code)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
data/txter.gemspec
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Generated by jeweler
|
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
|
4
|
+
# -*- encoding: utf-8 -*-
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |s|
|
|
7
|
+
s.name = %q{txter}
|
|
8
|
+
s.version = "2.0.2"
|
|
9
|
+
|
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
|
+
s.authors = ["Jack Danger Canty"]
|
|
12
|
+
s.date = %q{2010-03-17}
|
|
13
|
+
s.description = %q{Drop-in functionality to let Ruby apps send and receive TXT messages}
|
|
14
|
+
s.email = %q{gitcommit@6brand.com}
|
|
15
|
+
s.extra_rdoc_files = [
|
|
16
|
+
"README.markdown"
|
|
17
|
+
]
|
|
18
|
+
s.files = [
|
|
19
|
+
"MIT-LICENSE",
|
|
20
|
+
"README.markdown",
|
|
21
|
+
"Rakefile",
|
|
22
|
+
"VERSION",
|
|
23
|
+
"init.rb",
|
|
24
|
+
"lib/4info_templates/confirm.haml",
|
|
25
|
+
"lib/4info_templates/deliver.haml",
|
|
26
|
+
"lib/4info_templates/unblock.haml",
|
|
27
|
+
"lib/configuration.rb",
|
|
28
|
+
"lib/contactable.rb",
|
|
29
|
+
"lib/controller.rb",
|
|
30
|
+
"lib/gateway.rb",
|
|
31
|
+
"lib/gateway_4info.rb",
|
|
32
|
+
"lib/gateway_twilio.rb",
|
|
33
|
+
"lib/txter.rb",
|
|
34
|
+
"test/.gitignore",
|
|
35
|
+
"test/database.yml",
|
|
36
|
+
"test/gateway_4info_test.rb",
|
|
37
|
+
"test/gateway_twilio_test.rb",
|
|
38
|
+
"test/test_helper.rb",
|
|
39
|
+
"test/txter_contactable_test.rb",
|
|
40
|
+
"test/txter_controller_test.rb",
|
|
41
|
+
"test/txter_module_test.rb",
|
|
42
|
+
"txter.gemspec"
|
|
43
|
+
]
|
|
44
|
+
s.homepage = %q{http://github.com/JackDanger/txter}
|
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
|
46
|
+
s.require_paths = ["lib"]
|
|
47
|
+
s.rubygems_version = %q{1.3.5}
|
|
48
|
+
s.summary = %q{Send and receive SMS messages simply via the Twilio gateway or the 4info.com gateway}
|
|
49
|
+
s.test_files = [
|
|
50
|
+
"test/gateway_4info_test.rb",
|
|
51
|
+
"test/gateway_twilio_test.rb",
|
|
52
|
+
"test/test_helper.rb",
|
|
53
|
+
"test/txter_contactable_test.rb",
|
|
54
|
+
"test/txter_controller_test.rb",
|
|
55
|
+
"test/txter_module_test.rb"
|
|
56
|
+
]
|
|
57
|
+
|
|
58
|
+
if s.respond_to? :specification_version then
|
|
59
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
|
60
|
+
s.specification_version = 3
|
|
61
|
+
|
|
62
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
|
63
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
|
64
|
+
s.add_development_dependency(%q<mocha>, [">= 0"])
|
|
65
|
+
else
|
|
66
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
67
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
|
68
|
+
end
|
|
69
|
+
else
|
|
70
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
|
71
|
+
s.add_dependency(%q<mocha>, [">= 0"])
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
metadata
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: txter
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Jack Danger Canty
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
|
|
12
|
+
date: 2010-03-17 00:00:00 -07:00
|
|
13
|
+
default_executable:
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: shoulda
|
|
17
|
+
type: :development
|
|
18
|
+
version_requirement:
|
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0"
|
|
24
|
+
version:
|
|
25
|
+
- !ruby/object:Gem::Dependency
|
|
26
|
+
name: mocha
|
|
27
|
+
type: :development
|
|
28
|
+
version_requirement:
|
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: "0"
|
|
34
|
+
version:
|
|
35
|
+
description: Drop-in functionality to let Ruby apps send and receive TXT messages
|
|
36
|
+
email: gitcommit@6brand.com
|
|
37
|
+
executables: []
|
|
38
|
+
|
|
39
|
+
extensions: []
|
|
40
|
+
|
|
41
|
+
extra_rdoc_files:
|
|
42
|
+
- README.markdown
|
|
43
|
+
files:
|
|
44
|
+
- MIT-LICENSE
|
|
45
|
+
- README.markdown
|
|
46
|
+
- Rakefile
|
|
47
|
+
- VERSION
|
|
48
|
+
- init.rb
|
|
49
|
+
- lib/4info_templates/confirm.haml
|
|
50
|
+
- lib/4info_templates/deliver.haml
|
|
51
|
+
- lib/4info_templates/unblock.haml
|
|
52
|
+
- lib/configuration.rb
|
|
53
|
+
- lib/contactable.rb
|
|
54
|
+
- lib/controller.rb
|
|
55
|
+
- lib/gateway.rb
|
|
56
|
+
- lib/gateway_4info.rb
|
|
57
|
+
- lib/gateway_twilio.rb
|
|
58
|
+
- lib/txter.rb
|
|
59
|
+
- test/.gitignore
|
|
60
|
+
- test/database.yml
|
|
61
|
+
- test/gateway_4info_test.rb
|
|
62
|
+
- test/gateway_twilio_test.rb
|
|
63
|
+
- test/test_helper.rb
|
|
64
|
+
- test/txter_contactable_test.rb
|
|
65
|
+
- test/txter_controller_test.rb
|
|
66
|
+
- test/txter_module_test.rb
|
|
67
|
+
- txter.gemspec
|
|
68
|
+
has_rdoc: true
|
|
69
|
+
homepage: http://github.com/JackDanger/txter
|
|
70
|
+
licenses: []
|
|
71
|
+
|
|
72
|
+
post_install_message:
|
|
73
|
+
rdoc_options:
|
|
74
|
+
- --charset=UTF-8
|
|
75
|
+
require_paths:
|
|
76
|
+
- lib
|
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: "0"
|
|
82
|
+
version:
|
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: "0"
|
|
88
|
+
version:
|
|
89
|
+
requirements: []
|
|
90
|
+
|
|
91
|
+
rubyforge_project:
|
|
92
|
+
rubygems_version: 1.3.5
|
|
93
|
+
signing_key:
|
|
94
|
+
specification_version: 3
|
|
95
|
+
summary: Send and receive SMS messages simply via the Twilio gateway or the 4info.com gateway
|
|
96
|
+
test_files:
|
|
97
|
+
- test/gateway_4info_test.rb
|
|
98
|
+
- test/gateway_twilio_test.rb
|
|
99
|
+
- test/test_helper.rb
|
|
100
|
+
- test/txter_contactable_test.rb
|
|
101
|
+
- test/txter_controller_test.rb
|
|
102
|
+
- test/txter_module_test.rb
|