sms_aero 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4085b518c9a9df7ed562ce3b9b4af7e9bafc4d18
4
- data.tar.gz: c4f2d81c67a6bf2085b4013b160bf03743e6eaf2
3
+ metadata.gz: ee41b1be5aeaa61ce83c74ca4e3605d45f981c4e
4
+ data.tar.gz: bfd499ee848d4ed0848c80d5bd0920055518c9d6
5
5
  SHA512:
6
- metadata.gz: 88343afc18f9b4018cf8bdf9f45ac1f57a25f838ca41e7734221768bdabbec6a85791272fb8c1e84c5401ebbc7529927b40dfd191bf9630515b2c5cfb2aee0a9
7
- data.tar.gz: ca6cc12bd5f7ba6b50b8f4d239a32726e0d61b6d8f0d4b733edc18adf1f5c9f63ec1aacd7b91c2cc986a64801bca2810dea2eacfd41b8f576d8770d9a9f55937
6
+ metadata.gz: 8bb5adc819ed5576a3df4de08db3e9f72376c1446dfa53b6eb70fc5f14bf1363cf4a23043670d185511a9e997c01638f97fd4a2f1f94e28c8c8fb0711ad279d9
7
+ data.tar.gz: e72f8ea396e6c79fcead9a9232081976a67e38f579db861cb0e9a59fe62ee53746dc13e812acabaea196344e195d17b82af2f13369f730e12c7c2d9c2969b95b
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
@@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
 
8
+ ## [0.1.2] - [2017-12-03]
9
+
10
+ ### Added
11
+ - checking existance & availability of phone number using methods `#hlr` and `#hlr_status id` (@Earendil95)
12
+
8
13
  ## [0.1.1] - [2017-09-02]
9
14
 
10
15
  ### Changed
@@ -43,3 +48,4 @@ Some changes in the interface has been made as well.
43
48
  [0.0.9]: https://github.com/nepalez/sms_aero/compare/v0.0.8...v0.0.9
44
49
  [0.1.0]: https://github.com/nepalez/sms_aero/compare/v0.0.9...v0.1.0
45
50
  [0.1.1]: https://github.com/nepalez/sms_aero/compare/v0.1.0...v0.1.1
51
+ [0.1.2]: https://github.com/nepalez/sms_aero/compare/v0.1.0...v0.1.2
data/README.md CHANGED
@@ -123,6 +123,17 @@ answer = client.delete_phone phone: "+7 (999) 123-4567",
123
123
  answer.result # => "accepted"
