monogoto_api 0.3.1
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/LICENSE +21 -0
- data/lib/monogoto_api/client.rb +85 -0
- data/lib/monogoto_api/event/list.rb +27 -0
- data/lib/monogoto_api/event.rb +32 -0
- data/lib/monogoto_api/ip.rb +31 -0
- data/lib/monogoto_api/ping/list.rb +41 -0
- data/lib/monogoto_api/ping.rb +38 -0
- data/lib/monogoto_api/session_status.rb +20 -0
- data/lib/monogoto_api/thing.rb +41 -0
- data/lib/monogoto_api/version.rb +5 -0
- data/lib/monogoto_api.rb +16 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42f522d0958c03ff1086ed382b8f694d1b1fe7e20cb79104e8ca0761ecb83dd5
|
4
|
+
data.tar.gz: a2293409442e20edfc33aadb7a3fa8555126392862af211b604d08198925bfd4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 415b72e8b7716d44b591b9f2c3bca17e050c7166ea1d2a202cf2b203fc4c07531bac752b284ae50de3c1f24f85852614e9fc8d042ac563f6723b6b62ab16fbf1
|
7
|
+
data.tar.gz: 675830c19adfffcf1cd5ade14c1dea72349bc488cee1d6f834dca1f6ea12ddd631aab8e3cb5c52091a7c0cf2c6c259046e837c5392a581d9856fecf404fd6e16
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 Zembia
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "httparty"
|
4
|
+
|
5
|
+
module MonogotoApi
|
6
|
+
class Client
|
7
|
+
include HTTParty
|
8
|
+
|
9
|
+
base_uri "https://console.monogoto.io"
|
10
|
+
|
11
|
+
def initialize(user, password)
|
12
|
+
auth = { "UserName" => user, "Password" => password }
|
13
|
+
jwt_response = self.class.post(
|
14
|
+
"/Auth",
|
15
|
+
body: auth.to_json, headers: { "Content-Type" => "application/json" }
|
16
|
+
)
|
17
|
+
|
18
|
+
@jwt = jwt_response["token"]
|
19
|
+
@customer_id = jwt_response["CustomerId"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def things
|
23
|
+
resp = get("/things", headers: auth_header)
|
24
|
+
MonogotoApi::Thing.parse_many(resp.parsed_response)
|
25
|
+
end
|
26
|
+
|
27
|
+
def thing(iccid)
|
28
|
+
resp = get("/thing/ThingId_ICCID_#{ iccid }", headers: auth_header)
|
29
|
+
MonogotoApi::Thing.parse(resp.parsed_response)
|
30
|
+
end
|
31
|
+
|
32
|
+
def thing_state(iccid)
|
33
|
+
get("/thing/ThingId_ICCID_#{ iccid }/state", headers: auth_header).body
|
34
|
+
end
|
35
|
+
|
36
|
+
def thing_session_status(iccid)
|
37
|
+
resp = get("/thing/status/?ThingIds=ThingId_ICCID_#{ iccid }", headers: auth_header)
|
38
|
+
MonogotoApi::SessionStatus.parse(resp.parsed_response)
|
39
|
+
end
|
40
|
+
|
41
|
+
def thing_events(iccid, limit: 20)
|
42
|
+
body = { "ThingIdELK" => "ThingId_ICCID_#{ iccid }", "limit" => limit }
|
43
|
+
# body.merge!(opts) if opts.any?
|
44
|
+
resp = post(
|
45
|
+
"/thing/searchCDR",
|
46
|
+
body:,
|
47
|
+
headers: apikey_headers
|
48
|
+
)
|
49
|
+
MonogotoApi::Event::List.parse(resp)
|
50
|
+
end
|
51
|
+
|
52
|
+
def thing_ping(iccid)
|
53
|
+
thing_data = thing(iccid)
|
54
|
+
resp = post(
|
55
|
+
"/thing/ThingId_ICCID_#{ iccid }/ping",
|
56
|
+
body: { "IPAddress" => thing_data.ip },
|
57
|
+
headers: apikey_headers
|
58
|
+
)
|
59
|
+
MonogotoApi::Ping::List.parse(resp)
|
60
|
+
end
|
61
|
+
|
62
|
+
def thing_refresh_connection(iccid)
|
63
|
+
resp = get("/thing/ThingId_ICCID_#{ iccid }/refreshConnection", headers: auth_header)
|
64
|
+
resp.success?
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def auth_header
|
70
|
+
{ Authorization: "Bearer #{ @jwt }" }
|
71
|
+
end
|
72
|
+
|
73
|
+
def apikey_headers
|
74
|
+
{ Authorization: "Bearer #{ @jwt }", apikey: @customer_id }
|
75
|
+
end
|
76
|
+
|
77
|
+
def get(path, headers: {})
|
78
|
+
self.class.get(path, headers:)
|
79
|
+
end
|
80
|
+
|
81
|
+
def post(path, body: {}, headers: {})
|
82
|
+
self.class.post(path, body:, headers:)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
class Event
|
5
|
+
class List
|
6
|
+
attr_reader :events, :counter
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@events = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Push event element to events array
|
13
|
+
def push(event)
|
14
|
+
push_result = @events.push(event)
|
15
|
+
@counter = push_result.size
|
16
|
+
push_result
|
17
|
+
end
|
18
|
+
|
19
|
+
# Parser of API events response
|
20
|
+
def self.parse(resp_events)
|
21
|
+
list = new
|
22
|
+
resp_events.fetch("hits", {}).each { |event| list.push(MonogotoApi::Event.parse(event)) }
|
23
|
+
list
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
class Event
|
5
|
+
attr_reader :severity, :msg, :msg_type, :timestamp, :data_type
|
6
|
+
|
7
|
+
def initialize(**attributes)
|
8
|
+
@severity = attributes[:severity]
|
9
|
+
@msg = attributes[:msg]
|
10
|
+
@msg_type = attributes[:msg_type]
|
11
|
+
@timestamp = attributes[:timestamp]
|
12
|
+
@data_type = attributes[:data_type]
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.parse(hash_event)
|
16
|
+
data_first = hash_event["_source"]
|
17
|
+
new(
|
18
|
+
severity: data_first["Severity"],
|
19
|
+
msg: data_first["message"],
|
20
|
+
msg_type: data_first["MessageType"],
|
21
|
+
timestamp: Time.at(data_first["Timestamp"] / 1_000),
|
22
|
+
data_type: data_first["EsDataType"]
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.parse_many(hits)
|
27
|
+
output = []
|
28
|
+
hits.each { |pre_event| output.push(parse(pre_event)) }
|
29
|
+
output
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
class IP
|
5
|
+
attr_reader :ip, :ip_allocation_policy, :ip_lock, :ipv_type
|
6
|
+
|
7
|
+
def initialize(**attributes)
|
8
|
+
@ip = attributes[:ip]
|
9
|
+
@ip_allocation_policy = attributes[:ip_allocation_policy]
|
10
|
+
@ip_lock = attributes[:ip_lock]
|
11
|
+
@ipv_type = attributes[:ipv_type]
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.parse_many(response)
|
15
|
+
output = []
|
16
|
+
response.each do |pre_ip|
|
17
|
+
output.push(parse(pre_ip))
|
18
|
+
end
|
19
|
+
output
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.parse(hash_ip)
|
23
|
+
new(
|
24
|
+
ip: hash_ip["IP"],
|
25
|
+
ip_allocation_policy: hash_ip["IPAllocationPolicy"],
|
26
|
+
ip_lock: hash_ip["IPLock"],
|
27
|
+
ipv_type: hash_ip["IPvType"]
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
class Ping
|
5
|
+
class List
|
6
|
+
attr_reader :pings
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@pings = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Push ping element to pings array
|
13
|
+
def push(ping)
|
14
|
+
@pings.push(ping)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Parser of API ping response
|
18
|
+
# "/thing/ThingId_ICCID_#{ iccid }/ping"
|
19
|
+
def self.parse(hash_pings)
|
20
|
+
list = new
|
21
|
+
hash_pings.each { |ping| list.push(MonogotoApi::Ping.parse(ping)) }
|
22
|
+
list
|
23
|
+
end
|
24
|
+
|
25
|
+
# Extract packet loss counter of ping list
|
26
|
+
def packet_loss
|
27
|
+
@pings.map(&:packet_loss).max
|
28
|
+
end
|
29
|
+
|
30
|
+
# Extract received counter of ping list
|
31
|
+
def received
|
32
|
+
@pings.map(&:received).max
|
33
|
+
end
|
34
|
+
|
35
|
+
# Check if are any packet loss in any ping
|
36
|
+
def ok?
|
37
|
+
packet_loss.zero?
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
class Ping
|
5
|
+
attr_reader :host, :size, :ttl, :time, :sent, :received, :packet_loss
|
6
|
+
|
7
|
+
def initialize(**attributes)
|
8
|
+
@host = attributes[:host]
|
9
|
+
@size = attributes[:size]
|
10
|
+
@ttl = attributes[:ttl]
|
11
|
+
@time = attributes[:time]
|
12
|
+
@sent = attributes[:sent]
|
13
|
+
@received = attributes[:received]
|
14
|
+
@packet_loss = attributes[:packet_loss]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse_many(response)
|
18
|
+
output = []
|
19
|
+
response.each do |pre_ip|
|
20
|
+
output.push(parse(pre_ip))
|
21
|
+
end
|
22
|
+
output
|
23
|
+
end
|
24
|
+
|
25
|
+
# Parser of single element of API ping response
|
26
|
+
def self.parse(hash_ping)
|
27
|
+
new(
|
28
|
+
host: hash_ping["host"],
|
29
|
+
size: hash_ping["size"].to_i,
|
30
|
+
ttl: hash_ping["ttl"].to_i,
|
31
|
+
time: hash_ping["time"],
|
32
|
+
sent: hash_ping["sent"].to_i,
|
33
|
+
received: hash_ping["received"].to_i,
|
34
|
+
packet_loss: hash_ping["packetLoss"].to_i
|
35
|
+
)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
class SessionStatus
|
5
|
+
attr_reader :connection, :provision
|
6
|
+
|
7
|
+
def initialize(**attributes)
|
8
|
+
@provision = attributes[:provision]
|
9
|
+
@connection = attributes[:connection]
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.parse(hash_session)
|
13
|
+
data_first = hash_session["Data"].first
|
14
|
+
new(
|
15
|
+
provision: data_first["ProvisionStatus"],
|
16
|
+
connection: data_first["ConnectionStatus"]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MonogotoApi
|
4
|
+
# Thing refer to Monogoto SIM
|
5
|
+
class Thing
|
6
|
+
attr_reader :iccid, :imei, :operator, :state, :name, :ips
|
7
|
+
|
8
|
+
def initialize(**attributes)
|
9
|
+
@iccid = attributes[:iccid]
|
10
|
+
@imei = attributes[:imei]
|
11
|
+
@operator = attributes[:operator]
|
12
|
+
@state = attributes[:state]
|
13
|
+
@name = attributes[:name]
|
14
|
+
@ips = attributes[:ips]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse_many(response)
|
18
|
+
output = []
|
19
|
+
response.each do |pre_thing|
|
20
|
+
output.push(parse(pre_thing))
|
21
|
+
end
|
22
|
+
output
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse(hash_thing)
|
26
|
+
ips = MonogotoApi::IP.parse_many(hash_thing["IPs"])
|
27
|
+
new(
|
28
|
+
imei: hash_thing["IMEI"],
|
29
|
+
name: hash_thing["ThingName"],
|
30
|
+
iccid: hash_thing["ExternalUniqueId"],
|
31
|
+
operator: hash_thing["MnoName"],
|
32
|
+
state: hash_thing["State"],
|
33
|
+
ips:
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
def ip
|
38
|
+
@ips.first.ip
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/monogoto_api.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "monogoto_api/client"
|
4
|
+
require_relative "monogoto_api/event"
|
5
|
+
require_relative "monogoto_api/event/list"
|
6
|
+
require_relative "monogoto_api/ip"
|
7
|
+
require_relative "monogoto_api/ping"
|
8
|
+
require_relative "monogoto_api/ping/list"
|
9
|
+
require_relative "monogoto_api/session_status"
|
10
|
+
require_relative "monogoto_api/thing"
|
11
|
+
require_relative "monogoto_api/version"
|
12
|
+
|
13
|
+
module MonogotoApi
|
14
|
+
class << self
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: monogoto_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Javier Contreras Ferrada
|
8
|
+
bindir: bin
|
9
|
+
cert_chain: []
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: debug
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - ">="
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '0'
|
19
|
+
type: :development
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: dotenv
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: httparty
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0.21'
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 0.21.0
|
50
|
+
type: :runtime
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0.21'
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.21.0
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: base64
|
62
|
+
requirement: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :runtime
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: csv
|
76
|
+
requirement: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
type: :runtime
|
82
|
+
prerelease: false
|
83
|
+
version_requirements: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
description: Unofficial Ruby gem for Monogoto API. Monogoto is a IoT connectivity
|
89
|
+
management platform
|
90
|
+
email:
|
91
|
+
- javier.contreras@zembia.cl
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- LICENSE
|
97
|
+
- lib/monogoto_api.rb
|
98
|
+
- lib/monogoto_api/client.rb
|
99
|
+
- lib/monogoto_api/event.rb
|
100
|
+
- lib/monogoto_api/event/list.rb
|
101
|
+
- lib/monogoto_api/ip.rb
|
102
|
+
- lib/monogoto_api/ping.rb
|
103
|
+
- lib/monogoto_api/ping/list.rb
|
104
|
+
- lib/monogoto_api/session_status.rb
|
105
|
+
- lib/monogoto_api/thing.rb
|
106
|
+
- lib/monogoto_api/version.rb
|
107
|
+
homepage: https://github.com/zembia/monogoto_api_ruby
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
rubygems_mfa_required: 'true'
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '3.2'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubygems_version: 3.6.7
|
127
|
+
specification_version: 4
|
128
|
+
summary: Unofficial Ruby gem for Monogoto API
|
129
|
+
test_files: []
|