beeline_iot 1.0.0
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/LICENSE.txt +22 -0
- data/README.md +95 -0
- data/Rakefile +12 -0
- data/lib/beeline_iot/client.rb +115 -0
- data/lib/beeline_iot/error.rb +6 -0
- data/lib/beeline_iot/methods.rb +21 -0
- data/lib/beeline_iot/version.rb +5 -0
- data/lib/beeline_iot.rb +25 -0
- metadata +98 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: dff332f70983247cdca25af086bad6f04ab8ea349bdbea8cae6a14541c2391c5
|
|
4
|
+
data.tar.gz: c24d7a751c0ed7a050759026c7a4243a4547316374e5565e0a2f81c25874da03
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: bebaca511a9caaca1a5111d6d154be94c27a9618845812b0998f7c4b51ac88ae10327d069feb9961ced7f0ffc87dd87c6b416116145a5e04c75c81d018b0e035
|
|
7
|
+
data.tar.gz: e3149709e0b3ee0eae1fd2323c4c34de6e38ad3c5a112cc84f20c3b8380ca9d768818fcb6fccd1a4c0d4824c7f90eacd157cabb5f5999688323cc359065ef76f
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
TargetRubyVersion: 2.6
|
|
3
|
+
|
|
4
|
+
Style/StringLiterals:
|
|
5
|
+
Enabled: true
|
|
6
|
+
EnforcedStyle: double_quotes
|
|
7
|
+
|
|
8
|
+
Style/StringLiteralsInInterpolation:
|
|
9
|
+
Enabled: true
|
|
10
|
+
EnforcedStyle: double_quotes
|
|
11
|
+
|
|
12
|
+
Style/Documentation:
|
|
13
|
+
Enabled: false
|
|
14
|
+
|
|
15
|
+
Layout/LineLength:
|
|
16
|
+
Max: 120
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2024 Vladislav Kostikov
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Beeline IoT M2M
|
|
2
|
+
[](https://badge.fury.io/rb/beeline_iot)
|
|
3
|
+
|
|
4
|
+
Библиотека для взаимодействия с Центром Управления IoT M2M Билайн Бизнес.
|
|
5
|
+
[Официальный сайт](https://iot.beeline.ru/)
|
|
6
|
+
[Официальная документация](https://iot.beeline.ru/#/m2m/api_guide)
|
|
7
|
+
|
|
8
|
+
## Установка
|
|
9
|
+
|
|
10
|
+
Добавьте в ваш Gemfile:
|
|
11
|
+
|
|
12
|
+
`gem "novofon"`
|
|
13
|
+
|
|
14
|
+
И выполните команду:
|
|
15
|
+
|
|
16
|
+
`bundle install`
|
|
17
|
+
|
|
18
|
+
Или установите с помощью команды:
|
|
19
|
+
|
|
20
|
+
`gem install novofon`
|
|
21
|
+
|
|
22
|
+
## Использование
|
|
23
|
+
|
|
24
|
+
C помощью модуля:
|
|
25
|
+
|
|
26
|
+
```ruby
|
|
27
|
+
# Авторизация.
|
|
28
|
+
auth_data = {
|
|
29
|
+
username: "e1xx",
|
|
30
|
+
password: "qweqwe",
|
|
31
|
+
client_id: "3",
|
|
32
|
+
client_secret: "7LWdlTpx9PYrqUz0sy28mlFH1pt38fPgqOkfkzBc",
|
|
33
|
+
grant_type: "password"
|
|
34
|
+
}
|
|
35
|
+
BeelineIot::Client.login(auth_data)
|
|
36
|
+
|
|
37
|
+
# Также возможно задать авторизационные данные так.
|
|
38
|
+
BeelineIot.grant_type = "password"
|
|
39
|
+
BeelineIot.log_requests = false # по-умолчанию
|
|
40
|
+
|
|
41
|
+
# Получение списка сим-карт.
|
|
42
|
+
dashboard_id = 12345
|
|
43
|
+
response = BeelineIot::Client.request(
|
|
44
|
+
:post,
|
|
45
|
+
"/api/v0/dashboards/#{dashboard_id}/sim_cards/list_all_sim"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
# Получение списка сим-карт доступным методом.
|
|
49
|
+
dashboard_id = 12345
|
|
50
|
+
response = BeelineIot::Client.sim_list(dashboard_id)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
С помощью экземпляра класса:
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
# Авторизация.
|
|
57
|
+
auth_data = {
|
|
58
|
+
username: "e1xx",
|
|
59
|
+
password: "qweqwe",
|
|
60
|
+
client_id: "3",
|
|
61
|
+
client_secret: "7LWdlTpx9PYrqUz0sy28mlFH1pt38fPgqOkfkzBc",
|
|
62
|
+
grant_type: "password"
|
|
63
|
+
}
|
|
64
|
+
client = BeelineIot::Client.new(auth_data)
|
|
65
|
+
client.login(auth_data)
|
|
66
|
+
|
|
67
|
+
# Получение информации по SIM-карте, дополнительные параметры тоже можно передавать.
|
|
68
|
+
dashboard_id = 12345
|
|
69
|
+
params = { per_page: 5 }
|
|
70
|
+
response = BeelineIot::Client.request(
|
|
71
|
+
:get,
|
|
72
|
+
"/api/v0/dashboards/#{dashboard_id}/sim_cards/#{sim_id}",
|
|
73
|
+
params
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
# Получение информации по SIM-карте доступным методом, дополнительные параметры тоже можно передавать.
|
|
77
|
+
dashboard_id = 12345
|
|
78
|
+
sim_id = 987654
|
|
79
|
+
params = { order: { id: "asc" } }
|
|
80
|
+
response = BeelineIot::Client.get_sims(dashboard_id, sim_id, params)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Доступные методы
|
|
84
|
+
|
|
85
|
+
Вы можете использовать доступные методы или метод `.request()` в таком формате:
|
|
86
|
+
|
|
87
|
+
```ruby
|
|
88
|
+
BeelineIot::Client.request(:method, "path", params = {})
|
|
89
|
+
client.request(:method, "path", params = {})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
* `sim_list(dashboard_id, params = {})` - список SIM-карт
|
|
93
|
+
* `get_sims(dashboard_id, sim_id, params = {})` - получение информации по SIM-карте
|
|
94
|
+
* `rate_plans(dashboard_id, params = {})` - список тарифных планов
|
|
95
|
+
* `communication_plans(dashboard_id, params = {})` - список услуг
|
data/Rakefile
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# require "digest/md5"
|
|
4
|
+
require "openssl"
|
|
5
|
+
# require "base64"
|
|
6
|
+
require "faraday"
|
|
7
|
+
|
|
8
|
+
require "beeline_iot/methods"
|
|
9
|
+
|
|
10
|
+
module BeelineIot
|
|
11
|
+
class Client
|
|
12
|
+
include Methods
|
|
13
|
+
|
|
14
|
+
def initialize(auth_data = {})
|
|
15
|
+
@username = auth_data[:username]
|
|
16
|
+
@password = auth_data[:password]
|
|
17
|
+
@client_id = auth_data[:client_id]
|
|
18
|
+
@client_secret = auth_data[:client_secret]
|
|
19
|
+
@grant_type = auth_data[:grant_type]
|
|
20
|
+
@token_type = auth_data[:token_type]
|
|
21
|
+
@expires_in = auth_data[:expires_in]
|
|
22
|
+
@access_token = auth_data[:access_token]
|
|
23
|
+
@refresh_token = auth_data[:refresh_token]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def login(auth_data)
|
|
27
|
+
return self if @access_token
|
|
28
|
+
|
|
29
|
+
response = request :post, "/oauth/token", auth_data
|
|
30
|
+
@token_type = response["token_type"]
|
|
31
|
+
@expires_in = response["expires_in"]
|
|
32
|
+
@access_token = response["access_token"]
|
|
33
|
+
@refresh_token = response["refresh_token"]
|
|
34
|
+
self
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def request(method, path, params = {})
|
|
38
|
+
raise "No auth data provided" unless enough_auth_data?
|
|
39
|
+
|
|
40
|
+
params = params.to_json
|
|
41
|
+
response = client.send(method, path, params) do |request|
|
|
42
|
+
add_request_headers(request, path)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
result = ActiveSupport::JSON.decode(response.body)&.with_indifferent_access
|
|
46
|
+
raise BeelineIot::Error, "Error [HTTP #{response.status}]: #{response.reason_phrase}" unless response.success?
|
|
47
|
+
|
|
48
|
+
result
|
|
49
|
+
rescue ActiveSupport::JSON.parse_error
|
|
50
|
+
raise BeelineIot::Error, "Response is not JSON: #{response.body}"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def client
|
|
56
|
+
@client ||= ::Faraday.new(url: "https://iot.beeline.ru") do |faraday|
|
|
57
|
+
faraday.request :url_encoded
|
|
58
|
+
faraday.response :logger if BeelineIot.log_requests
|
|
59
|
+
faraday.adapter Faraday.default_adapter
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def add_request_headers(request, path)
|
|
64
|
+
request.headers["Content-Type"] = "application/json"
|
|
65
|
+
return if path == "/oauth/token"
|
|
66
|
+
|
|
67
|
+
request.headers["X-Requested-With"] = "XMLHttpRequest" unless path == "/oauth/token"
|
|
68
|
+
request.headers["Authorization"] = "#{@token_type} #{@access_token}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def enough_auth_data?(data: {})
|
|
72
|
+
if [@token_type, @access_token].all? ||
|
|
73
|
+
[@username, @password, @client_id, @client_secret, @grant_type].all?
|
|
74
|
+
return true
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
false
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Class methods
|
|
81
|
+
class << self
|
|
82
|
+
include Methods
|
|
83
|
+
|
|
84
|
+
def login(auth_data)
|
|
85
|
+
client = BeelineIot::Client.new(auth_data)
|
|
86
|
+
response = client.request :post, "/oauth/token", auth_data
|
|
87
|
+
BeelineIot.username = auth_data[:username]
|
|
88
|
+
BeelineIot.password = auth_data[:password]
|
|
89
|
+
BeelineIot.client_id = auth_data[:client_id]
|
|
90
|
+
BeelineIot.client_secret = auth_data[:client_secret]
|
|
91
|
+
BeelineIot.grant_type = auth_data[:grant_type]
|
|
92
|
+
BeelineIot.token_type = response["token_type"]
|
|
93
|
+
BeelineIot.expires_in = response["expires_in"]
|
|
94
|
+
BeelineIot.access_token = response["access_token"]
|
|
95
|
+
BeelineIot.refresh_token = response["refresh_token"]
|
|
96
|
+
BeelineIot
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def request(method, path, params = {})
|
|
100
|
+
client = BeelineIot::Client.new(
|
|
101
|
+
username: BeelineIot.username,
|
|
102
|
+
password: BeelineIot.password,
|
|
103
|
+
client_id: BeelineIot.client_id,
|
|
104
|
+
client_secret: BeelineIot.client_secret,
|
|
105
|
+
grant_type: BeelineIot.grant_type,
|
|
106
|
+
token_type: BeelineIot.token_type,
|
|
107
|
+
expires_in: BeelineIot.expires_in,
|
|
108
|
+
access_token: BeelineIot.access_token,
|
|
109
|
+
refresh_token: BeelineIot.refresh_token
|
|
110
|
+
)
|
|
111
|
+
client.request(method, path, params)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BeelineIot
|
|
4
|
+
module Methods
|
|
5
|
+
def sim_list(dashboard_id, params = {})
|
|
6
|
+
request(:post, "/api/v0/dashboards/#{dashboard_id}/sim_cards/list_all_sim", params)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def get_sims(dashboard_id, sim_id, params = {})
|
|
10
|
+
request(:get, "/api/v0/dashboards/#{dashboard_id}/sim_cards/#{sim_id}", params)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def rate_plans(dashboard_id, params = {})
|
|
14
|
+
request(:post, "/api/v0/dashboards/#{dashboard_id}/rate_plans", params)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def communication_plans(dashboard_id, params = {})
|
|
18
|
+
request(:post, "/api/v0/dashboards/#{dashboard_id}/communication_plans", params)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/beeline_iot.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "active_support"
|
|
4
|
+
require "active_support/core_ext"
|
|
5
|
+
require "active_support/json"
|
|
6
|
+
require "active_support/hash_with_indifferent_access"
|
|
7
|
+
|
|
8
|
+
require_relative "beeline_iot/version"
|
|
9
|
+
|
|
10
|
+
require "beeline_iot/client"
|
|
11
|
+
require "beeline_iot/error"
|
|
12
|
+
require "beeline_iot/methods"
|
|
13
|
+
|
|
14
|
+
module BeelineIot
|
|
15
|
+
mattr_accessor :username,
|
|
16
|
+
:password,
|
|
17
|
+
:client_id,
|
|
18
|
+
:client_secret,
|
|
19
|
+
:grant_type,
|
|
20
|
+
:token_type,
|
|
21
|
+
:expires_in,
|
|
22
|
+
:access_token,
|
|
23
|
+
:refresh_token,
|
|
24
|
+
:log_requests
|
|
25
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: beeline_iot
|
|
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-03-29 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: activesupport
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: faraday
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '1'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '1'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: json
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '1'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '1'
|
|
55
|
+
description:
|
|
56
|
+
email:
|
|
57
|
+
- vlad@kostikov.ru
|
|
58
|
+
executables: []
|
|
59
|
+
extensions: []
|
|
60
|
+
extra_rdoc_files: []
|
|
61
|
+
files:
|
|
62
|
+
- ".rspec"
|
|
63
|
+
- ".rubocop.yml"
|
|
64
|
+
- LICENSE.txt
|
|
65
|
+
- README.md
|
|
66
|
+
- Rakefile
|
|
67
|
+
- lib/beeline_iot.rb
|
|
68
|
+
- lib/beeline_iot/client.rb
|
|
69
|
+
- lib/beeline_iot/error.rb
|
|
70
|
+
- lib/beeline_iot/methods.rb
|
|
71
|
+
- lib/beeline_iot/version.rb
|
|
72
|
+
homepage: https://github.com/vladkostikov/beeline_iot
|
|
73
|
+
licenses:
|
|
74
|
+
- MIT
|
|
75
|
+
metadata:
|
|
76
|
+
homepage_uri: https://github.com/vladkostikov/beeline_iot
|
|
77
|
+
source_code_uri: https://github.com/vladkostikov/beeline_iot
|
|
78
|
+
rubygems_mfa_required: 'true'
|
|
79
|
+
post_install_message:
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 2.6.0
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubygems_version: 3.4.21
|
|
95
|
+
signing_key:
|
|
96
|
+
specification_version: 4
|
|
97
|
+
summary: Beeline IoT M2M
|
|
98
|
+
test_files: []
|