mote_sms 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +0 -1
- data/lib/mote_sms/number.rb +5 -2
- data/lib/mote_sms/transports/action_mailer_transport.rb +48 -0
- data/lib/mote_sms/transports.rb +1 -0
- data/lib/mote_sms/version.rb +1 -1
- data/mote_sms.gemspec +1 -0
- data/spec/mote_sms/number_spec.rb +10 -10
- data/spec/mote_sms/transports/action_mailer_transport_spec.rb +27 -0
- metadata +22 -3
data/.travis.yml
CHANGED
data/lib/mote_sms/number.rb
CHANGED
@@ -38,9 +38,10 @@ module MoteSMS
|
|
38
38
|
#
|
39
39
|
def parse_raw_number
|
40
40
|
unless vanity?
|
41
|
-
raise ArgumentError, "Unable to parse #{@raw_number} as number" unless
|
41
|
+
raise ArgumentError, "Unable to parse #{@raw_number} as number" unless @raw_number.to_s =~ /\A[\d\.\/\-\s\(\)\+]+\z/
|
42
|
+
cc = @options[:cc]
|
42
43
|
normalized = Phony.normalize(@raw_number)
|
43
|
-
normalized = "#{
|
44
|
+
normalized = "#{cc}#{normalized}" unless cc && normalized.start_with?(cc)
|
44
45
|
raise ArgumentError, "Wrong national destination code #{@raw_number}" unless Phony.plausible?(normalized, @options)
|
45
46
|
|
46
47
|
@number = Phony.normalize normalized
|
@@ -48,6 +49,8 @@ module MoteSMS
|
|
48
49
|
@number = @raw_number.gsub(/[^A-Z0-9]/i, '').upcase.strip
|
49
50
|
raise ArgumentError, "Invalid vanity number #{@raw_number}" if @number.length == 0 || @number.length > 11
|
50
51
|
end
|
52
|
+
rescue NoMethodError
|
53
|
+
raise ArgumentError, "Unable to parse #{@raw_number} using phony"
|
51
54
|
end
|
52
55
|
end
|
53
56
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'action_mailer'
|
2
|
+
|
3
|
+
module MoteSMS
|
4
|
+
|
5
|
+
# Internal: ActionMailer class to forward SMS to recipient.
|
6
|
+
class ActionMailerSMSMailer < ::ActionMailer::Base
|
7
|
+
def forward_sms(recipient, sms)
|
8
|
+
subject = "SMS to #{sms.to.map(&:to_s).join(', ')}"
|
9
|
+
mail to: recipient, from: "#{sms.from} <#{recipient}>", subject: subject, body: sms.body
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# MoteSMS::ActionMailerTransport provides a transport implementation which
|
14
|
+
# can be used in development to forward SMS as e-mails. This allows to test
|
15
|
+
# sending SMSes to an e-mail endpoint.
|
16
|
+
#
|
17
|
+
# Examples:
|
18
|
+
#
|
19
|
+
# # => forwards all SMS to sms@example.com
|
20
|
+
# MoteSMS.transport = MoteSMS::ActionMailerTransport.new "sms@example.com"
|
21
|
+
#
|
22
|
+
# # => also accepts a Proc as recipient
|
23
|
+
# MoteSMS.transport = MoteSMS::ActionMailerTransport.new ->(msg) { "#{msg.from}@example.com" }
|
24
|
+
#
|
25
|
+
class ActionMailerTransport
|
26
|
+
|
27
|
+
# Public: Read/change the recipient used when delivering the message.
|
28
|
+
# Also accepts a Proc.
|
29
|
+
attr_accessor :recipient
|
30
|
+
|
31
|
+
# Public: Create a new ActionMailerTransport instance
|
32
|
+
def initialize(recipient)
|
33
|
+
self.recipient = recipient
|
34
|
+
end
|
35
|
+
|
36
|
+
# Public: Sends message using ActionMailer to recipient.
|
37
|
+
#
|
38
|
+
# message - The MoteSMS::Message instance to deliver.
|
39
|
+
# options - The Hash with additional, transport specific options,
|
40
|
+
# currently ignored.
|
41
|
+
#
|
42
|
+
# Returns nothing.
|
43
|
+
def deliver(message, options = {})
|
44
|
+
to = self.recipient.respond_to?(:call) ? self.recipient.call(message) : self.recipient
|
45
|
+
ActionMailerSMSMailer.forward_sms(to, message).deliver
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/mote_sms/transports.rb
CHANGED
@@ -4,4 +4,5 @@ module MoteSMS
|
|
4
4
|
# available in ruby as `MoteSMS::<Some>Transport`.
|
5
5
|
autoload :TestTransport, 'mote_sms/transports/test_transport'
|
6
6
|
autoload :MobileTechnicsTransport, 'mote_sms/transports/mobile_technics_transport'
|
7
|
+
autoload :ActionMailerTransport, 'mote_sms/transports/action_mailer_transport'
|
7
8
|
end
|
data/lib/mote_sms/version.rb
CHANGED
data/mote_sms.gemspec
CHANGED
@@ -18,14 +18,6 @@ describe MoteSMS::Number do
|
|
18
18
|
its(:to_number) { should == '41443643533' }
|
19
19
|
end
|
20
20
|
|
21
|
-
context 'E164 conforming number with name' do
|
22
|
-
subject { described_class.new('Frank: +41 44 3643533', cc: '41') }
|
23
|
-
|
24
|
-
its(:to_s) { should == '+41 44 364 35 33' }
|
25
|
-
its(:number) { should == '41443643533' }
|
26
|
-
its(:to_number) { should == '41443643533' }
|
27
|
-
end
|
28
|
-
|
29
21
|
context 'handles local numbers' do
|
30
22
|
subject { described_class.new('079 700 50 90', cc: '41') }
|
31
23
|
|
@@ -34,11 +26,19 @@ describe MoteSMS::Number do
|
|
34
26
|
its(:to_number) { should == '41797005090' }
|
35
27
|
end
|
36
28
|
|
29
|
+
context 'handles numbers with NDC regexp' do
|
30
|
+
subject { described_class.new('079 700 50 90', cc: '41', ndc: /(44|79)/) }
|
31
|
+
|
32
|
+
its(:to_s) { should == '+41 79 700 50 90' }
|
33
|
+
its(:number) { should == '41797005090' }
|
34
|
+
its(:to_number) { should == '41797005090' }
|
35
|
+
end
|
36
|
+
|
37
37
|
context 'non conforming number' do
|
38
38
|
it 'raises error when creating' do
|
39
39
|
Proc.new { described_class.new('what ever?') }.should raise_error(ArgumentError, /unable to parse/i)
|
40
|
-
Proc.new { described_class.new('0000') }.should raise_error(ArgumentError
|
41
|
-
Proc.new { described_class.new('123456789012345678901') }.should raise_error(ArgumentError
|
40
|
+
Proc.new { described_class.new('0000') }.should raise_error(ArgumentError)
|
41
|
+
Proc.new { described_class.new('123456789012345678901') }.should raise_error(ArgumentError)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'mote_sms/message'
|
3
|
+
require 'mote_sms/transports/action_mailer_transport'
|
4
|
+
|
5
|
+
describe MoteSMS::ActionMailerTransport do
|
6
|
+
subject { described_class.new "sms@example.com" }
|
7
|
+
let(:message) { MoteSMS::Message.new do
|
8
|
+
from 'Sender'
|
9
|
+
to '+41 79 123 12 12'
|
10
|
+
body 'This is the SMS content'
|
11
|
+
end
|
12
|
+
}
|
13
|
+
let(:email) { ActionMailer::Base.deliveries.last }
|
14
|
+
|
15
|
+
before do
|
16
|
+
ActionMailer::Base.deliveries.clear
|
17
|
+
ActionMailer::Base.delivery_method = :test
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'sends SMS as e-mail' do
|
21
|
+
subject.deliver message
|
22
|
+
email.to.should == ["sms@example.com"]
|
23
|
+
email.from.should == ["sms@example.com"]
|
24
|
+
email.subject.should == "SMS to +41 79 123 12 12"
|
25
|
+
email.body.should == "This is the SMS content"
|
26
|
+
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mote_sms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: phony
|
@@ -75,6 +75,22 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: 1.8.0
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: actionmailer
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '3.2'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '3.2'
|
78
94
|
description: ! "Unofficial ruby adapter for MobileTechnics HTTP Bulk SMS API.\n Tries
|
79
95
|
to mimick mail API, so users can switch e.g. ActionMailer\n with
|
80
96
|
this SMS provider."
|
@@ -96,6 +112,7 @@ files:
|
|
96
112
|
- lib/mote_sms/number_list.rb
|
97
113
|
- lib/mote_sms/transports.rb
|
98
114
|
- lib/mote_sms/transports/.gitkeep
|
115
|
+
- lib/mote_sms/transports/action_mailer_transport.rb
|
99
116
|
- lib/mote_sms/transports/mobile_technics_transport.rb
|
100
117
|
- lib/mote_sms/transports/test_transport.rb
|
101
118
|
- lib/mote_sms/version.rb
|
@@ -103,6 +120,7 @@ files:
|
|
103
120
|
- spec/mote_sms/message_spec.rb
|
104
121
|
- spec/mote_sms/number_list_spec.rb
|
105
122
|
- spec/mote_sms/number_spec.rb
|
123
|
+
- spec/mote_sms/transports/action_mailer_transport_spec.rb
|
106
124
|
- spec/mote_sms/transports/mobile_technics_transport_spec.rb
|
107
125
|
- spec/mote_sms/transports/test_transport_spec.rb
|
108
126
|
- spec/mote_sms_spec.rb
|
@@ -127,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
145
|
version: '0'
|
128
146
|
segments:
|
129
147
|
- 0
|
130
|
-
hash:
|
148
|
+
hash: -686134082126475921
|
131
149
|
requirements: []
|
132
150
|
rubyforge_project:
|
133
151
|
rubygems_version: 1.8.23
|
@@ -138,6 +156,7 @@ test_files:
|
|
138
156
|
- spec/mote_sms/message_spec.rb
|
139
157
|
- spec/mote_sms/number_list_spec.rb
|
140
158
|
- spec/mote_sms/number_spec.rb
|
159
|
+
- spec/mote_sms/transports/action_mailer_transport_spec.rb
|
141
160
|
- spec/mote_sms/transports/mobile_technics_transport_spec.rb
|
142
161
|
- spec/mote_sms/transports/test_transport_spec.rb
|
143
162
|
- spec/mote_sms_spec.rb
|