ondotori-ruby-client 0.0.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a629b226e96126e7f1164d71fcd36700b7af8d2229c2e16a2ccbb6c5a44213a8
4
- data.tar.gz: 5a134e0ca23f3fb706566f86fb335fddf2ae3ce3fcbbe035bcefeb546dfc35a7
3
+ metadata.gz: 4a965c44ac6b06067e1f7a91965f71b1aa5af922cf72f25810ea6c33a3b3ad34
4
+ data.tar.gz: a9a87b72b9667432147b0ee1b3e507379e336ef6323fb9ec5bc3f4de96b21c44
5
5
  SHA512:
6
- metadata.gz: d0044b0473197e69e7f978f399ec29c24e62f406118f1e1808f76d822b371e4f41cf311e66727953fd8e1ba446f535aba101d8d92552ad0e658e21e8136d85b1
7
- data.tar.gz: 1a0826dcc6e452c31f15f6c364559f8102d7403731659c1d55bb5974375fc0832199d63f9d40c8ca9e629be37e1d9ef1633a90f8553162e141536d79057d5444
6
+ metadata.gz: 3778d91789c76e492aed29ded770fae6f456793eb8ffcd9c7996dae9304ef4bcc72ff65f7633dcf89e72b95b571ef46b0d406585399aafa4ddde32725694c46f
7
+ data.tar.gz: 4433bd62632b388ec92f85b46ce7bc04318fa148417e57042dce7fdab87ecc8d2bdcf5dc1f6b473aa46795d6d9c1ea13c6444a482e473260c031d23b25282ecb
data/.rubocop.yml CHANGED
@@ -44,6 +44,9 @@ Naming/FileName:
44
44
  Metrics/MethodLength:
45
45
  Max: 32
46
46
 
47
+ Metrics/ParameterLists:
48
+ Max: 6
49
+
47
50
  # Offence count: 10
48
51
  Metrics/AbcSize:
