4info 1.3.4 → 2.0.0
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 +10 -10
- data/VERSION +1 -1
- data/init.rb +1 -1
- data/lib/{templates → 4info_templates}/confirm.haml +0 -0
- data/lib/{templates → 4info_templates}/deliver.haml +0 -0
- data/lib/{templates → 4info_templates}/unblock.haml +0 -0
- data/lib/configuration.rb +3 -1
- data/lib/contactable.rb +45 -60
- data/lib/controller.rb +3 -3
- data/lib/gateway.rb +45 -0
- data/lib/gateway_4info.rb +114 -0
- data/lib/gateway_twilio.rb +45 -0
- data/lib/{four_info.rb → txter.rb} +6 -5
- data/test/gateway_4info_test.rb +75 -0
- data/test/gateway_twilio_test.rb +15 -0
- data/test/test_helper.rb +6 -5
- data/test/{four_info_contactable_test.rb → txter_contactable_test.rb} +51 -73
- data/test/{four_info_controller_test.rb → txter_controller_test.rb} +8 -8
- data/test/txter_module_test.rb +56 -0
- data/{4info.gemspec → txter.gemspec} +7 -7
- metadata +20 -16
- data/lib/4info.rb +0 -3
- data/lib/request.rb +0 -75
- data/lib/response.rb +0 -27
- data/test/four_info_module_test.rb +0 -56
@@ -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
|
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
|
|
26
26
|
"lib/configuration.rb",
|
27
27
|
"lib/contactable.rb",
|
28
28
|
"lib/controller.rb",
|
29
|
-
"lib/
|
29
|
+
"lib/txter.rb",
|
30
30
|
"lib/request.rb",
|
31
31
|
"lib/response.rb",
|
32
32
|
"lib/templates/confirm.haml",
|
@@ -34,9 +34,9 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/templates/unblock.haml",
|
35
35
|
"test/.gitignore",
|
36
36
|
"test/database.yml",
|
37
|
-
"test/
|
38
|
-
"test/
|
39
|
-
"test/
|
37
|
+
"test/txter_contactable_test.rb",
|
38
|
+
"test/txter_controller_test.rb",
|
39
|
+
"test/txter_module_test.rb",
|
40
40
|
"test/test_helper.rb"
|
41
41
|
]
|
42
42
|
s.homepage = %q{http://github.com/JackDanger/4info}
|
@@ -45,9 +45,9 @@ Gem::Specification.new do |s|
|
|
45
45
|
s.rubygems_version = %q{1.3.5}
|
46
46
|
s.summary = %q{Send and receive SMS messages via 4info.com}
|
47
47
|
s.test_files = [
|
48
|
-
"test/
|
49
|
-
"test/
|
50
|
-
"test/
|
48
|
+
"test/txter_contactable_test.rb",
|
49
|
+
"test/txter_controller_test.rb",
|
50
|
+
"test/txter_module_test.rb",
|
51
51
|
"test/test_helper.rb"
|
52
52
|
]
|
53
53
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 4info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Danger Canty
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-03-
|
12
|
+
date: 2010-03-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -61,28 +61,30 @@ extensions: []
|
|
61
61
|
extra_rdoc_files:
|
62
62
|
- README.markdown
|
63
63
|
files:
|
64
|
-
- 4info.gemspec
|
65
64
|
- MIT-LICENSE
|
66
65
|
- README.markdown
|
67
66
|
- Rakefile
|
68
67
|
- VERSION
|
69
68
|
- init.rb
|
70
|
-
- lib/
|
69
|
+
- lib/4info_templates/confirm.haml
|
70
|
+
- lib/4info_templates/deliver.haml
|
71
|
+
- lib/4info_templates/unblock.haml
|
71
72
|
- lib/configuration.rb
|
72
73
|
- lib/contactable.rb
|
73
74
|
- lib/controller.rb
|
74
|
-
- lib/
|
75
|
-
- lib/
|
76
|
-
- lib/
|
77
|
-
- lib/
|
78
|
-
- lib/templates/deliver.haml
|
79
|
-
- lib/templates/unblock.haml
|
75
|
+
- lib/gateway.rb
|
76
|
+
- lib/gateway_4info.rb
|
77
|
+
- lib/gateway_twilio.rb
|
78
|
+
- lib/txter.rb
|
80
79
|
- test/.gitignore
|
81
80
|
- test/database.yml
|
82
|
-
- test/
|
83
|
-
- test/
|
84
|
-
- test/four_info_module_test.rb
|
81
|
+
- test/gateway_4info_test.rb
|
82
|
+
- test/gateway_twilio_test.rb
|
85
83
|
- test/test_helper.rb
|
84
|
+
- test/txter_contactable_test.rb
|
85
|
+
- test/txter_controller_test.rb
|
86
|
+
- test/txter_module_test.rb
|
87
|
+
- txter.gemspec
|
86
88
|
has_rdoc: true
|
87
89
|
homepage: http://github.com/JackDanger/4info
|
88
90
|
licenses: []
|
@@ -112,7 +114,9 @@ signing_key:
|
|
112
114
|
specification_version: 3
|
113
115
|
summary: Send and receive SMS messages via 4info.com
|
114
116
|
test_files:
|
115
|
-
- test/
|
116
|
-
- test/
|
117
|
-
- test/four_info_module_test.rb
|
117
|
+
- test/gateway_4info_test.rb
|
118
|
+
- test/gateway_twilio_test.rb
|
118
119
|
- test/test_helper.rb
|
120
|
+
- test/txter_contactable_test.rb
|
121
|
+
- test/txter_controller_test.rb
|
122
|
+
- test/txter_module_test.rb
|
data/lib/4info.rb
DELETED
data/lib/request.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
module FourInfo
|
2
|
-
class Request
|
3
|
-
|
4
|
-
attr_accessor :config
|
5
|
-
attr_accessor :number
|
6
|
-
attr_accessor :message
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
unless FourInfo.configured?
|
10
|
-
raise "You need to configure FourInfo before using it!"
|
11
|
-
end
|
12
|
-
self.config = FourInfo.configuration
|
13
|
-
end
|
14
|
-
|
15
|
-
def deliver_message(message, number)
|
16
|
-
self.number = FourInfo.internationalize(number)
|
17
|
-
self.message = message
|
18
|
-
|
19
|
-
xml = template(:deliver).render(self)
|
20
|
-
Response.new(perform(xml))
|
21
|
-
end
|
22
|
-
|
23
|
-
def confirm(number)
|
24
|
-
self.number = FourInfo.internationalize(number)
|
25
|
-
|
26
|
-
xml = template(:confirm).render(self)
|
27
|
-
Response.new(perform(xml))
|
28
|
-
end
|
29
|
-
|
30
|
-
def unblock(number)
|
31
|
-
self.number = FourInfo.internationalize(number)
|
32
|
-
|
33
|
-
xml = template(:unblock).render(self)
|
34
|
-
Response.new(perform(xml))
|
35
|
-
end
|
36
|
-
|
37
|
-
protected
|
38
|
-
|
39
|
-
def template(name)
|
40
|
-
# Haml templates for XML
|
41
|
-
require 'cgi'
|
42
|
-
templates = Dir.glob(File.expand_path(File.join(File.dirname(__FILE__), 'templates', '*.haml')))
|
43
|
-
file = templates.detect {|t| File.basename(t).chomp('.haml').to_sym == name.to_sym }
|
44
|
-
raise ArgumentError, "Missing 4Info template: #{name}" unless file
|
45
|
-
Haml::Engine.new(File.read(file))
|
46
|
-
end
|
47
|
-
|
48
|
-
def perform(body)
|
49
|
-
if :live == FourInfo.mode
|
50
|
-
start do |http|
|
51
|
-
http.post(
|
52
|
-
FourInfo.gateway.path,
|
53
|
-
body,
|
54
|
-
{'Content-Type' => 'text/xml'}
|
55
|
-
).read_body
|
56
|
-
end
|
57
|
-
else
|
58
|
-
FourInfo.log "Would have sent to 4info.net: #{body}"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def start
|
63
|
-
net = config.proxy_address ?
|
64
|
-
Net::HTTP::Proxy(
|
65
|
-
config.proxy_address,
|
66
|
-
config.proxy_port,
|
67
|
-
config.proxy_username,
|
68
|
-
config.proxy_password) :
|
69
|
-
Net::HTTP
|
70
|
-
net.start(FourInfo.gateway.host, FourInfo.gateway.port) do |http|
|
71
|
-
yield http
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
data/lib/response.rb
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
module FourInfo
|
2
|
-
class Response
|
3
|
-
def initialize(xml)
|
4
|
-
gem 'hpricot'
|
5
|
-
require 'hpricot'
|
6
|
-
@xml = xml
|
7
|
-
@body = Hpricot.parse(xml)
|
8
|
-
end
|
9
|
-
|
10
|
-
def inspect
|
11
|
-
@xml.to_s
|
12
|
-
end
|
13
|
-
|
14
|
-
def [](name)
|
15
|
-
nodes = (@body/name)
|
16
|
-
1 == nodes.size ? nodes.first : nodes
|
17
|
-
end
|
18
|
-
|
19
|
-
def success?
|
20
|
-
'Success' == self['message'].inner_text
|
21
|
-
end
|
22
|
-
|
23
|
-
def confirmation_code
|
24
|
-
self[:confcode].inner_text
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
-
|
3
|
-
class FourInfoModuleTest < ActiveSupport::TestCase
|
4
|
-
|
5
|
-
context "standardizing numbers" do
|
6
|
-
context "to digits" do
|
7
|
-
should "remove all but integers" do
|
8
|
-
assert_equal '12345', FourInfo.numerize('1-2-3-4-5')
|
9
|
-
assert_equal '12345', FourInfo.numerize('1 2 3 4 5')
|
10
|
-
assert_equal '12345', FourInfo.numerize('1,2(3)4.5')
|
11
|
-
assert_equal '12345', FourInfo.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', FourInfo.internationalize('12345678901')
|
17
|
-
assert_equal '+72345678901', FourInfo.internationalize('72345678901')
|
18
|
-
end
|
19
|
-
should "add a '+1' to any 10 digit number" do
|
20
|
-
assert_equal '+12345678901', FourInfo.internationalize('2345678901')
|
21
|
-
assert_equal '+17345678901', FourInfo.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, FourInfo.internationalize(number)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
should "return nil for all bad numbers" do
|
31
|
-
assert_equal nil, FourInfo.internationalize(nil)
|
32
|
-
assert_equal nil, FourInfo.internationalize('nil')
|
33
|
-
assert_equal nil, FourInfo.internationalize('1234')
|
34
|
-
assert_equal nil, FourInfo.internationalize('11111111111111111111111')
|
35
|
-
assert_equal nil, FourInfo.internationalize('what?')
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "generating codes" do
|
41
|
-
setup { @code = FourInfo.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 = FourInfo.confirmation_message(@code)
|
51
|
-
}
|
52
|
-
should "include code" do
|
53
|
-
assert @message.include?(@code)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|