124
124
  ```
125
125
 
126
+ ```ruby
127
+ # checking existance & availability of phone number
128
+ answer = client.hlr phone: "+7 (999) 123-4567"
129
+ answer.result # => "accepted"
130
+ id = answer.id # => "12345", id of request
131
+
132
+ answer = client.hlr_status id
133
+ answer.result # => "accepted"
134
+ answer.status # => any of :available, :unavailable or :nonexistent
135
+ ```
136
+
126
137
  [sms-aero]: https://smsaero.ru/api/description/
127
138
  [codeclimate-badger]: https://img.shields.io/codeclimate/github/nepalez/sms_aero.svg?style=flat
128
139
  [codeclimate]: https://codeclimate.com/github/nepalez/sms_aero
@@ -6,7 +6,7 @@ class SmsAero::Birthday < String
6
6
  def initialize(value)
7
7
  date = value.respond_to?(:to_date) ? value.to_date : Date.parse(value)
8
8
  super date.strftime "%Y-%m-%d"
9
- rescue
9
+ rescue StandardError
10
10
  raise "#{value} is not a valid value for a birthday"
11
11
  end
12
12
  end
@@ -10,7 +10,7 @@ class SmsAero::Future < String
10
10
  number = time.to_i
11
11
  return super(number.to_s) if number > ::Time.now.to_i
12
12
  raise "#{value} is a time in the past, not in the future"
13
- rescue
13
+ rescue StandardError
14
14
  raise "#{value} is not a valid time"
15
15
  end
16
16
  end
@@ -0,0 +1,11 @@
1
+ module SmsAero::HlrStatus
2
+ extend SmsAero::Callable
3
+
4
+ def self.new(value)
5
+ case value.to_i
6
+ when 1 then :available
7
+ when 2 then :unavailable
8
+ else :nonexistent
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ class SmsAero
2
+ class Response::WithHlr < Response
3
+ option :status, HlrStatus
4
+ end
5
+ end
@@ -1,8 +1,8 @@
1
1
  class SmsAero::Response
2
2
  extend Dry::Initializer
3
3
  extend SmsAero::Optional
4
- option :reason, proc(&:to_s), default: proc { nil }
5
- option :result, proc(&:strip), default: -> { "accepted" }
4
+ option :reason, proc(&:to_s), default: proc { nil }
5
+ option :result, proc(&:strip), default: -> { "accepted" }
6
6
 
7
7
  def success?
8
8
  result == "accepted"
@@ -27,4 +27,5 @@ class SmsAero::Response
27
27
  require_relative "response/with_senders"
28
28
  require_relative "response/with_statuses"
29
29
  require_relative "response/with_tariff"
30
+ require_relative "response/with_hlr"
30
31
  end
data/lib/sms_aero.rb CHANGED
@@ -14,6 +14,7 @@ class SmsAero < Evil::Client
14
14
  require_relative "sms_aero/group"
15
15
  require_relative "sms_aero/channel"
16
16
  require_relative "sms_aero/tariff"
17
+ require_relative "sms_aero/hlr_status"
17
18
  require_relative "sms_aero/response"
18
19
 
19
20
  option :user, FilledString
@@ -113,7 +114,7 @@ class SmsAero < Evil::Client
113
114
  option :group, FilledString
114
115
 
115
116
  path "delgroup"
116
- query { options.select { |key| key == :group } }
117
+ query { { group: group } }
117
118
  end
118
119
 
119
120
  operation :delete_phone do
@@ -121,7 +122,7 @@ class SmsAero < Evil::Client
121
122
  option :group, FilledString, optional: true
122
123
 
123
124
  path "delphone"
124
- query { options.select { |key| %i[phone group].include? key } }
125
+ query { options.slice(:phone, :group) }
125
126
  end
126
127
 
127
128
  operation :send_sms do
@@ -140,4 +141,22 @@ class SmsAero < Evil::Client
140
141
 
141
142
  response(200) { |*res| Response::WithId.build(*res) }
142
143
  end
144
+
145
+ operation :hlr do
146
+ option :phone, Phone
147
+
148
+ path "hlr"
149
+ query { { phone: phone } }
150
+
151
+ response(200) { |*res| Response::WithId.build(*res) }
152
+ end
153
+
154
+ operation :hlr_status do
155
+ option :id, FilledString
156
+
157
+ path "hlrStatus"
158
+ query { { id: id } }
159
+
160
+ response(200) { |*res| Response::WithHlr.build(*res) }
161
+ end
143
162
  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.1.1"
3
+ gem.version = "0.1.2"
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"
@@ -17,6 +17,6 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_development_dependency "rake", ">= 10"
19
19
  gem.add_development_dependency "rspec", "~> 3.0"
20
- gem.add_development_dependency "rubocop", "~> 0.42"
20
+ gem.add_development_dependency "rubocop", "~> 0.48"
21
21
  gem.add_development_dependency "webmock", "~> 2.1"
22
22
  end
@@ -0,0 +1,86 @@
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.result).to eq "accepted"
24
+ expect(subject.id).to eq "123"
25
+ end
26
+
27
+ context "with invalid phone" do
28
+ let(:params) { { phone: "123" } }
29
+
30
+ it "raises an exception" do
31
+ expect { subject }.to raise_error(Evil::Client::ValidationError, /123/)
32
+ end
33
+ end
34
+
35
+ context "without a phone" do
36
+ let(:params) { {} }
37
+
38
+ it "raises an exception" do
39
+ expect { subject }.to raise_error(ArgumentError)
40
+ end
41
+ end
42
+ end
43
+
44
+ describe "#hlr_status" do
45
+ let(:params) { { id: 1 } }
46
+ let(:status) { 1 }
47
+ let(:answer) { { result: "accepted", status: status } }
48
+ let(:url) do
49
+ "https://gate.smsaero.ru/hlrStatus?answer=json&user=LOGIN&" \
50
+ "password=319f4d26e3c536b5dd871bb2c52e3178&id=1"
51
+ end
52
+
53
+ subject { client.hlr_status params }
54
+
55
+ it "sends a request" do
56
+ subject
57
+ expect(a_request(:post, url)).to have_been_made
58
+ end
59
+
60
+ it "returns success" do
61
+ expect(subject.result).to eq "accepted"
62
+ end
63
+
64
+ it "converts status to sym" do
65
+ expect(subject.status).to eq :available
66
+ end
67
+
68
+ context "other statuses" do
69
+ context "unavailable" do
70
+ let(:status) { 2 }
71
+
72
+ it "converts status to sym" do
73
+ expect(subject.status).to eq :unavailable
74
+ end
75
+ end
76
+
77
+ context "nonexistent" do
78
+ let(:status) { 3 }
79
+
80
+ it "converts status to sym" do
81
+ expect(subject.status).to eq :nonexistent
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
metadata CHANGED
@@ -1,86 +1,86 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sms_aero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kozin (nepalez)
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-02 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
+ name: evil-client
14
15
  requirement: !ruby/object:Gem::Requirement
15
16
  requirements:
16
17
  - - "~>"
17
18
  - !ruby/object:Gem::Version
18
19
  version: '2.0'
19
- name: evil-client
20
- prerelease: false
21
20
  type: :runtime
21
+ prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
+ name: rake
28
29
  requirement: !ruby/object:Gem::Requirement
29
30
  requirements:
30
31
  - - ">="
31
32
  - !ruby/object:Gem::Version
32
33
  version: '10'
33
- name: rake
34
- prerelease: false
35
34
  type: :development
35
+ prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
+ name: rspec
42
43
  requirement: !ruby/object:Gem::Requirement
43
44
  requirements:
44
45
  - - "~>"
45
46
  - !ruby/object:Gem::Version
46
47
  version: '3.0'
47
- name: rspec
48
- prerelease: false
49
48
  type: :development
49
+ prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
55
  - !ruby/object:Gem::Dependency
56
+ name: rubocop
56
57
  requirement: !ruby/object:Gem::Requirement
57
58
  requirements:
58
59
  - - "~>"
59
60
  - !ruby/object:Gem::Version
60
- version: '0.42'
61
- name: rubocop
62
- prerelease: false
61
+ version: '0.48'
63
62
  type: :development
63
+ prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0.42'
68
+ version: '0.48'
69
69
  - !ruby/object:Gem::Dependency
70
+ name: webmock
70
71
  requirement: !ruby/object:Gem::Requirement
71
72
  requirements:
72
73
  - - "~>"
73
74
  - !ruby/object:Gem::Version
74
75
  version: '2.1'
75
- name: webmock
76
- prerelease: false
77
76
  type: :development
77
+ prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.1'
83
- description:
83
+ description:
84
84
  email: andrew.kozin@gmail.com
85
85
  executables: []
86
86
  extensions: []
@@ -107,11 +107,13 @@ files:
107
107
  - lib/sms_aero/filled_string.rb
108
108
  - lib/sms_aero/future.rb
109
109
  - lib/sms_aero/group.rb
110
+ - lib/sms_aero/hlr_status.rb
110
111
  - lib/sms_aero/optional.rb
111
112
  - lib/sms_aero/phone.rb
112
113
  - lib/sms_aero/response.rb
113
114
  - lib/sms_aero/response/with_balance.rb
114
115
  - lib/sms_aero/response/with_groups.rb
116
+ - lib/sms_aero/response/with_hlr.rb
115
117
  - lib/sms_aero/response/with_id.rb
116
118
  - lib/sms_aero/response/with_senders.rb
117
119
  - lib/sms_aero/response/with_statuses.rb
@@ -135,13 +137,14 @@ files:
135
137
  - spec/operations/check_tariff_spec.rb
136
138
  - spec/operations/delete_group_spec.rb
137
139
  - spec/operations/delete_phone_spec.rb
140
+ - spec/operations/hlr_spec.rb
138
141
  - spec/operations/send_sms_spec.rb
139
142
  - spec/spec_helper.rb
140
143
  homepage: https://github.com/nepalez/sms_aero
141
144
  licenses:
142
145
  - MIT
143
146
  metadata: {}
144
- post_install_message:
147
+ post_install_message:
145
148
  rdoc_options: []
146
149
  require_paths:
147
150
  - lib
@@ -156,9 +159,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  - !ruby/object:Gem::Version
157
160
  version: '0'
158
161
  requirements: []
159
- rubyforge_project:
160
- rubygems_version: 2.6.4
161
- signing_key:
162
+ rubyforge_project:
163
+ rubygems_version: 2.6.14
164
+ signing_key:
162
165
  specification_version: 4
163
166
  summary: HTTP(s) client to SMS Aero API
164
167
  test_files:
@@ -179,5 +182,6 @@ test_files:
179
182
  - spec/operations/check_tariff_spec.rb
180
183
  - spec/operations/delete_group_spec.rb
181
184
  - spec/operations/delete_phone_spec.rb
185
+ - spec/operations/hlr_spec.rb
182
186
  - spec/operations/send_sms_spec.rb
183
187
  - spec/spec_helper.rb