sms_aero 0.0.9 → 0.0.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47495d4e60d1b2a8904d61a84e717e2dd07f45e6
4
- data.tar.gz: d4f7bf8b15f966f5aa2995484caaa44a81e006f5
3
+ metadata.gz: 11a7f4bcfe9374590b97682e24add8d2a61ff4f1
4
+ data.tar.gz: f16f9215a7b84ab1a0906af3515be48461022012
5
5
  SHA512:
6
- metadata.gz: 4072ece391ff1ad9f1ebd508b9a89d39c70e6c95f9aecb4a6d85ddf08de1b10da031f5e94ec3a65601cd906199e00e367587ef6a17a288326e86be35a2324704
7
- data.tar.gz: 036f412146078b61ec6d1fee915d4a98686de50301938e9c7e7e7b57879e4972365510aff4a805fb7f0fb41e8b672b6c9ebb1a2711075a990de512aa8274f214
6
+ metadata.gz: aad6a6ba533cc42e810959fe7819f6c4d5b5f3d9b7c212b487ed5807007a27fce2d50d7a20433b334be9173b59db753f2737f3fa1ae6f7471a6f2c39c6ba74da
7
+ data.tar.gz: 16f5ee1c830ba19bcfa9b7879caeb83c1b798f711428dc97834906eba4bb7931385d6597a442046a472fe80ceb4d9bb2470c730379c1d7b4c244d67fdf08f394
data/.rubocop.yml CHANGED
@@ -12,6 +12,9 @@ Metrics/LineLength:
12
12
  - http
13
13
  - https
14
14
 
15
+ Layout/SpaceInLambdaLiteral:
16
+ Enabled: false
17
+
15
18
  Style/Lambda:
16
19
  Enabled: false
17
20
 
@@ -21,13 +24,13 @@ Style/StringLiterals:
21
24
  Style/FrozenStringLiteralComment:
22
25
  Enabled: false
23
26
 
24
- Style/Documentation:
27
+ Style/DateTime:
25
28
  Enabled: false
26
29
 
27
- Style/ClassAndModuleChildren:
30
+ Style/Documentation:
28
31
  Enabled: false
29
32
 
30
- Style/SpaceInLambdaLiteral:
33
+ Style/ClassAndModuleChildren:
31
34
  Enabled: false
32
35
 
33
36
  Style/PercentLiteralDelimiters:
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [0.0.10] - [2017-12-03]
8
+
9
+ ### Added
10
+ - checking existance & availability of phone number using methods `#hlr` and `#hlr_status id` (@Earendil95)
11
+
7
12
  ## [0.0.9] - [2017-06-23]
8
13
 
9
14
  ### Fixed
@@ -19,3 +24,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
19
24
  [dry-types]: https://github.com/dry-rb/dry-types
20
25
  [0.0.8]: https://github.com/nepalez/sms_aero/compare/v0.0.7...v0.0.8
21
26
  [0.0.9]: https://github.com/nepalez/sms_aero/compare/v0.0.8...v0.0.9
27
+ [0.0.10]: https://github.com/nepalez/sms_aero/compare/v0.0.8...v0.0.10
28
+
data/README.md CHANGED
@@ -127,3 +127,14 @@ answer = client.delete_phone phone: "+7 (999) 123-4567",
127
127
 
128
128
  answer.result # => "accepted"
