locasms 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -1
- data/README.md +1 -1
- data/lib/locasms/version.rb +1 -1
- data/lib/locasms.rb +5 -3
- data/locasms.gemspec +5 -5
- data/spec/lib/locasms/client_spec.rb +16 -16
- data/spec/lib/locasms/helpers/date_time_helper_spec.rb +4 -4
- data/spec/lib/locasms/numbers_spec.rb +71 -43
- data/spec/lib/locasms/rest_client_spec.rb +9 -9
- metadata +13 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 364b1c84ab3b08af2dbcbc97454606fa196b0c0f
|
4
|
+
data.tar.gz: 91f8f1d10f22abce7d0e18a9b2b6437905d61ef3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4469e3539da0f5f3b9ccbd1376a43b87884fc5c6e9d3024aed4e764452eabb83a5c76c0c8b1fd4cb329008ec7ac78a34e901b69b5d0855ee31938804d5bdb0fa
|
7
|
+
data.tar.gz: b03a24dca3edf92af9cb3bcae54acd2285f2beeaef3b2c9df15cc5ffb1f763e6ebbf5302f7e3a7b865187d8a88f96055473830e079913c09ca712b00c8060c0c
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# locasms [](https://travis-ci.org/mcorp/locasms) [](https://gemnasium.com/mcorp/locasms)
|
1
|
+
# locasms [](https://travis-ci.org/mcorp/locasms) [](https://gemnasium.com/mcorp/locasms) [](https://codeclimate.com/github/mcorp/locasms)
|
2
2
|
|
3
3
|
Client to consume [LocaSMS api's][0].
|
4
4
|
|
data/lib/locasms/version.rb
CHANGED
data/lib/locasms.rb
CHANGED
@@ -6,9 +6,11 @@ autoload :RestClient, 'rest_client'
|
|
6
6
|
autoload :Logger, 'logger'
|
7
7
|
|
8
8
|
module LocaSMS
|
9
|
-
autoload :Client,
|
10
|
-
autoload :Exception,
|
11
|
-
autoload :
|
9
|
+
autoload :Client, 'locasms/client'
|
10
|
+
autoload :Exception, 'locasms/exception'
|
11
|
+
autoload :InvalidLogin, 'locasms/exception'
|
12
|
+
autoload :InvalidOperation, 'locasms/exception'
|
13
|
+
autoload :Numbers, 'locasms/numbers'
|
12
14
|
autoload :RestClient, 'locasms/rest_client'
|
13
15
|
|
14
16
|
module Helpers
|
data/locasms.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'locasms/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "locasms"
|
8
8
|
spec.version = LocaSMS::VERSION
|
9
|
-
spec.authors = ["Adilson Carvalho"]
|
10
|
-
spec.email = ["lc.adilson@gmail.com"]
|
9
|
+
spec.authors = ["Adilson Carvalho", "Leonardo Saraiva", "Marco Carvalho"]
|
10
|
+
spec.email = ["lc.adilson@gmail.com", "vyper@maneh.org", "marco.carvalho.swasthya@gmail.com"]
|
11
11
|
spec.description = %q{Cliente para o serviço de disparo de SMS da LocaSMS}
|
12
12
|
spec.summary = %q{Cliente para o serviço de disparo de SMS da LocaSMS}
|
13
13
|
spec.homepage = "https://github.com/mcorp/locasms"
|
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.3'
|
22
|
-
spec.add_development_dependency 'rake', '~>
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.4.2'
|
23
23
|
|
24
24
|
# test stuff
|
25
|
-
spec.add_development_dependency 'rspec', '~> 2
|
26
|
-
spec.add_development_dependency 'fuubar', '~>
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.2'
|
26
|
+
spec.add_development_dependency 'fuubar', '~> 2.0.0'
|
27
27
|
|
28
28
|
# run tests automatically
|
29
29
|
spec.add_development_dependency 'guard'
|
@@ -5,18 +5,18 @@ describe LocaSMS::Client do
|
|
5
5
|
subject { LocaSMS::Client.new :login, :password, rest_client: rest_client }
|
6
6
|
|
7
7
|
describe '.initialize' do
|
8
|
-
it { subject.login.
|
9
|
-
it { subject.password.
|
8
|
+
it { expect(subject.login).to be(:login) }
|
9
|
+
it { expect(subject.password).to be(:password) }
|
10
10
|
end
|
11
11
|
|
12
12
|
describe '#deliver' do
|
13
13
|
it 'Should send SMS' do
|
14
|
-
subject.
|
14
|
+
expect(subject).to receive(:numbers)
|
15
15
|
.once
|
16
16
|
.with([:a, :b, :c])
|
17
17
|
.and_return('XXX')
|
18
18
|
|
19
|
-
rest_client.
|
19
|
+
expect(rest_client).to receive(:get)
|
20
20
|
.once
|
21
21
|
.with(:sendsms, msg: 'given message', numbers:'XXX')
|
22
22
|
.and_return({})
|
@@ -25,30 +25,30 @@ describe LocaSMS::Client do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'Should not send SMS' do
|
28
|
-
subject.
|
28
|
+
expect(subject).to receive(:numbers)
|
29
29
|
.once
|
30
30
|
.with([:a, :b, :c])
|
31
31
|
.and_raise(LocaSMS::Exception)
|
32
32
|
|
33
|
-
rest_client.
|
33
|
+
expect(rest_client).to receive(:get).never
|
34
34
|
|
35
|
-
|
35
|
+
expect { subject.deliver('given message', :a, :b, :c) }.to raise_error(LocaSMS::Exception)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
39
|
describe '#deliver_at' do
|
40
40
|
it 'Should send SMS' do
|
41
|
-
subject.
|
41
|
+
expect(subject).to receive(:numbers)
|
42
42
|
.once
|
43
43
|
.with([:a, :b, :c])
|
44
44
|
.and_return('XXX')
|
45
45
|
|
46
|
-
LocaSMS::Helpers::DateTimeHelper.
|
46
|
+
expect(LocaSMS::Helpers::DateTimeHelper).to receive(:split)
|
47
47
|
.once
|
48
48
|
.with(:datetime)
|
49
49
|
.and_return(%w[date time])
|
50
50
|
|
51
|
-
rest_client.
|
51
|
+
expect(rest_client).to receive(:get)
|
52
52
|
.once
|
53
53
|
.with(:sendsms, msg: 'given message', numbers:'XXX', jobdate: 'date', jobtime: 'time')
|
54
54
|
.and_return({})
|
@@ -57,25 +57,25 @@ describe LocaSMS::Client do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'Should not send SMS' do
|
60
|
-
subject.
|
60
|
+
expect(subject).to receive(:numbers)
|
61
61
|
.once
|
62
62
|
.with([:a, :b, :c])
|
63
63
|
.and_raise(LocaSMS::Exception)
|
64
64
|
|
65
|
-
LocaSMS::Helpers::DateTimeHelper.
|
65
|
+
expect(LocaSMS::Helpers::DateTimeHelper).to receive(:split)
|
66
66
|
.once
|
67
67
|
.with(:datetime)
|
68
68
|
.and_return(%w[date time])
|
69
69
|
|
70
|
-
rest_client.
|
70
|
+
expect(rest_client).to receive(:get).never
|
71
71
|
|
72
|
-
|
72
|
+
expect { subject.deliver_at('given message', :datetime, :a, :b, :c) }.to raise_error(LocaSMS::Exception)
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
describe '#balance' do
|
77
77
|
it 'Should check param assignment' do
|
78
|
-
rest_client.
|
78
|
+
expect(rest_client).to receive(:get)
|
79
79
|
.once
|
80
80
|
.with(:getbalance)
|
81
81
|
.and_return({})
|
@@ -92,7 +92,7 @@ describe LocaSMS::Client do
|
|
92
92
|
campaign_release: :releasesms
|
93
93
|
}[method]
|
94
94
|
|
95
|
-
rest_client.
|
95
|
+
expect(rest_client).to receive(:get)
|
96
96
|
.once
|
97
97
|
.with(rest_method, id: '12345')
|
98
98
|
.and_return({})
|
@@ -5,7 +5,7 @@ describe LocaSMS::Helpers::DateTimeHelper do
|
|
5
5
|
|
6
6
|
describe '#parse' do
|
7
7
|
it 'Should call the class method' do
|
8
|
-
subject.
|
8
|
+
expect(subject).to receive(:parse)
|
9
9
|
.once
|
10
10
|
.with(:value)
|
11
11
|
|
@@ -15,7 +15,7 @@ describe LocaSMS::Helpers::DateTimeHelper do
|
|
15
15
|
|
16
16
|
describe '#split' do
|
17
17
|
it 'Should call the class method' do
|
18
|
-
subject.
|
18
|
+
expect(subject).to receive(:split)
|
19
19
|
.once
|
20
20
|
.with(:value)
|
21
21
|
|
@@ -38,12 +38,12 @@ describe LocaSMS::Helpers::DateTimeHelper do
|
|
38
38
|
|
39
39
|
describe '.split' do
|
40
40
|
it 'Should break a date into date and time' do
|
41
|
-
subject.
|
41
|
+
expect(subject).to receive(:parse)
|
42
42
|
.once
|
43
43
|
.with(:datetime)
|
44
44
|
.and_return(Time.parse('1977-03-14 14:12:00'))
|
45
45
|
|
46
|
-
subject.split(:datetime).
|
46
|
+
expect(subject.split(:datetime)).to eq(%w(14/03/1977 14:12))
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -5,74 +5,102 @@ describe LocaSMS::Numbers do
|
|
5
5
|
|
6
6
|
describe '.initialize' do
|
7
7
|
subject do
|
8
|
-
LocaSMS::Numbers.
|
9
|
-
|
10
|
-
.
|
11
|
-
|
12
|
-
|
8
|
+
expect_any_instance_of(LocaSMS::Numbers).
|
9
|
+
to receive(:evaluate).
|
10
|
+
once.
|
11
|
+
with([:numbers]).
|
12
|
+
and_return(good: [1, 3], bad: [2, 4])
|
13
13
|
LocaSMS::Numbers.new :numbers
|
14
14
|
end
|
15
15
|
|
16
|
-
it{ subject.good.
|
17
|
-
it{ subject.bad.
|
16
|
+
it { expect(subject.good).to eq([1, 3]) }
|
17
|
+
it { expect(subject.bad).to eq([2, 4]) }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '#normalize' do
|
21
|
-
it
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
it
|
27
|
-
|
21
|
+
it do
|
22
|
+
expect(subject.normalize('+55 (11) 8888-9999')).to(
|
23
|
+
eq(%w(551188889999))
|
24
|
+
)
|
25
|
+
end
|
26
|
+
it do
|
27
|
+
expect(subject.normalize('55', ['11', '22'])).to(
|
28
|
+
eq(%w(55 11 22))
|
29
|
+
)
|
30
|
+
end
|
31
|
+
it do
|
32
|
+
expect(subject.normalize(['55', 'ZZ', '22'])).to(
|
33
|
+
eq(%w(55 ZZ 22))
|
34
|
+
)
|
35
|
+
end
|
36
|
+
it do
|
37
|
+
expect(subject.normalize('55,44,33', ['ZZ', '22,11'])).to(
|
38
|
+
eq(%w(55 44 33 ZZ 22 11))
|
39
|
+
)
|
40
|
+
end
|
41
|
+
it do
|
42
|
+
expect(subject.normalize(55, [11, 22])).to(
|
43
|
+
eq(%w(55 11 22))
|
44
|
+
)
|
45
|
+
end
|
46
|
+
it { expect(subject.normalize('Z')).to eq(['Z']) }
|
47
|
+
it { expect(subject.normalize(nil)).to eq([]) }
|
28
48
|
end
|
29
49
|
|
30
50
|
describe '#valid_number?' do
|
31
|
-
it{ subject.valid_number?('+55 (11) 8888-9999').
|
32
|
-
it{ subject.valid_number?('88889999').
|
33
|
-
it{ subject.valid_number?('988889999').
|
34
|
-
it{ subject.valid_number?('ABC').
|
35
|
-
it{ subject.valid_number?('').
|
36
|
-
it{ subject.valid_number?(nil).
|
51
|
+
it { expect(subject.valid_number?('+55 (11) 8888-9999')).to be_falsey }
|
52
|
+
it { expect(subject.valid_number?('88889999')).to be_falsey }
|
53
|
+
it { expect(subject.valid_number?('988889999')).to be_falsey }
|
54
|
+
it { expect(subject.valid_number?('ABC')).to be_falsey }
|
55
|
+
it { expect(subject.valid_number?('')).to be_falsey }
|
56
|
+
it { expect(subject.valid_number?(nil)).to be_falsey }
|
37
57
|
|
38
|
-
it{ subject.valid_number?('1188889999').
|
39
|
-
it{ subject.valid_number?('11988889999').
|
58
|
+
it { expect(subject.valid_number?('1188889999')).to be_truthy }
|
59
|
+
it { expect(subject.valid_number?('11988889999')).to be_truthy }
|
40
60
|
end
|
41
61
|
|
42
62
|
describe '#evaluate' do
|
43
63
|
it 'Should separate numbers in good and bad' do
|
44
|
-
subject.
|
45
|
-
.
|
46
|
-
|
47
|
-
|
48
|
-
subject.
|
49
|
-
.
|
50
|
-
|
51
|
-
|
52
|
-
subject.
|
53
|
-
.
|
54
|
-
|
55
|
-
|
56
|
-
subject.evaluate(:numbers).
|
64
|
+
expect(subject).to receive(:normalize).
|
65
|
+
once.
|
66
|
+
with([:numbers]).
|
67
|
+
and_return([:good, :bad])
|
68
|
+
expect(subject).to receive(:valid_number?).
|
69
|
+
once.
|
70
|
+
with(:good).
|
71
|
+
and_return(true)
|
72
|
+
expect(subject).to receive(:valid_number?).
|
73
|
+
once.
|
74
|
+
with(:bad).
|
75
|
+
and_return(false)
|
76
|
+
expect(subject.evaluate(:numbers)).to(
|
77
|
+
eq(good: [:good], bad: [:bad])
|
78
|
+
)
|
57
79
|
end
|
58
80
|
end
|
59
81
|
|
60
82
|
describe '#bad?' do
|
61
|
-
it
|
62
|
-
|
83
|
+
it do
|
84
|
+
expect(subject).to receive(:bad).once.and_return([ ])
|
85
|
+
expect(subject.bad?).to be_falsey
|
86
|
+
end
|
87
|
+
it do
|
88
|
+
expect(subject).to receive(:bad).once.and_return([1])
|
89
|
+
expect(subject.bad?).to be_truthy
|
90
|
+
end
|
63
91
|
end
|
64
92
|
|
65
93
|
describe '#to_s' do
|
66
94
|
it 'Should return and empty string' do
|
67
|
-
subject.to_s.
|
95
|
+
expect(subject.to_s).to eq('')
|
68
96
|
end
|
69
97
|
|
70
98
|
it 'Should return all good numbers in a string comma separated' do
|
71
|
-
subject.
|
72
|
-
.
|
73
|
-
|
74
|
-
subject.to_s.
|
99
|
+
expect(subject).to receive(:good).
|
100
|
+
once.
|
101
|
+
and_return([1, 2, 3, 4])
|
102
|
+
expect(subject.to_s).to eq('1,2,3,4')
|
75
103
|
end
|
76
104
|
end
|
77
105
|
|
78
|
-
end
|
106
|
+
end
|
@@ -4,8 +4,8 @@ describe LocaSMS::RestClient do
|
|
4
4
|
describe '.initialize' do
|
5
5
|
context 'When giving proper initialization parameters' do
|
6
6
|
subject { LocaSMS::RestClient.new :url, :params }
|
7
|
-
it { subject.base_url.
|
8
|
-
it { subject.base_params.
|
7
|
+
it { expect(subject.base_url).to be(:url) }
|
8
|
+
it { expect(subject.base_params).to be(:params) }
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -16,31 +16,31 @@ describe LocaSMS::RestClient do
|
|
16
16
|
describe '#params_for' do
|
17
17
|
subject { LocaSMS::RestClient.new :url, { b1: 'X' } }
|
18
18
|
|
19
|
-
it{ subject.params_for(:action).
|
20
|
-
it{ subject.params_for(:action, p1: 10).
|
19
|
+
it { expect(subject.params_for(:action)).to eq({action: :action, b1: 'X'}) }
|
20
|
+
it { expect(subject.params_for(:action, p1: 10)).to eq({action: :action, b1: 'X', p1: 10}) }
|
21
21
|
end
|
22
22
|
|
23
23
|
describe '#parse_response' do
|
24
24
|
subject { LocaSMS::RestClient.new :url, :params }
|
25
25
|
|
26
26
|
it 'Should raise exception on invalid operation' do
|
27
|
-
|
27
|
+
expect { subject.parse_response(:action, '0:OPERACAO INVALIDA') }.to raise_error(LocaSMS::InvalidOperation)
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'Should raise exception on a failed response' do
|
31
|
-
|
31
|
+
expect { subject.parse_response(:action, '{"status":0,"data":null,"msg":"FALHA EPICA"}') }.to raise_error(LocaSMS::Exception, 'FALHA EPICA')
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'Should raise exception on a failed login attempt' do
|
35
|
-
|
35
|
+
expect { subject.parse_response(:action, '{"status":0,"data":null,"msg":"FALHA AO REALIZAR LOGIN"}') }.to raise_error(LocaSMS::InvalidLogin)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'Should return the non-json value as a json' do
|
39
|
-
subject.parse_response(:action, 'non-json return').
|
39
|
+
expect(subject.parse_response(:action, 'non-json return')).to eq({'status' => 1, 'data' => 'non-json return', "msg" => nil})
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'Should return a parsed json return' do
|
43
|
-
subject.parse_response(:action, '{"status":1,"data":28,"msg":null}').
|
43
|
+
expect(subject.parse_response(:action, '{"status":1,"data":28,"msg":null}')).to eq({'status' => 1, 'data' => 28, "msg" => nil})
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
metadata
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: locasms
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adilson Carvalho
|
8
|
+
- Leonardo Saraiva
|
9
|
+
- Marco Carvalho
|
8
10
|
autorequire:
|
9
11
|
bindir: bin
|
10
12
|
cert_chain: []
|
11
|
-
date:
|
13
|
+
date: 2015-03-10 00:00:00.000000000 Z
|
12
14
|
dependencies:
|
13
15
|
- !ruby/object:Gem::Dependency
|
14
16
|
name: bundler
|
@@ -30,42 +32,42 @@ dependencies:
|
|
30
32
|
requirements:
|
31
33
|
- - ~>
|
32
34
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
35
|
+
version: 10.4.2
|
34
36
|
type: :development
|
35
37
|
prerelease: false
|
36
38
|
version_requirements: !ruby/object:Gem::Requirement
|
37
39
|
requirements:
|
38
40
|
- - ~>
|
39
41
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
42
|
+
version: 10.4.2
|
41
43
|
- !ruby/object:Gem::Dependency
|
42
44
|
name: rspec
|
43
45
|
requirement: !ruby/object:Gem::Requirement
|
44
46
|
requirements:
|
45
47
|
- - ~>
|
46
48
|
- !ruby/object:Gem::Version
|
47
|
-
version: '2
|
49
|
+
version: '3.2'
|
48
50
|
type: :development
|
49
51
|
prerelease: false
|
50
52
|
version_requirements: !ruby/object:Gem::Requirement
|
51
53
|
requirements:
|
52
54
|
- - ~>
|
53
55
|
- !ruby/object:Gem::Version
|
54
|
-
version: '2
|
56
|
+
version: '3.2'
|
55
57
|
- !ruby/object:Gem::Dependency
|
56
58
|
name: fuubar
|
57
59
|
requirement: !ruby/object:Gem::Requirement
|
58
60
|
requirements:
|
59
61
|
- - ~>
|
60
62
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
63
|
+
version: 2.0.0
|
62
64
|
type: :development
|
63
65
|
prerelease: false
|
64
66
|
version_requirements: !ruby/object:Gem::Requirement
|
65
67
|
requirements:
|
66
68
|
- - ~>
|
67
69
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
70
|
+
version: 2.0.0
|
69
71
|
- !ruby/object:Gem::Dependency
|
70
72
|
name: guard
|
71
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,6 +169,8 @@ dependencies:
|
|
167
169
|
description: Cliente para o serviço de disparo de SMS da LocaSMS
|
168
170
|
email:
|
169
171
|
- lc.adilson@gmail.com
|
172
|
+
- vyper@maneh.org
|
173
|
+
- marco.carvalho.swasthya@gmail.com
|
170
174
|
executables: []
|
171
175
|
extensions: []
|
172
176
|
extra_rdoc_files: []
|
@@ -213,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
213
217
|
version: '0'
|
214
218
|
requirements: []
|
215
219
|
rubyforge_project:
|
216
|
-
rubygems_version: 2.
|
220
|
+
rubygems_version: 2.4.6
|
217
221
|
signing_key:
|
218
222
|
specification_version: 4
|
219
223
|
summary: Cliente para o serviço de disparo de SMS da LocaSMS
|