49
52
  Max: 39
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Ruby](https://github.com/k28/ondotori-ruby-client/actions/workflows/main.yml/badge.svg)](https://github.com/k28/ondotori-ruby-client/actions/workflows/main.yml)
2
+
1
3
  ## Installation
2
4
 
3
5
  Add this line to your application's Gemfile:
@@ -44,8 +46,6 @@ client = Ondotori::WebAPI::Client.new(params)
44
46
  To get current readings, do the following.
45
47
 
46
48
  ```
47
- params = { "api-key" => "API Key you create", "login-id" => "tbxxxx", "login-pass" => "password"}
48
- client = Ondotori::WebAPI::Client.new(params)
49
49
  response = client.current()
50
50
  ```
51
51
  #### Get Latest Data
@@ -53,8 +53,6 @@ response = client.current()
53
53
  To get latest data, do the following.
54
54
 
55
55
  ```
56
- params = { "api-key" => "API Key you create", "login-id" => "tbxxxx", "login-pass" => "password"}
57
- client = Ondotori::WebAPI::Client.new(params)
58
56
  response = client.latest_data("SERIAL")
59
57
  ```
60
58
 
@@ -63,8 +61,6 @@ response = client.latest_data("SERIAL")
63
61
  To get latest data (RTR500), do the following.
64
62
 
65
63
  ```
66
- params = { "api-key" => "API Key you create", "login-id" => "tbxxxx", "login-pass" => "password"}
67
- client = Ondotori::WebAPI::Client.new(params)
68
64
  response = client.latest_data_rtr500(base: "BaseUnit Serial", remote: "RemoteUnit Serial")
69
65
  ```
70
66
 
@@ -75,12 +71,24 @@ To get data (TR-7wb/nw/wf, TR4), do the following.
75
71
  ```
76
72
  from = Time.now - (3600 * 24)
77
73
  to = Time.now
78
- limit = 173
79
- params = { "api-key" => "API Key you create", "login-id" => "tbxxxx", "login-pass" => "password"}
80
- client = Ondotori::WebAPI::Client.new(params)
81
- response = client.data("Device Serial", from: from, to: to, limit: limit)
74
+ limit = 16000
75
+ data_range = Ondotori::WebAPI::Api::DataRange.new(from: from, to: to, limit: 10)
76
+ response = client.data("Device Serial", data_range: data_range)
77
+ ```
78
+ data_range parameter is optional.
79
+
80
+ #### Get Data (RTR500 Series)
81
+
82
+ To get data (RTR500 Series), do the following.
83
+
84
+ ```
85
+ from = Time.now - (3600 * 24)
86
+ to = Time.now
87
+ limit = 16000
88
+ data_range = Ondotori::WebAPI::Api::DataRange.new(from: from, to: to, limit: 10)
89
+ response = client.data_rtr500(base: "BaseUnit Serial", remote: "Device Serial", data_range: data_range)
82
90
  ```
83
- from, to and limit parameter is optional.
91
+ data_range parameter is optional.
84
92
 
85
93
  #### Error Handling
86
94
 
@@ -9,3 +9,4 @@ require_relative "ondotori/webapi/api/param"
9
9
  require_relative "ondotori/webapi/api/params"
10
10
  require_relative "ondotori/webapi/api/response"
11
11
  require_relative "ondotori/webapi/api/uri"
12
+ 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 = "0.0.4"
4
+ VERSION = "1.0.0"
5
5
  end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ondotori
4
+ module WebAPI
5
+ module Api
6
+ class DataRange
7
+ attr_reader :from, :to, :limit
8
+
9
+ def initialize(from: nil, to: nil, limit: nil)
10
+ validate(from, to, limit)
11
+
12
+ @from = from
13
+ @to = to
14
+ @limit = limit.nil? ? 0 : [0, limit].max
15
+ end
16
+
17
+ def validate(from, to, _limit)
18
+ [from, to].each do |param|
19
+ next if param.nil? || param.instance_of?(Time)
20
+
21
+ raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new(
22
+ "from and to parameter must be nil or Time.", 9992
23
+ )
24
+ end
25
+ end
26
+
27
+ def add_data_range(params)
28
+ params["unixtime-from"] = @from.to_i unless @from.nil?
29
+ params["unixtime-to"] = @to.to_i unless @to.nil?
30
+ params["number"] = @limit if @limit != 0
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -81,36 +81,48 @@ module Ondotori
81
81
  end
82
82
 
83
83
  class DataParams < ParamsBase
84
- def initialize(param, serial, from: nil, to: nil, limit: nil)
84
+ def initialize(param, serial, data_range: nil)
85
85
  super(param)
86
- validate(serial, from, to, limit)
86
+ validate(serial)
87
+ @data_range = data_range
87
88
  @serial = serial
88
- @from = from
89
- @to = to
90
- @limit = limit.nil? ? 0 : [0, limit].max
91
89
  end
92
90
 
93
- def validate(serial, from, to, _limit)
91
+ def validate(serial)
94
92
  unless serial.instance_of?(String)
95
93
  raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new(
96
94
  "serial must be String.", 9991
97
95
  )
98
96
  end
99
- [from, to].each do |param|
100
- next if param.nil? || param.instance_of?(Time)
97
+ end
98
+
99
+ def to_ondotori_param
100
+ params = super
101
+ params["remote-serial"] = @serial
102
+ @data_range&.add_data_range(params)
103
+
104
+ params
105
+ end
106
+ end
101
107
 
108
+ class DataRTR500Params < DataParams
109
+ def initialize(param, serial, base, data_range: nil)
110
+ super(param, serial, data_range: data_range)
111
+ validate_base(base)
112
+ @base = base
113
+ end
114
+
115
+ def validate_base(base)
116
+ unless base.instance_of?(String)
102
117
  raise Ondotori::WebAPI::Api::Errors::InvaildParameter.new(
103
- "from and to parameter must be nil or Time.", 9992
118
+ "base unit serial must be String.", 9991
104
119
  )
105
120
  end
106
121
  end
107
122
 
108
123
  def to_ondotori_param
109
124
  params = super
110
- params["remote-serial"] = @serial
111
- params["unixtime-from"] = @from.to_i unless @from.nil?
112
- params["unixtime-to"] = @to.to_i unless @to.nil?
113
- params["number"] = @limit if @limit != 0
125
+ params["base-serial"] = @base
114
126
 
115
127
  params
116
128
  end
@@ -10,32 +10,35 @@ module Ondotori
10
10
  @uri = uri
11
11
  end
12
12
 
13
- def current(remote_serial_list: [], base_serial_list: [])
14
- current_param = Api::CurrentParams.new(@param, remote: remote_serial_list, base: base_serial_list)
15
- response = @web_access.access("#{base_uri}current", current_param.to_ondotori_param)
13
+ def access_server(param, uri)
14
+ response = @web_access.access(uri, param.to_ondotori_param)
16
15
  ondotori_response = Ondotori::WebAPI::Api::Response.new(response)
17
16
  ondotori_response.result
18
17
  end
19
18
 
19
+ def current(remote_serial_list: [], base_serial_list: [])
20
+ param = Api::CurrentParams.new(@param, remote: remote_serial_list, base: base_serial_list)
21
+ access_server(param, "#{base_uri}current")
22
+ end
23
+
20
24
  def latest_data(serial)
21
25
  param = Api::LatestDataParams.new(@param, serial: serial)
22
- response = @web_access.access("#{base_uri}latest-data", param.to_ondotori_param)
23
- ondotori_response = Ondotori::WebAPI::Api::Response.new(response)
24
- ondotori_response.result
26
+ access_server(param, "#{base_uri}latest-data")
25
27
  end
26
28
 
27
29
  def latest_data_rtr500(base: "", remote: "")
28
30
  param = Api::LatestDataRTR500Params.new(@param, base: base, remote: remote)
29
- response = @web_access.access("#{base_uri}latest-data-rtr500", param.to_ondotori_param)
30
- ondotori_response = Ondotori::WebAPI::Api::Response.new(response)
31
- ondotori_response.result
31
+ access_server(param, "#{base_uri}latest-data-rtr500")
32
32
  end
33
33
 
34
- def data(serial, from: nil, to: nil, limit: nil)
35
- param = Api::DataParams.new(@param, serial, from: from, to: to, limit: limit)
36
- response = @web_access.access("#{base_uri}data", param.to_ondotori_param)
37
- ondotori_response = Ondotori::WebAPI::Api::Response.new(response)
38
- ondotori_response.result
34
+ def data(serial, data_range: nil)
35
+ param = Api::DataParams.new(@param, serial, data_range: data_range)
36
+ access_server(param, "#{base_uri}data")
37
+ end
38
+
39
+ def data_rtr500(base: "", remote: "", data_range: nil)
40
+ param = Api::DataRTR500Params.new(@param, remote, base, data_range: data_range)
41
+ access_server(param, "#{base_uri}data-rtr500")
39
42
  end
40
43
 
41
44
  def base_uri
@@ -13,14 +13,15 @@ module Ondotori
13
13
  end
14
14
 
15
15
  class StbWebAccess < WebAccess
16
- attr_reader :params
16
+ attr_reader :params, :uri
17
17
 
18
18
  def initialize(timeout, on_access)
19
19
  super timeout
20
20
  @on_access = on_access
21
21
  end
22
22
 
23
- def access(_uri, params)
23
+ def access(uri, params)
24
+ @uri = uri
24
25
  @params = params
25
26
  @on_access.call(self)
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ondotori-ruby-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.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-02-27 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: You can use this gem to get the recorded data from WebStorage.
14
14
  email:
@@ -31,6 +31,7 @@ files:
31
31
  - example/get_current_temp.rb
32
32
  - lib/ondotori-ruby-client.rb
33
33
  - lib/ondotori/version.rb
34
+ - lib/ondotori/webapi/api/data_range.rb
34
35
  - lib/ondotori/webapi/api/errors.rb
35
36
  - lib/ondotori/webapi/api/param.rb
36
37
  - lib/ondotori/webapi/api/params.rb