mblox 0.0.1 → 0.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/README.md +4 -1
- data/lib/mblox/configuration.rb +7 -1
- data/lib/mblox/sms.rb +4 -0
- data/lib/mblox/version.rb +1 -1
- data/spec/configuration_spec.rb +23 -0
- data/spec/log_spec.rb +1 -9
- data/spec/sms_spec.rb +20 -0
- data/spec/spec_helper.rb +8 -0
- metadata +10 -8
- data/STDOUT +0 -1
data/README.md
CHANGED
@@ -36,6 +36,9 @@ Configuration
|
|
36
36
|
# If config.log_at == :debug and your logger's log level is :info, logging will be suppressed because it is below the log level of the logger.
|
37
37
|
config.logger = Logger.new(STDOUT)
|
38
38
|
config.log_at :info
|
39
|
+
|
40
|
+
# What to do if messages are longer than 160 characters. Default is :raise_error
|
41
|
+
config.on_message_too_long = :truncate
|
39
42
|
end
|
40
43
|
|
41
44
|
Once your application is configured, send messages:
|
@@ -49,7 +52,7 @@ Copy config.yml.example to config.yml and set all the values in that file. Run:
|
|
49
52
|
|
50
53
|
rspec
|
51
54
|
|
52
|
-
You should recieve
|
55
|
+
You should recieve 3 SMS messages to your phone within several seconds.
|
53
56
|
|
54
57
|
## Contributing
|
55
58
|
|
data/lib/mblox/configuration.rb
CHANGED
@@ -11,10 +11,16 @@ module Mblox
|
|
11
11
|
|
12
12
|
class Configuration
|
13
13
|
attr_accessor :outbound_url, :profile_id, :sender_id, :password, :partner_name, :tariff, :service_id
|
14
|
-
attr_reader :logger, :log_level
|
14
|
+
attr_reader :logger, :log_level, :on_message_too_long
|
15
15
|
def initialize
|
16
16
|
@logger = Rails.logger if defined?(::Rails)
|
17
17
|
@log_level = :debug
|
18
|
+
@on_message_too_long = :raise_error
|
19
|
+
end
|
20
|
+
|
21
|
+
def on_message_too_long= action
|
22
|
+
raise ArgumentError, "Mblox.config.on_message_too_long must be either :truncate or :raise_error" unless [:truncate, :raise_error].include?(action)
|
23
|
+
@on_message_too_long = action
|
18
24
|
end
|
19
25
|
|
20
26
|
def log_at level
|
data/lib/mblox/sms.rb
CHANGED
@@ -11,6 +11,10 @@ module Mblox
|
|
11
11
|
raise SmsError, "Phone number must be ten digits" unless /\A[0-9]{10}\z/.match(phone)
|
12
12
|
raise SmsError, "Phone number cannot begin with 0 or 1" if ['0','1'].include?(phone[0].to_s)
|
13
13
|
raise SmsError, "Message cannot be blank" if message.empty?
|
14
|
+
if message.size > 160
|
15
|
+
raise SmsError, "Message cannot be longer than 160 characters" if :raise_error == Mblox.config.on_message_too_long
|
16
|
+
message = message[0,160] if :truncate == Mblox.config.on_message_too_long
|
17
|
+
end
|
14
18
|
@phone = "1#{phone}"
|
15
19
|
@message = message.dup
|
16
20
|
end
|
data/lib/mblox/version.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "configuration" do
|
4
|
+
describe "on_message_too_long" do
|
5
|
+
it "should default to :raise_error" do
|
6
|
+
Mblox.reset_configuration
|
7
|
+
expect(Mblox.config.on_message_too_long).to eq(:raise_error)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should allow the value :truncate" do
|
11
|
+
expect { Mblox.config.on_message_too_long = :truncate }.to_not raise_error
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should allow the value :raise_error" do
|
15
|
+
expect { Mblox.config.on_message_too_long = :raise_error }.to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should not allow other values and should remain in a valid state" do
|
19
|
+
expect { Mblox.config.on_message_too_long = :do_nothing }.to raise_error(ArgumentError, "Mblox.config.on_message_too_long must be either :truncate or :raise_error")
|
20
|
+
expect(Mblox.config.on_message_too_long).to eq(:raise_error)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/log_spec.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
require "logger"
|
3
3
|
|
4
|
-
module Mblox
|
5
|
-
class << self
|
6
|
-
def reset_configuration
|
7
|
-
@config = Configuration.new
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
4
|
describe "logger" do
|
13
5
|
before(:each) do
|
14
6
|
Mblox.reset_configuration
|
@@ -31,7 +23,7 @@ describe "logger" do
|
|
31
23
|
|
32
24
|
it "should not allow log level news when the logger is created after log level is set" do
|
33
25
|
Mblox.config.log_at :news
|
34
|
-
expect { Mblox.config.logger = ::Logger.new(
|
26
|
+
expect { Mblox.config.logger = ::Logger.new(STDOUT)}.to raise_error(ArgumentError, "Mblox log level must be set to :fatal, :error, :warn, :info or :debug")
|
35
27
|
expect { Mblox.log "Some news" }.to_not raise_error
|
36
28
|
end
|
37
29
|
|
data/spec/sms_spec.rb
CHANGED
@@ -25,6 +25,22 @@ describe "message" do
|
|
25
25
|
expect { Mblox::Sms.new("2"*10, "") }.to raise_error(Mblox::SmsError, "Message cannot be blank")
|
26
26
|
end
|
27
27
|
|
28
|
+
it "can be 160 characters long" do
|
29
|
+
expect { Mblox::Sms.new("2"*10, "A"*160) }.to_not raise_error
|
30
|
+
end
|
31
|
+
|
32
|
+
it "will be truncated when the message is longer than 160 characters if configured to do so" do
|
33
|
+
message = "A"+"ABCDEFGHIJ"*16
|
34
|
+
Mblox.config.on_message_too_long = :truncate
|
35
|
+
expect { @mblox = Mblox::Sms.new("2"*10, message) }.to_not raise_error
|
36
|
+
expect(@mblox.message).to eq(message[0,160])
|
37
|
+
end
|
38
|
+
|
39
|
+
it "cannot be longer than 160 characters if configured to raise error" do
|
40
|
+
Mblox.config.on_message_too_long = :raise_error
|
41
|
+
expect { Mblox::Sms.new("2"*10, "A"*161) }.to raise_error(Mblox::SmsError, "Message cannot be longer than 160 characters")
|
42
|
+
end
|
43
|
+
|
28
44
|
it "should be safe from changing" do
|
29
45
|
msg = the_message
|
30
46
|
mblox = Mblox::Sms.new(TEST_NUMBER,msg)
|
@@ -42,6 +58,10 @@ describe "SMS messages" do
|
|
42
58
|
expect(Mblox::Sms.new(TEST_NUMBER.to_s,the_message).send).to eq(result_ok)
|
43
59
|
end
|
44
60
|
|
61
|
+
it "should allow 160-character messages" do
|
62
|
+
expect(Mblox::Sms.new(TEST_NUMBER,"A"*160).send).to eq(result_ok)
|
63
|
+
end
|
64
|
+
|
45
65
|
it "should fail when sent to a landline" do
|
46
66
|
expect(Mblox::Sms.new("6176354500",the_message).send).to eq(result_unroutable)
|
47
67
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -30,3 +30,11 @@ end
|
|
30
30
|
def result_unroutable
|
31
31
|
"RequestResult: \"0:OK\" / SubscriberResult: \"10:MsipRejectCode=29 Number unroutable:2e Do not retry:2e\""
|
32
32
|
end
|
33
|
+
|
34
|
+
module Mblox
|
35
|
+
class << self
|
36
|
+
def reset_configuration
|
37
|
+
@config = Configuration.new
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mblox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -119,7 +119,6 @@ files:
|
|
119
119
|
- LICENSE.txt
|
120
120
|
- README.md
|
121
121
|
- Rakefile
|
122
|
-
- STDOUT
|
123
122
|
- config.yml.example
|
124
123
|
- lib/mblox.rb
|
125
124
|
- lib/mblox/configuration.rb
|
@@ -127,6 +126,7 @@ files:
|
|
127
126
|
- lib/mblox/sms_error.rb
|
128
127
|
- lib/mblox/version.rb
|
129
128
|
- mblox.gemspec
|
129
|
+
- spec/configuration_spec.rb
|
130
130
|
- spec/log_spec.rb
|
131
131
|
- spec/sms_spec.rb
|
132
132
|
- spec/spec_helper.rb
|
@@ -164,16 +164,18 @@ summary: ! '# Mblox This gem is for subscribers to Mblox to send SMS messages.
|
|
164
164
|
will default to Rails.logger and config.log_at will default to :debug # config.log_at
|
165
165
|
means the level at which Mblox will log. # If config.log_at == :debug and your logger''s
|
166
166
|
log level is :info, logging will be suppressed because it is below the log level
|
167
|
-
of the logger. config.logger = Logger.new(STDOUT) config.log_at :info
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
167
|
+
of the logger. config.logger = Logger.new(STDOUT) config.log_at :info # What to
|
168
|
+
do if messages are longer than 160 characters. Default is :raise_error config.on_message_too_long
|
169
|
+
= :truncate end Once your application is configured, send messages: phone_number
|
170
|
+
= 2225555555 # The number you''re sending to. Must be a 10-digit number, including
|
171
|
+
the area code. Can be a String or Fixnum. Mblox::Sms.new(phone_number, "your message").send ##
|
172
|
+
Testing Copy config.yml.example to config.yml and set all the values in that file. Run: rspec You
|
173
|
+
should recieve 3 SMS messages to your phone within several seconds. ## Contributing 1.
|
173
174
|
Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit
|
174
175
|
your changes (`git commit -am ''Add some feature''`) 4. Push to the branch (`git
|
175
176
|
push origin my-new-feature`) 5. Create new Pull Request'
|
176
177
|
test_files:
|
178
|
+
- spec/configuration_spec.rb
|
177
179
|
- spec/log_spec.rb
|
178
180
|
- spec/sms_spec.rb
|
179
181
|
- spec/spec_helper.rb
|
data/STDOUT
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# Logfile created on 2013-05-01 15:05:03 -0400 by logger.rb/31641
|