rostelecom_m2m 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +21 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +12 -0
- data/lib/rostelecom_m2m.rb +64 -0
- data/rostelecom_m2m.gemspec +29 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ab11a4cdc48ddae6f26b52682d6f9eb057a07c17802f2f62270ad356f4e6ed1b
|
4
|
+
data.tar.gz: 1b3744f476a9b9fa79bbdb2007900d6215d0796273736abe93c5b95f4d39c360
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 999630969b223a1f13f9284d5799ace6f0a529c595cb5a6eb2f8636e4f78d8b80d255051917b3ab4288000cb32056385ba72c4e446b51c19d7e68ab0bcd00948
|
7
|
+
data.tar.gz: 964e25801fef1943289f2c0d53290cc7dc617f42b70000a4fbb23fe1ef5596e7fec912bbb00695e006e6b23571630ca837f264e41143df03dc9665edbcc9e727
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
|
14
|
+
Style/Documentation:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Layout/LineLength:
|
21
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Vladislav Kostikov
|
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,40 @@
|
|
1
|
+
# Ростелеком M2M
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/rostelecom_m2m.svg)](https://badge.fury.io/rb/rostelecom_m2m)
|
3
|
+
|
4
|
+
Библиотека для взаимодействия с Ростелеком M2M.\
|
5
|
+
[Официальный сайт](https://m2m.ru/)
|
6
|
+
|
7
|
+
## Установка
|
8
|
+
|
9
|
+
Добавьте в ваш Gemfile:
|
10
|
+
|
11
|
+
`gem "rostelecom_m2m"`
|
12
|
+
|
13
|
+
И выполните команду:
|
14
|
+
|
15
|
+
`bundle install`
|
16
|
+
|
17
|
+
Или установите с помощью команды:
|
18
|
+
|
19
|
+
`gem install rostelecom_m2m`
|
20
|
+
|
21
|
+
## Использование
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
# Авторизация и получение токена.
|
25
|
+
auth_data = {
|
26
|
+
username: "M2M_user",
|
27
|
+
password: "pass1234",
|
28
|
+
auth_token: "",
|
29
|
+
debug: true
|
30
|
+
}
|
31
|
+
client = RostelecomM2M.new(auth_data)
|
32
|
+
response = client.post("/tokens-stub-m2m/get", auth_data)
|
33
|
+
auth_token = response.dig(:message, "authToken")
|
34
|
+
|
35
|
+
# Сохранение токена для последующих запросов.
|
36
|
+
client.auth_token = auth_token
|
37
|
+
|
38
|
+
# Получение списка сим-карт.
|
39
|
+
sim_cards = client.post("/M2M/SIMCards/search", authToken: client.auth_token).dig(:message)
|
40
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "net/http"
|
5
|
+
require "uri"
|
6
|
+
|
7
|
+
class RostelecomM2M
|
8
|
+
attr_accessor :login, :password, :auth_token, :debug
|
9
|
+
|
10
|
+
VERSION = "1.0.0"
|
11
|
+
|
12
|
+
def initialize(parameters = {})
|
13
|
+
self.login = parameters[:login]
|
14
|
+
self.password = parameters[:password]
|
15
|
+
self.auth_token = parameters[:auth_token]
|
16
|
+
self.debug = parameters[:debug] || false
|
17
|
+
end
|
18
|
+
|
19
|
+
def get(url, parameters = {})
|
20
|
+
uri = URI.parse("https://m2m.rt.ru/openapi/v1#{url}")
|
21
|
+
uri.query = URI.encode_www_form(parameters)
|
22
|
+
request = Net::HTTP::Get.new(uri)
|
23
|
+
|
24
|
+
validate_response(make_request(request, uri))
|
25
|
+
end
|
26
|
+
|
27
|
+
def post(url, parameters = {})
|
28
|
+
uri = URI.parse("https://m2m.rt.ru/openapi/v1#{url}")
|
29
|
+
uri.query = URI.encode_www_form(parameters)
|
30
|
+
request = Net::HTTP::Post.new(uri)
|
31
|
+
|
32
|
+
validate_response(make_request(request, uri))
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def make_request(request, uri)
|
38
|
+
print_debug_message(request) if debug
|
39
|
+
|
40
|
+
req_options = {
|
41
|
+
use_ssl: uri.scheme == "https"
|
42
|
+
}
|
43
|
+
|
44
|
+
Net::HTTP.start(uri.hostname, uri.port, req_options) do |http|
|
45
|
+
http.request(request)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_response(response)
|
50
|
+
case response.code.to_i
|
51
|
+
when 200, 204
|
52
|
+
{ error: false, message: JSON.parse(response.body) }
|
53
|
+
else
|
54
|
+
{ error: true, message: JSON.parse(response.body) }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_debug_message(request)
|
59
|
+
puts "================ ROSTELECOM REQUEST ================"
|
60
|
+
puts "Request: #{request.method} #{request.uri.host + request.uri.path}"
|
61
|
+
puts "Parameters: #{URI.decode_www_form(request.uri.query).to_h}"
|
62
|
+
puts "================================================"
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "rostelecom_m2m"
|
5
|
+
spec.version = "1.0.0"
|
6
|
+
spec.authors = ["Vladislav Kostikov"]
|
7
|
+
spec.email = ["vlad@kostikov.ru"]
|
8
|
+
|
9
|
+
spec.summary = "Rostelecom M2M"
|
10
|
+
spec.homepage = "https://github.com/vladkostikov/rostelecom_m2m"
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = ">= 2.6.0"
|
13
|
+
|
14
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
15
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
16
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
20
|
+
spec.files = Dir.chdir(__dir__) do
|
21
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
22
|
+
(File.expand_path(f) == __FILE__) ||
|
23
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor Gemfile])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rostelecom_m2m
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vladislav Kostikov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- vlad@kostikov.ru
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".rspec"
|
21
|
+
- ".rubocop.yml"
|
22
|
+
- CHANGELOG.md
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/rostelecom_m2m.rb
|
27
|
+
- rostelecom_m2m.gemspec
|
28
|
+
homepage: https://github.com/vladkostikov/rostelecom_m2m
|
29
|
+
licenses:
|
30
|
+
- MIT
|
31
|
+
metadata:
|
32
|
+
homepage_uri: https://github.com/vladkostikov/rostelecom_m2m
|
33
|
+
source_code_uri: https://github.com/vladkostikov/rostelecom_m2m
|
34
|
+
rubygems_mfa_required: 'true'
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 2.6.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.4.21
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: Rostelecom M2M
|
54
|
+
test_files: []
|