sms_aero2 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0543afba5dd6255815003bf2e757620ee30254f57f1885a7465836b8c5f4e36f
4
+ data.tar.gz: 29a95da07d357cbae6902846f7ff26ec4540573d0241111e3a09fe41c9459f3c
5
+ SHA512:
6
+ metadata.gz: a65af07462c9445a60db8c0515e6322173ded4337a80b9b4cba7da8de871dfd10e77118b69cacd299e7deb1053ff827384b74eed046ee7ad913a181ccf510b26
7
+ data.tar.gz: d5e29855953d29ffb06f7654ec3b047a49a0c60f6285a09de3eb19da703c2f83d323b2885617ca09125a77775407fc940f422ce370793f6f0d8759d8b854984b
@@ -0,0 +1,38 @@
1
+ name: Ruby
2
+
3
+ on:
4
+ push:
5
+ branches: [ master ]
6
+ pull_request:
7
+ branches: [ master ]
8
+
9
+ jobs:
10
+ rspec:
11
+ runs-on: ubuntu-latest
12
+ env:
13
+ BUNDLE_JOBS: 4
14
+ BUNDLE_RETRY: 3
15
+ CI: true
16
+ strategy:
17
+ fail-fast: false
18
+ matrix:
19
+ ruby: ["3.1", "3.2", "3.3"]
20
+ steps:
21
+ - uses: actions/checkout@v2
22
+ - uses: actions/cache@v1
23
+ with:
24
+ path: /home/runner/bundle
25
+ key: bundle-${{ matrix.ruby }}-${{ hashFiles('**/*.gemspec') }}
26
+ restore-keys: |
27
+ bundle-${{ matrix.ruby }}-
28
+ - uses: ruby/setup-ruby@v1
29
+ with:
30
+ ruby-version: ${{ matrix.ruby }}
31
+ - name: Bundle install
32
+ run: |
33
+ bundle config path /home/runner/bundle
34
+ bundle install
35
+ bundle update
36
+ - name: Run RSpec
37
+ run: |
38
+ bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-3.2.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.2.0] - 2024-08-29
6
+
7
+ ### Added
8
+
9
+ - Ruby 3 support, thanks to [Sergei](https://github.com/zumkorn)
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at skiline.alex@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sms_aero2.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,57 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sms_aero2 (0.1.2)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ addressable (2.8.7)
10
+ public_suffix (>= 2.0.2, < 7.0)
11
+ bigdecimal (3.1.8)
12
+ coderay (1.1.3)
13
+ crack (1.0.0)
14
+ bigdecimal
15
+ rexml
16
+ diff-lcs (1.5.1)
17
+ hashdiff (1.1.1)
18
+ method_source (1.1.0)
19
+ pry (0.14.2)
20
+ coderay (~> 1.1)
21
+ method_source (~> 1.0)
22
+ public_suffix (6.0.1)
23
+ rake (13.2.1)
24
+ rexml (3.3.6)
25
+ strscan
26
+ rspec (3.13.0)
27
+ rspec-core (~> 3.13.0)
28
+ rspec-expectations (~> 3.13.0)
29
+ rspec-mocks (~> 3.13.0)
30
+ rspec-core (3.13.0)
31
+ rspec-support (~> 3.13.0)
32
+ rspec-expectations (3.13.2)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-mocks (3.13.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-support (3.13.1)
39
+ strscan (3.1.0)
40
+ webmock (3.23.1)
41
+ addressable (>= 2.8.0)
42
+ crack (>= 0.3.2)
43
+ hashdiff (>= 0.4.0, < 2.0.0)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ bundler (~> 2.5.10)
50
+ pry (~> 0.14.2)
51
+ rake (~> 13.2.1)
52
+ rspec (~> 3.13)
53
+ sms_aero2!
54
+ webmock (>= 3.23.1)
55
+
56
+ BUNDLED WITH
57
+ 2.5.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Alexander Shvaykin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # SmsAero2
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'sms_aero2'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install sms_aero2
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ client = SmsAero2::Client.new(login: 'some_email@example.com', token: 'some_token', logger: SomeLogger)
23
+
24
+ client.send_sms(to: 79998887766, from: 'SomeCompany', text:'Hello World!', channel: :international)
25
+ client.hlr_status(id: '1234')
26
+ client.hlr(phone: '79998887766')
27
+
28
+ ```
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sms_aero2"
5
+
6
+ require "pry"
7
+ Pry.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,3 @@
1
+ module SmsAero2
2
+ class Error < StandardError; end
3
+ end
@@ -0,0 +1,9 @@
1
+ module SmsAero2
2
+ class HlrOperation < Operation
3
+ private
4
+
5
+ def result_class
6
+ SmsAero2::HlrResult
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module SmsAero2
2
+ class HlrResult < Result
3
+ def id
4
+ data.fetch('id')
5
+ end
6
+
7
+ def status
8
+ statuses[data.fetch('hlrStatus') - 1]
9
+ end
10
+
11
+ private
12
+
13
+ def statuses
14
+ [:available, :unavailable, :not_exists, :in_work]
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,26 @@
1
+ module SmsAero2
2
+ class Operation
3
+ BASE_URL = 'https://gate.smsaero.ru/v2/'.freeze
4
+ attr_reader :request, :action_path, :params
5
+
6
+ def initialize(request, action_path = '', **params)
7
+ @request = request
8
+ @action_path = action_path
9
+ @params = params
10
+ end
11
+
12
+ def call
13
+ result_class.new(request.call(url, **params))
14
+ end
15
+
16
+ private
17
+
18
+ def url
19
+ URI.join(BASE_URL, action_path)
20
+ end
21
+
22
+ def result_class
23
+ SmsAero2::Result
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,56 @@
1
+ require 'json'
2
+
3
+ module SmsAero2
4
+ class Request
5
+ class HttpError < SmsAero2::Error
6
+ attr_accessor :status
7
+ end
8
+ class InvalidResponse < SmsAero2::Error; end
9
+
10
+ attr_reader :client, :logger
11
+
12
+ def initialize(client)
13
+ @client = client
14
+ @logger = client.logger
15
+ end
16
+
17
+ def call(url, **params)
18
+ uri = URI(url)
19
+ uri.query = URI.encode_www_form(params)
20
+
21
+ response = send_request(uri)
22
+ logger&.info(
23
+ "Send http request to GET #{url} with params: #{params}"
24
+ )
25
+ response_body(response)
26
+
27
+ rescue SmsAero2::Error => e
28
+ logger&.error("http request to #{url} with params: #{params} is failed message: #{e.message}")
29
+ raise e
30
+ end
31
+
32
+ private
33
+
34
+ def send_request(uri)
35
+ request = Net::HTTP::Get.new(uri)
36
+ request.basic_auth(client.login, client.token)
37
+ request['Content-Type'] = 'application/json'
38
+ Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
39
+ http.request(request)
40
+ end
41
+ end
42
+
43
+ def response_body(response)
44
+ body = response.read_body
45
+ if response.code.to_s.match?(/2|4[0-9]{2}/)
46
+ JSON.parse(body)
47
+ else
48
+ error = HttpError.new("server return error code: #{response.code} response: #{body}")
49
+ error.status = response.code
50
+ raise error
51
+ end
52
+ rescue JSON::ParserError
53
+ raise InvalidResponse, "server return invalid response: #{body}"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,21 @@
1
+ module SmsAero2
2
+ class Result
3
+ attr_reader :response
4
+
5
+ def initialize(response)
6
+ @response = response
7
+ end
8
+
9
+ def success?
10
+ response.fetch('success')
11
+ end
12
+
13
+ def reason
14
+ response.fetch('message')
15
+ end
16
+
17
+ def data
18
+ response.fetch('data')
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SmsAero2
2
+ VERSION = "0.2.0"
3
+ end
data/lib/sms_aero2.rb ADDED
@@ -0,0 +1,53 @@
1
+ require 'logger'
2
+ require "sms_aero2/error"
3
+ require "sms_aero2/version"
4
+ require "sms_aero2/request"
5
+ require "sms_aero2/result"
6
+ require "sms_aero2/hlr_result"
7
+ require "sms_aero2/operation"
8
+ require "sms_aero2/hlr_operation"
9
+
10
+ module SmsAero2
11
+ class Client
12
+ attr_accessor :login, :token, :logger
13
+
14
+ def initialize(login:, token:, logger: nil)
15
+ @login = login
16
+ @token = token
17
+ @logger = logger
18
+ end
19
+
20
+ # channel values:
21
+ # 'info' Info signature for all operators
22
+ # 'digital' Digital channel sending (only permitted transaction flow)
23
+ # 'international' International delivery (Operators of Russia, Kazakhstan, Ukraine and Belarus)
24
+ # 'direct' Advertising channel send message free letter signature.
25
+ # 'service' Service channel for sending service SMS according to the approved template
26
+ # with a paid signature of the sender.
27
+ def send_sms(to:, from:, text:, channel:, **options)
28
+ path = options[:testsend] ? 'sms/testsend' : 'sms/send'
29
+ if %w[info digital international direct service].include?(channel.to_s)
30
+ SmsAero2::Operation.new(
31
+ request, path,
32
+ number: to, sign: from, text: text, channel: channel.upcase, **options
33
+ ).call
34
+ else
35
+ raise ArgumentError, "invalid channel value, see documentation"
36
+ end
37
+ end
38
+
39
+ def hlr_status(id:)
40
+ SmsAero2::HlrOperation.new(request, 'hlr/status', id: id).call
41
+ end
42
+
43
+ def hlr(phone:)
44
+ SmsAero2::HlrOperation.new(request, 'hlr/check', number: phone).call
45
+ end
46
+
47
+ private
48
+
49
+ def request
50
+ @request ||= SmsAero2::Request.new(self)
51
+ end
52
+ end
53
+ end
data/sms_aero2.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "sms_aero2/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sms_aero2"
7
+ spec.version = SmsAero2::VERSION
8
+ spec.authors = ["Alexander Shvaykin"]
9
+ spec.email = ["skiline.alex@gmail.com"]
10
+
11
+ spec.summary = %q{Simple gem for smsaero.ru API.}
12
+ spec.homepage = "https://teachbase.ru"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["homepage_uri"] = spec.homepage
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 2.5.10"
27
+ spec.add_development_dependency "rake", "~> 13.2.1"
28
+ spec.add_development_dependency "rspec", "~> 3.13"
29
+ spec.add_development_dependency "webmock", ">= 3.23.1"
30
+ spec.add_development_dependency "pry", "~> 0.14.2"
31
+ end
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sms_aero2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Shvaykin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-08-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.5.10
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.5.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 13.2.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 13.2.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.13'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.13'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 3.23.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 3.23.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.14.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.14.2
83
+ description:
84
+ email:
85
+ - skiline.alex@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".github/workflows/ruby.yml"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".ruby-version"
94
+ - CHANGELOG.md
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - Gemfile.lock
98
+ - LICENSE.txt
99
+ - README.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - lib/sms_aero2.rb
104
+ - lib/sms_aero2/error.rb
105
+ - lib/sms_aero2/hlr_operation.rb
106
+ - lib/sms_aero2/hlr_result.rb
107
+ - lib/sms_aero2/operation.rb
108
+ - lib/sms_aero2/request.rb
109
+ - lib/sms_aero2/result.rb
110
+ - lib/sms_aero2/version.rb
111
+ - sms_aero2.gemspec
112
+ homepage: https://teachbase.ru
113
+ licenses:
114
+ - MIT
115
+ metadata:
116
+ homepage_uri: https://teachbase.ru
117
+ post_install_message:
118
+ rdoc_options: []
119
+ require_paths:
120
+ - lib
121
+ required_ruby_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ required_rubygems_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ requirements: []
132
+ rubygems_version: 3.5.17
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Simple gem for smsaero.ru API.
136
+ test_files: []