sms_validation 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sms_validation/sms.rb +4 -0
- data/lib/sms_validation/version.rb +1 -1
- data/spec/sms_spec.rb +32 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b680d0a60c8b323c44c6008c814afc782f6763a7
|
4
|
+
data.tar.gz: 6c78e5f0cff56d2fe3f3b5849adcf7c5601cb726
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0028894c60c16c7bb17e031db6114645f404f8db2418f864293b5156a4ce4afd82421ec8f40511452567fa2d0cd143df35b2fe83a963594212cf5139a539a64a
|
7
|
+
data.tar.gz: 901fd4a43d146b3c993b517e367b74331db37d7134c1f747692ecce9a49c49af86bb34495968380c3b726365cb08529124513e7cd5a9ea9cf0e8e789d38e9782
|
data/lib/sms_validation/sms.rb
CHANGED
@@ -9,6 +9,8 @@ module SmsValidation
|
|
9
9
|
MAX_LENGTH = 160
|
10
10
|
MAX_SECTION_LENGTH = MAX_LENGTH - "(MSG XXX/XXX): ".size
|
11
11
|
MESSAGE_WHEN_SPLIT_MESSAGE = "This message was split because it is too long to fit into a single SMS. Instead of #message, use #messages or change SmsValidation.configuration.on_message_too_long to something other than :split"
|
12
|
+
LEGAL_CHARACTERS = "~\`!\"#\$\%&'\(\)*+,-.\/:;<=>?@_£¤¥§¿i¡ÄÅÃÆÇÉÑÖØÜßâáäåãæçèéìíñòöøóùüú\n\r\t ©"
|
13
|
+
ILLEGAL_CHARACTERS = /([^a-zA-Z0-9#{LEGAL_CHARACTERS}\\])/
|
12
14
|
|
13
15
|
attr_reader :phone, :messages
|
14
16
|
|
@@ -18,6 +20,8 @@ module SmsValidation
|
|
18
20
|
raise InvalidPhoneNumberError, "Phone number cannot begin with a \"#{phone[0]}\"" if ['0','1'].include?(phone[0].to_s)
|
19
21
|
raise InvalidMessageError, "Message cannot be blank" if message.empty?
|
20
22
|
SmsValidation.configuration.logger.warn { "WARNING: Some characters may be lost because the message must be broken into at least 1000 sections" } if message.size > (999 * MAX_SECTION_LENGTH)
|
23
|
+
illegal_characters = message.scan(ILLEGAL_CHARACTERS).to_a
|
24
|
+
raise InvalidMessageError, "Message cannot contain the following special characters: #{illegal_characters.uniq.join(', ')}" unless illegal_characters.size.zero?
|
21
25
|
@messages = (message.size > MAX_LENGTH) ? SmsValidation::Sms.__send__(SmsValidation.configuration.on_message_too_long, message) : [message.dup]
|
22
26
|
@phone = "1#{phone}"
|
23
27
|
end
|
data/spec/sms_spec.rb
CHANGED
@@ -82,6 +82,38 @@ describe SmsValidation::Sms do
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
+
describe "when it contains only legal characters" do
|
86
|
+
described_class::LEGAL_CHARACTERS.each_char do |i|
|
87
|
+
describe "when message contains legal character '#{i}'" do
|
88
|
+
let(:message) { "#{super()}#{i}#{super()}" }
|
89
|
+
|
90
|
+
it { expect(subject.message).to eq(message) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "when message contains legal character '\'" do
|
95
|
+
let(:message) { "#{super()}\A#{super()}" }
|
96
|
+
|
97
|
+
it { expect(subject.message).to eq(message) }
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "when it contains illegal characters" do
|
102
|
+
["\u2018", "\u2019", "\u201c", "\u201d"].each do |i|
|
103
|
+
describe "when message contains illegal character '#{i}'" do
|
104
|
+
let(:message) { "#{super()}#{i}#{super()}" }
|
105
|
+
|
106
|
+
it { expect{subject}.to raise_error(SmsValidation::Sms::InvalidMessageError, "Message cannot contain the following special characters: #{i}") }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
describe "when message contains multiple illegal characters" do
|
111
|
+
let(:message) { "#{super()}\u2018\u2019\u8888#{super()}" }
|
112
|
+
|
113
|
+
it { expect{subject}.to raise_error(SmsValidation::Sms::InvalidMessageError, "Message cannot contain the following special characters: \u2018, \u2019, \u8888") }
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
85
117
|
describe "when longer than 160 characters" do
|
86
118
|
describe "when on_message_too_long = :truncate" do
|
87
119
|
let(:on_message_too_long) { :truncate }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sms_validation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Isaac Betesh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -94,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
94
|
version: '0'
|
95
95
|
requirements: []
|
96
96
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.2.2
|
98
98
|
signing_key:
|
99
99
|
specification_version: 4
|
100
100
|
summary: '# SmsValidation This gem does not send SMS messages. It just makes sure
|