129
129
  ```
130
+
131
+ ```ruby
132
+ # checking existance & availability of phone number
133
+ answer = client.hlr phone: "+7 (999) 123-4567"
134
+ answer.result # => "accepted"
135
+ id = answer.id # => "12345", id of request
136
+
137
+ answer = client.hlr_status id
138
+ answer.result # => "accepted"
139
+ answer.status # => any of :available, :unavailable or :nonexistent
140
+ ```
@@ -0,0 +1,32 @@
1
+ class SmsAero
2
+ HLR_STATUSES = {
3
+ 1 => :available,
4
+ 2 => :unavailable,
5
+ 3 => :nonexistent
6
+ }.freeze
7
+
8
+ operation :hlr do
9
+ documentation "https://smsaero.ru/api/description/#hlr"
10
+
11
+ path { "hlr" }
12
+
13
+ query { attribute :phone, Types::Phone }
14
+
15
+ response :success, 200, format: :json, model: Answer do
16
+ attribute :id, proc(&:to_s)
17
+ attribute :success, default: proc { id != "" }
18
+ end
19
+ end
20
+
21
+ operation :hlr_status do
22
+ documentation "https://smsaero.ru/api/description/#hlr"
23
+
24
+ path { "hlrStatus" }
25
+
26
+ query { attribute :id, Types::Coercible::String.constrained(filled: true) }
27
+
28
+ response :success, 200, format: :json, model: Answer do
29
+ attribute :status, -> (s) { HLR_STATUSES[s.to_i] }
30
+ end
31
+ end
32
+ end
@@ -13,7 +13,7 @@ module SmsAero::Types
13
13
  date = value.to_date if value.respond_to? :to_date
14
14
  date ||= ::Date.parse(value.to_s)
15
15
  date.strftime "%Y-%m-%d"
16
- rescue
16
+ rescue StandardError
17
17
  raise TypeError, "#{value.inspect} cannot be coerced to date"
18
18
  end
19
19
  end
@@ -9,7 +9,7 @@ module SmsAero::Types
9
9
  number = time.to_i
10
10
 
11
11
  number > ::Time.now.to_i ? number : raise(error)
12
- rescue
12
+ rescue StandardError
13
13
  raise error
14
14
  end
15
15
  end
data/sms_aero.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "sms_aero"
3
- gem.version = "0.0.9"
3
+ gem.version = "0.0.10"
4
4
  gem.author = "Andrew Kozin (nepalez)"
5
5
  gem.email = "andrew.kozin@gmail.com"
6
6
  gem.homepage = "https://github.com/nepalez/sms_aero"
@@ -0,0 +1,88 @@
1
+ describe SmsAero do
2
+ let(:settings) { { user: "LOGIN", password: "PASSWORD" } }
3
+ let(:client) { described_class.new(settings) }
4
+
5
+ before { stub_request(:any, //).to_return(body: answer.to_json) }
6
+
7
+ describe "#hlr" do
8
+ let(:params) { { phone: "+7(002)034-5678" } }
9
+ let(:answer) { { result: "accepted", id: 123 } }
10
+ let(:url) do
11
+ "https://gate.smsaero.ru/hlr?answer=json&user=LOGIN&" \
12
+ "password=319f4d26e3c536b5dd871bb2c52e3178&phone=70020345678"
13
+ end
14
+
15
+ subject { client.hlr params }
16
+
17
+ it "sends a request" do
18
+ subject
19
+ expect(a_request(:post, url)).to have_been_made
20
+ end
21
+
22
+ it "returns success" do
23
+ expect(subject).to be_kind_of SmsAero::Answer
24
+ expect(subject.result).to eq "accepted"
25
+ expect(subject.id).to eq "123"
26
+ end
27
+
28
+ context "with invalid phone" do
29
+ let(:params) { { phone: "123" } }
30
+
31
+ it "raises an exception" do
32
+ expect { subject }.to raise_error(TypeError, /123/)
33
+ end
34
+ end
35
+
36
+ context "without a phone" do
37
+ let(:params) { {} }
38
+
39
+ it "raises an exception" do
40
+ expect { subject }.to raise_error(ArgumentError)
41
+ end
42
+ end
43
+ end
44
+
45
+ describe "#hlr_status" do
46
+ let(:params) { { id: 1 } }
47
+ let(:status) { 1 }
48
+ let(:answer) { { result: "accepted", status: status } }
49
+ let(:url) do
50
+ "https://gate.smsaero.ru/hlrStatus?answer=json&user=LOGIN&" \
51
+ "password=319f4d26e3c536b5dd871bb2c52e3178&id=1"
52
+ end
53
+
54
+ subject { client.hlr_status params }
55
+
56
+ it "sends a request" do
57
+ subject
58
+ expect(a_request(:post, url)).to have_been_made
59
+ end
60
+
61
+ it "returns success" do
62
+ expect(subject).to be_kind_of SmsAero::Answer
63
+ expect(subject.result).to eq "accepted"
64
+ end
65
+
66
+ it "converts status to sym" do
67
+ expect(subject.status).to eq :available
68
+ end
69
+
70
+ context "other statuses" do
71
+ context "unavailable" do
72
+ let(:status) { 2 }
73
+
74
+ it "converts status to sym" do
75
+ expect(subject.status).to eq :unavailable
76
+ end
77
+ end
78
+
79
+ context "nonexistent" do
80
+ let(:status) { 3 }
81
+
82
+ it "converts status to sym" do
83
+ expect(subject.status).to eq :nonexistent
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -2,18 +2,18 @@ require "spec_helper"
2
2
 
3
3
  RSpec.describe SmsAero::Types::SignStatus do
4
4
  context "valid status:" do
5
- let(:values) { %w(accepted approved rejected pending) }
5
+ let(:items) { %w(accepted approved rejected pending) }
6
6
 
7
7
  it "returns a status" do
8
- values.each { |value| expect(described_class[value]).to eq value }
8
+ items.each { |item| expect(described_class[item]).to eq item }
9
9
  end
10
10
  end
11
11
 
12
12
  context "invalid status:" do
13
- let(:value) { "wrong" }
13
+ let(:item) { "wrong" }
14
14
 
15
15
  it "fails" do
16
- expect { described_class[value] }.to raise_error(StandardError, /wrong/)
16
+ expect { described_class[item] }.to raise_error(StandardError, /wrong/)
17
17
  end
18
18
  end
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_aero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin (nepalez)
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-23 00:00:00.000000000 Z
11
+ date: 2017-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-types
@@ -142,6 +142,7 @@ files:
142
142
  - lib/sms_aero/operations/check_tariff.rb
143
143
  - lib/sms_aero/operations/delete_group.rb
144
144
  - lib/sms_aero/operations/delete_phone.rb
145
+ - lib/sms_aero/operations/hlr.rb
145
146
  - lib/sms_aero/operations/send_sms.rb
146
147
  - lib/sms_aero/operations/send_to_group.rb
147
148
  - lib/sms_aero/types/birthday.rb
@@ -165,6 +166,7 @@ files:
165
166
  - spec/sms_aero/operations/check_tariff_spec.rb
166
167
  - spec/sms_aero/operations/delete_group_spec.rb
167
168
  - spec/sms_aero/operations/delete_phone_spec.rb
169
+ - spec/sms_aero/operations/hlr_spec.rb
168
170
  - spec/sms_aero/operations/send_sms_spec.rb
169
171
  - spec/sms_aero/operations/send_to_group_spec.rb
170
172
  - spec/sms_aero/types/birthday_spec.rb
@@ -194,7 +196,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
196
  version: '0'
195
197
  requirements: []
196
198
  rubyforge_project:
197
- rubygems_version: 2.6.4
199
+ rubygems_version: 2.6.14
198
200
  signing_key:
199
201
  specification_version: 4
200
202
  summary: HTTP(s) client to SMS Aero API
@@ -211,6 +213,7 @@ test_files:
211
213
  - spec/sms_aero/operations/check_tariff_spec.rb
212
214
  - spec/sms_aero/operations/delete_group_spec.rb
213
215
  - spec/sms_aero/operations/delete_phone_spec.rb
216
+ - spec/sms_aero/operations/hlr_spec.rb
214
217
  - spec/sms_aero/operations/send_sms_spec.rb
215
218
  - spec/sms_aero/operations/send_to_group_spec.rb
216
219
  - spec/sms_aero/types/birthday_spec.rb