ondotori-ruby-client 1.0.0 → 1.2.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 +4 -4
- data/.rubocop.yml +2 -1
- data/CHANGELOG.md +9 -1
- data/Gemfile +1 -1
- data/README.md +25 -10
- data/example/get_current_temp.rb +8 -3
- data/lib/ondotori/version.rb +1 -1
- data/lib/ondotori/webapi/api/errors.rb +10 -3
- data/lib/ondotori/webapi/api/params.rb +21 -0
- data/lib/ondotori/webapi/api/rate_limit.rb +17 -0
- data/lib/ondotori/webapi/api/response.rb +2 -1
- data/lib/ondotori/webapi/client.rb +5 -0
- data/lib/ondotori/webapi/httpwebaccess.rb +2 -4
- data/lib/ondotori/webapi/webaccess.rb +1 -1
- data/lib/ondotori-ruby-client.rb +1 -0
- data/ondotori-ruby-client.gemspec +2 -1
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e2b5691b375a55fc06352a122ce7a460bb8c3c2dc24762b426e42408e4cb4ce
|
4
|
+
data.tar.gz: 6c35ca3b21b11fb29a30ca4ce43baa38ec06ab08514b4cdc67391ff555c9d13b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5d1a863aa4f7eb4fcb5b7ed30b42177c47c37b959e8554dfbbfbd03a8610f598ac255897a03ee3f803579b6651b5460e3fc39b986864a94cf46f9d1bb2aa2e4
|
7
|
+
data.tar.gz: 545a1ff4496317c78eb4c520f8ded98dbe83ca4b7e62329a8dd4311fd08b8cc2d0f6846ba7c4f65429d49fd09dc065678ded5f50f7922c313b083c0cd84afc5d
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -29,7 +29,7 @@ The first step is to create an API key.
|
|
29
29
|
|
30
30
|
#### Web Client Examples
|
31
31
|
|
32
|
-
```
|
32
|
+
```ruby
|
33
33
|
params = { "api-key" => "API Key you create", "login-id" => "tbxxxx", "login-pass" => "password"}
|
34
34
|
client = Ondotori::WebAPI::Client.new(params)
|
35
35
|
```
|
@@ -45,14 +45,15 @@ client = Ondotori::WebAPI::Client.new(params)
|
|
45
45
|
|
46
46
|
To get current readings, do the following.
|
47
47
|
|
48
|
-
```
|
48
|
+
```ruby
|
49
49
|
response = client.current()
|
50
50
|
```
|
51
|
+
|
51
52
|
#### Get Latest Data
|
52
53
|
|
53
54
|
To get latest data, do the following.
|
54
55
|
|
55
|
-
```
|
56
|
+
```ruby
|
56
57
|
response = client.latest_data("SERIAL")
|
57
58
|
```
|
58
59
|
|
@@ -60,7 +61,7 @@ response = client.latest_data("SERIAL")
|
|
60
61
|
|
61
62
|
To get latest data (RTR500), do the following.
|
62
63
|
|
63
|
-
```
|
64
|
+
```ruby
|
64
65
|
response = client.latest_data_rtr500(base: "BaseUnit Serial", remote: "RemoteUnit Serial")
|
65
66
|
```
|
66
67
|
|
@@ -68,43 +69,57 @@ response = client.latest_data_rtr500(base: "BaseUnit Serial", remote: "RemoteUni
|
|
68
69
|
|
69
70
|
To get data (TR-7wb/nw/wf, TR4), do the following.
|
70
71
|
|
71
|
-
```
|
72
|
+
```ruby
|
72
73
|
from = Time.now - (3600 * 24)
|
73
74
|
to = Time.now
|
74
75
|
limit = 16000
|
75
76
|
data_range = Ondotori::WebAPI::Api::DataRange.new(from: from, to: to, limit: 10)
|
76
77
|
response = client.data("Device Serial", data_range: data_range)
|
77
78
|
```
|
79
|
+
|
78
80
|
data_range parameter is optional.
|
79
81
|
|
80
82
|
#### Get Data (RTR500 Series)
|
81
83
|
|
82
84
|
To get data (RTR500 Series), do the following.
|
83
85
|
|
84
|
-
```
|
86
|
+
```ruby
|
85
87
|
from = Time.now - (3600 * 24)
|
86
88
|
to = Time.now
|
87
89
|
limit = 16000
|
88
90
|
data_range = Ondotori::WebAPI::Api::DataRange.new(from: from, to: to, limit: 10)
|
89
91
|
response = client.data_rtr500(base: "BaseUnit Serial", remote: "Device Serial", data_range: data_range)
|
90
92
|
```
|
93
|
+
|
91
94
|
data_range parameter is optional.
|
92
95
|
|
96
|
+
#### Get Alert log
|
97
|
+
|
98
|
+
To get alert log, do the following.
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
response = client.alert_log(base: "BaseUnit Serial", remote: "RemoteUnit Serial")
|
102
|
+
```
|
103
|
+
|
93
104
|
#### Error Handling
|
94
105
|
|
95
106
|
Ondotori Errors
|
96
107
|
|
97
108
|
In case of parameter abnormality or error returned from the web server, the error will be raised.
|
98
109
|
For example, to receive an authentication error from the server, use the following.
|
99
|
-
|
110
|
+
|
111
|
+
```ruby
|
100
112
|
rescue Ondotori::WebAPI::Api::Errors::ResponseError => e
|
101
|
-
|
113
|
+
puts "Response error #{e.message}"
|
102
114
|
end
|
103
115
|
```
|
116
|
+
|
117
|
+
If you reach the limit, you can check it with ResponseError.ratelimit.
|
104
118
|
All of these errors inherit from `Ondotori::WebAPI::Api::Errors::Error`, so you can handle or silence all errors if necessary:
|
105
|
-
|
119
|
+
|
120
|
+
```ruby
|
106
121
|
rescue Ondotori::WebAPI::Api::Errors::Error => e
|
107
|
-
|
122
|
+
puts "An error has occurred #{e.message}"
|
108
123
|
end
|
109
124
|
```
|
110
125
|
|
data/example/get_current_temp.rb
CHANGED
@@ -22,9 +22,7 @@ def load_params
|
|
22
22
|
wss_access_info["login-pass"] = load_info["login-pass"]
|
23
23
|
return wss_access_info
|
24
24
|
end
|
25
|
-
rescue SystemCallError => e
|
26
|
-
puts %(class=[#{e.class}] message=[#{e.message}])
|
27
|
-
rescue IOError => e
|
25
|
+
rescue SystemCallError, IOError => e
|
28
26
|
puts %(class=[#{e.class}] message=[#{e.message}])
|
29
27
|
end
|
30
28
|
|
@@ -35,6 +33,13 @@ def main
|
|
35
33
|
return
|
36
34
|
end
|
37
35
|
|
36
|
+
%w[api-key login-id login-pass].each do |k|
|
37
|
+
if params[k].nil?
|
38
|
+
puts "parameter #{k} is nil. Please check #{WEB_STORAGE_ACCESS_INFO_PATH}"
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
38
43
|
begin
|
39
44
|
client = Ondotori::WebAPI::Client.new(params)
|
40
45
|
response = client.current
|
data/lib/ondotori/version.rb
CHANGED
@@ -8,12 +8,19 @@ module Ondotori
|
|
8
8
|
attr_reader :code
|
9
9
|
|
10
10
|
def initialize(message, code = nil)
|
11
|
-
super
|
11
|
+
super(message)
|
12
12
|
@code = code
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
class ResponseError < Error
|
16
|
+
class ResponseError < Error
|
17
|
+
attr_reader :ratelimit
|
18
|
+
|
19
|
+
def initialize(message, code, ratelimit)
|
20
|
+
super(message, code)
|
21
|
+
@ratelimit = ratelimit
|
22
|
+
end
|
23
|
+
end
|
17
24
|
|
18
25
|
class InitializeParameterNotFound < Error; end
|
19
26
|
|
@@ -23,7 +30,7 @@ module Ondotori
|
|
23
30
|
attr_reader :detail
|
24
31
|
|
25
32
|
def initialize(message, detail, code = nil)
|
26
|
-
super
|
33
|
+
super(message, code)
|
27
34
|
@detail = detail
|
28
35
|
end
|
29
36
|
end
|
@@ -127,6 +127,27 @@ module Ondotori
|
|
127
127
|
params
|
128
128
|
end
|
129
129
|
end
|
130
|
+
|
131
|
+
class AlertLogParams < ParamsBase
|
132
|
+
def initialize(param, base: "", remote: "")
|
133
|
+
super(param)
|
134
|
+
if base.empty? || remote.empty?
|
135
|
+
raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new(
|
136
|
+
"alert-log need both the baseunit serial and remote unit serial.", 9990
|
137
|
+
)
|
138
|
+
end
|
139
|
+
@base_serial = base
|
140
|
+
@remote_serial = remote
|
141
|
+
end
|
142
|
+
|
143
|
+
def to_ondotori_param
|
144
|
+
params = super
|
145
|
+
params["base-serial"] = @base_serial
|
146
|
+
params["remote-serial"] = @remote_serial
|
147
|
+
|
148
|
+
params
|
149
|
+
end
|
150
|
+
end
|
130
151
|
end
|
131
152
|
end
|
132
153
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Ondotori
|
4
|
+
module WebAPI
|
5
|
+
module Api
|
6
|
+
class RateLimit
|
7
|
+
attr_reader :limit, :reset, :remaining
|
8
|
+
|
9
|
+
def initialize(response)
|
10
|
+
@limit = response.get_fields("X-RateLimit-Limit")
|
11
|
+
@reset = response.get_fields("X-RateLimit-Reset")
|
12
|
+
@remaining = response.get_fields("X-RateLimit-Remaining")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -18,7 +18,8 @@ module Ondotori
|
|
18
18
|
if result.key?("error")
|
19
19
|
code = result["error"]["code"]
|
20
20
|
message = result["error"]["message"]
|
21
|
-
|
21
|
+
ratelimit = Ondotori::WebAPI::Api::RateLimit.new(@response)
|
22
|
+
raise Ondotori::WebAPI::Api::Errors::ResponseError.new(message, code, ratelimit)
|
22
23
|
end
|
23
24
|
|
24
25
|
# unknown error...
|
@@ -41,6 +41,11 @@ module Ondotori
|
|
41
41
|
access_server(param, "#{base_uri}data-rtr500")
|
42
42
|
end
|
43
43
|
|
44
|
+
def alert_log(base: "", remote: "")
|
45
|
+
param = Api::AlertLogParams.new(@param, base: base, remote: remote)
|
46
|
+
access_server(param, "#{base_uri}alert")
|
47
|
+
end
|
48
|
+
|
44
49
|
def base_uri
|
45
50
|
return @uri unless @uri.empty?
|
46
51
|
|
@@ -18,12 +18,10 @@ module Ondotori
|
|
18
18
|
|
19
19
|
response = http.request_post(web_uri.path, params.to_json, make_headers)
|
20
20
|
case response
|
21
|
-
when Net::HTTPSuccess
|
22
|
-
response
|
23
|
-
when Net::HTTPClientError, Net::HTTPServerError
|
21
|
+
when Net::HTTPSuccess, Net::HTTPClientError, Net::HTTPServerError
|
24
22
|
response
|
25
23
|
else
|
26
|
-
# response.value raises
|
24
|
+
# response.value raises Exception...
|
27
25
|
raise Ondotori::WebAPI::Api::Errors::HttpAccessError.new("#{response.message}", "#{response.code}", 9995)
|
28
26
|
end
|
29
27
|
end
|
data/lib/ondotori-ruby-client.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative "ondotori/webapi/httpwebaccess"
|
|
7
7
|
require_relative "ondotori/webapi/api/errors"
|
8
8
|
require_relative "ondotori/webapi/api/param"
|
9
9
|
require_relative "ondotori/webapi/api/params"
|
10
|
+
require_relative "ondotori/webapi/api/rate_limit"
|
10
11
|
require_relative "ondotori/webapi/api/response"
|
11
12
|
require_relative "ondotori/webapi/api/uri"
|
12
13
|
require_relative "ondotori/webapi/api/data_range"
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["k28@me.com"]
|
10
10
|
|
11
11
|
spec.summary = "T&D WebStorage API Client"
|
12
|
-
spec.description = "You can use this gem to get the recorded data from WebStorage."
|
12
|
+
spec.description = "You can use this gem to get the recorded data from T&D WebStorage Service API."
|
13
13
|
spec.homepage = "https://github.com/k28/ondotori-ruby-client"
|
14
14
|
spec.license = "MIT"
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
@@ -32,4 +32,5 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
# For more information and examples about making a new gem, checkout our
|
34
34
|
# guide at: https://bundler.io/guides/creating_gem.html
|
35
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
35
36
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ondotori-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuya Hatano
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: You can use this gem to get the recorded data from WebStorage
|
13
|
+
description: You can use this gem to get the recorded data from T&D WebStorage Service
|
14
|
+
API.
|
14
15
|
email:
|
15
16
|
- k28@me.com
|
16
17
|
executables: []
|
@@ -35,6 +36,7 @@ files:
|
|
35
36
|
- lib/ondotori/webapi/api/errors.rb
|
36
37
|
- lib/ondotori/webapi/api/param.rb
|
37
38
|
- lib/ondotori/webapi/api/params.rb
|
39
|
+
- lib/ondotori/webapi/api/rate_limit.rb
|
38
40
|
- lib/ondotori/webapi/api/response.rb
|
39
41
|
- lib/ondotori/webapi/api/uri.rb
|
40
42
|
- lib/ondotori/webapi/client.rb
|
@@ -48,6 +50,7 @@ metadata:
|
|
48
50
|
homepage_uri: https://github.com/k28/ondotori-ruby-client
|
49
51
|
source_code_uri: https://github.com/k28/ondotori-ruby-client
|
50
52
|
changelog_uri: https://github.com/k28/ondotori-ruby-client/blob/main/CHANGELOG.md
|
53
|
+
rubygems_mfa_required: 'true'
|
51
54
|
post_install_message:
|
52
55
|
rdoc_options: []
|
53
56
|
require_paths:
|
@@ -63,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
66
|
- !ruby/object:Gem::Version
|
64
67
|
version: '0'
|
65
68
|
requirements: []
|
66
|
-
rubygems_version: 3.0.3
|
69
|
+
rubygems_version: 3.0.3.1
|
67
70
|
signing_key:
|
68
71
|
specification_version: 4
|
69
72
|
summary: T&D WebStorage API Client
|