ondotori-ruby-client 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4a965c44ac6b06067e1f7a91965f71b1aa5af922cf72f25810ea6c33a3b3ad34
4
- data.tar.gz: a9a87b72b9667432147b0ee1b3e507379e336ef6323fb9ec5bc3f4de96b21c44
3
+ metadata.gz: 442594d52153a81560cbbf8a79fcda7cf1ab6034c54367257e6d79249904e84b
4
+ data.tar.gz: b5178b2d79592f93caa2263957977ac7b0962ba158901306768417b5882c97a4
5
5
  SHA512:
6
- metadata.gz: 3778d91789c76e492aed29ded770fae6f456793eb8ffcd9c7996dae9304ef4bcc72ff65f7633dcf89e72b95b571ef46b0d406585399aafa4ddde32725694c46f
7
- data.tar.gz: 4433bd62632b388ec92f85b46ce7bc04318fa148417e57042dce7fdab87ecc8d2bdcf5dc1f6b473aa46795d6d9c1ea13c6444a482e473260c031d23b25282ecb
6
+ metadata.gz: 2f5925a8a7843296922668e9168e799bf1fc6522c6c6104320555219aace442eef1c671d2e55e80e38c9f6d15d60f2444ba0b630c2793f9487f7350cae57562e
7
+ data.tar.gz: bf580712e184dc1e9f7942dac11a4b745c488afa43d38ec6df1d2c3901380a32732724098eb05e10b644090875c9eec1eaa505f20926be760f7c691719a23eed
data/CHANGELOG.md CHANGED
@@ -1,4 +1,12 @@
1
- ## [Unreleased]
1
+ ## [Released]
2
+
3
+ ## [1.1.0] - 2021-04-17
4
+
5
+ - Support for getting RateLimit when an error occurs.
6
+
7
+ ## [1.0.0] - 2021-03-04
8
+
9
+ - Support v1 all API
2
10
 
3
11
  ## [0.1.0] - 2021-02-18
4
12
 
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,26 +69,28 @@ 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
 
93
96
  #### Error Handling
@@ -96,15 +99,19 @@ Ondotori Errors
96
99
 
97
100
  In case of parameter abnormality or error returned from the web server, the error will be raised.
98
101
  For example, to receive an authentication error from the server, use the following.
99
- ```
102
+
103
+ ```ruby
100
104
  rescue Ondotori::WebAPI::Api::Errors::ResponseError => e
101
- # puts "Response error #{e.messaeg}"
105
+ puts "Response error #{e.message}"
102
106
  end
103
107
  ```
108
+
109
+ If you reach the limit, you can check it with ResponseError.ratelimit.
104
110
  All of these errors inherit from `Ondotori::WebAPI::Api::Errors::Error`, so you can handle or silence all errors if necessary:
105
- ```
111
+
112
+ ```ruby
106
113
  rescue Ondotori::WebAPI::Api::Errors::Error => e
107
- # puts "Response error #{e.messaeg}"
114
+ puts "An error has occurred #{e.message}"
108
115
  end
109
116
  ```
110
117
 
@@ -35,6 +35,13 @@ def main
35
35
  return
36
36
  end
37
37
 
38
+ %w[api-key login-id login-pass].each do |k|
39
+ if params[k].nil?
40
+ puts "parameter #{k} is nil. Please check #{WEB_STORAGE_ACCESS_INFO_PATH}"
41
+ exit
42
+ end
43
+ end
44
+
38
45
  begin
39
46
  client = Ondotori::WebAPI::Client.new(params)
40
47
  response = client.current
@@ -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"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ondotori
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -13,7 +13,14 @@ module Ondotori
13
13
  end
14
14
  end
15
15
 
16
- class ResponseError < Error; end
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
 
@@ -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
- raise Ondotori::WebAPI::Api::Errors::ResponseError.new(message, code)
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...
@@ -23,7 +23,7 @@ module Ondotori
23
23
  when Net::HTTPClientError, Net::HTTPServerError
24
24
  response
25
25
  else
26
- # response.value raises Eception...
26
+ # response.value raises Exception...
27
27
  raise Ondotori::WebAPI::Api::Errors::HttpAccessError.new("#{response.message}", "#{response.code}", 9995)
28
28
  end
29
29
  end
@@ -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")
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.0.0
4
+ version: 1.1.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: 2021-03-04 00:00:00.000000000 Z
11
+ date: 2021-04-17 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