tanita-api-client 0.2.2 → 0.4.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 +4 -4
- data/.github/workflows/gem-push.yml +36 -0
- data/.github/workflows/test.yml +21 -0
- data/.gitignore +2 -0
- data/CHANGELOG.md +41 -19
- data/README.md +17 -9
- data/lib/tanita/api/client.rb +15 -12
- data/lib/tanita/api/client/base.rb +1 -119
- data/lib/tanita/api/client/base_api_client.rb +112 -0
- data/lib/tanita/api/client/base_entity.rb +26 -0
- data/lib/tanita/api/client/class_builder.rb +61 -0
- data/lib/tanita/api/client/helpers.rb +5 -1
- data/lib/tanita/api/client/version.rb +1 -1
- data/tanita-api-client.gemspec +4 -1
- metadata +37 -5
- data/.travis.yml +0 -7
- data/Gemfile.lock +0 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cef71ec4b4f23cc1fd850b5af941352ce271e4fa61e1ca9fb51541b2b8f155e9
|
4
|
+
data.tar.gz: 6e9b559345a4a581a29ec6ac255685662f5432aaaf03dc7a83c770900641db45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebe34ad9d7ac97d2e7ddb7f319757998ab0ba740a9799b417250fd267592b89c7b4df950551100e90c3a00c08b1df9dd0d66fe66538462d12166fc611cefcd6c
|
7
|
+
data.tar.gz: 7d603beaa0b12eae0918e4c2ce3916afc55060764f9ddc9343e0692e966978f4fdeba2e1acffc22595e6e55005093aa241223cf767cfcfab59b09a620f43081c
|
@@ -0,0 +1,36 @@
|
|
1
|
+
name: Ruby Gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [master]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
name: Build + Publish
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
|
12
|
+
steps:
|
13
|
+
- uses: actions/checkout@v2
|
14
|
+
- name: Set up Ruby 2.6
|
15
|
+
uses: actions/setup-ruby@v1
|
16
|
+
with:
|
17
|
+
ruby-version: 2.6
|
18
|
+
|
19
|
+
- name: Build and test
|
20
|
+
run: |
|
21
|
+
gem install bundler
|
22
|
+
bundle install --jobs 4 --retry 3
|
23
|
+
bundle exec rspec
|
24
|
+
env:
|
25
|
+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
|
26
|
+
|
27
|
+
- name: Publish to RubyGems
|
28
|
+
run: |
|
29
|
+
mkdir -p $HOME/.gem
|
30
|
+
touch $HOME/.gem/credentials
|
31
|
+
chmod 0600 $HOME/.gem/credentials
|
32
|
+
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
|
33
|
+
gem build *.gemspec
|
34
|
+
gem push *.gem
|
35
|
+
env:
|
36
|
+
GEM_HOST_API_KEY: ${{secrets.RUBYGEMS_AUTH_TOKEN}}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
name: Test
|
2
|
+
|
3
|
+
on: pull_request
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
|
9
|
+
steps:
|
10
|
+
- uses: actions/checkout@v2
|
11
|
+
- name: Set up Ruby
|
12
|
+
uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: 2.6
|
15
|
+
- name: Build and test
|
16
|
+
run: |
|
17
|
+
gem install bundler
|
18
|
+
bundle install --jobs 4 --retry 3
|
19
|
+
bundle exec rspec
|
20
|
+
env:
|
21
|
+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,33 +1,55 @@
|
|
1
|
-
# 0.
|
1
|
+
# 0.4.1
|
2
|
+
|
3
|
+
- refs #4 fix settings for simplecov.
|
4
|
+
|
5
|
+
# 0.4.0
|
6
|
+
|
7
|
+
- refs #4 measure code coverage
|
8
|
+
- refs #5 setup GitHub Actions for rspec and pushing to RubyGems
|
9
|
+
|
10
|
+
# 0.3.0
|
11
|
+
|
12
|
+
changed Result hash to be Object.
|
2
13
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
14
|
+
```
|
15
|
+
# before
|
16
|
+
result.items[0][:weight]
|
17
|
+
# after
|
18
|
+
result.items[0].weight
|
19
|
+
```
|
8
20
|
|
21
|
+
# 0.2.3
|
22
|
+
|
23
|
+
remove Gemfile.lock
|
24
|
+
|
25
|
+
# 0.2.2
|
26
|
+
|
27
|
+
- define constants
|
28
|
+
- `Tanita::Api::Client::AUTH_URL`
|
29
|
+
- `Tanita::Api::Client::AUTH_URL_PATH`
|
30
|
+
- `Tanita::Api::Client::TOKEN_URL`
|
31
|
+
- `Tanita::Api::Client::TOKEN_URL_PATH`
|
9
32
|
|
10
33
|
# 0.2.1
|
11
34
|
|
12
|
-
|
13
|
-
|
35
|
+
- rename constant
|
36
|
+
- from `Tanita::Api::Client::HttpHelper::BASE_URL` to `Tanita::Api::Client::BASE_URL`
|
14
37
|
|
15
38
|
# 0.2.0
|
16
39
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
40
|
+
- set required ruby version to greater than or equal to v2.4
|
41
|
+
- added `data_type` argument in BaseApiClient#initialize
|
42
|
+
- set a proper data type in Result class attributes
|
43
|
+
- rename some attributes in Result class
|
44
|
+
- e.g.
|
45
|
+
- `@data` to `@items`
|
46
|
+
- `@data[0][:date]` to `@items[0][:measured_at]` or `@items[0][:registered_at]`
|
24
47
|
|
25
48
|
# 0.1.1
|
26
49
|
|
27
|
-
|
28
|
-
|
50
|
+
- support Tanita::Api::Client.configure
|
51
|
+
- wrote spec
|
29
52
|
|
30
53
|
# 0.1.0
|
31
54
|
|
32
|
-
|
33
|
-
|
55
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
# Tanita::Api::Client
|
2
2
|
|
3
|
+
[](https://github.com/koshilife/tanita-api-ruby-client/actions?query=workflow%3ATest)
|
4
|
+
[](https://codecov.io/gh/koshilife/tanita-api-ruby-client)
|
5
|
+
[](http://badge.fury.io/rb/tanita-api-client)
|
6
|
+
[](https://github.com/koshilife/tanita-api-ruby-client/blob/master/LICENSE.txt)
|
3
7
|
|
4
8
|
## About
|
5
9
|
|
@@ -91,7 +95,7 @@ result = api.status
|
|
91
95
|
result = api.status(from: Date.current.ago(1.month), to: Date.current)
|
92
96
|
|
93
97
|
# list the body-weight data
|
94
|
-
result.items.each{|item| puts "#{Time.at(item
|
98
|
+
result.items.each{|item| puts "#{Time.at(item.measured_at).strftime('%F %R')} => #{item.weight}" }
|
95
99
|
2019-10-10 08:09 => 66.7
|
96
100
|
2019-10-11 09:02 => 66.5
|
97
101
|
2019-10-13 08:22 => 66.7
|
@@ -100,23 +104,27 @@ result.items.each{|item| puts "#{Time.at(item[:measured_at]).strftime('%F %R')}
|
|
100
104
|
|
101
105
|
# Result of Innerscan Api
|
102
106
|
result = Tanita::Api::Client::Innerscan.new.status
|
103
|
-
|
104
|
-
|
107
|
+
=> #<Tanita::Api::Client::Result:70199592389780 properties=birth_date,height,sex,items>
|
108
|
+
result.items[0]
|
109
|
+
=> #<Tanita::Api::Client::InnerscanItem:70199597695880 properties=measured_at,registered_at,model,weight,body_fat,muscle_mass,physique_rating,visceral_fat_rating,basal_metabolic_rate,metabolic_age,bone_mass>
|
110
|
+
result.items[0].weight
|
111
|
+
=> 66.7
|
105
112
|
|
106
113
|
# Result of Sphygmomanometer Api
|
107
114
|
result = Tanita::Api::Client::Sphygmomanometer.new.status
|
108
|
-
result.items[0]
|
109
|
-
=>
|
115
|
+
result.items[0]
|
116
|
+
=> #<Tanita::Api::Client::SphygmomanometerItem:70199592475760 properties=measured_at,registered_at,model,maximal_pressure,minimal_pressure,pulse>
|
110
117
|
|
111
118
|
# Result of Pedometer Api
|
112
119
|
result = Tanita::Api::Client::Pedometer.new.status
|
113
|
-
result.items[0]
|
114
|
-
=>
|
120
|
+
result.items[0]
|
121
|
+
=> #<Tanita::Api::Client::PedometerItem:70199605021160 properties=measured_at,registered_at,model,steps,exercise,calories>
|
122
|
+
|
115
123
|
|
116
124
|
# Result of Smug Api
|
117
125
|
result = Tanita::Api::Client::Smug.new.status
|
118
|
-
result.items[0]
|
119
|
-
=>
|
126
|
+
result.items[0]
|
127
|
+
=> #<Tanita::Api::Client::SmugItem:70199600803680 properties=measured_at,registered_at,model,urinary_sugar>
|
120
128
|
|
121
129
|
# common attributes of Result class
|
122
130
|
result.birth_date # [Date]
|
data/lib/tanita/api/client.rb
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
Dir[
|
4
|
+
File.join(
|
5
|
+
File.dirname(__FILE__),
|
6
|
+
'client',
|
7
|
+
'*'
|
8
|
+
)
|
9
|
+
].sort.each { |f| require f }
|
7
10
|
|
8
11
|
module Tanita
|
9
12
|
module Api
|
@@ -67,11 +70,11 @@ module Tanita
|
|
67
70
|
end
|
68
71
|
|
69
72
|
class Innerscan < BaseApiClient
|
70
|
-
def endpoint
|
73
|
+
def self.endpoint
|
71
74
|
'/status/innerscan.json'
|
72
75
|
end
|
73
76
|
|
74
|
-
def
|
77
|
+
def self.properties
|
75
78
|
{
|
76
79
|
:weight => {:code => '6021', :type => Float},
|
77
80
|
:body_fat => {:code => '6022', :type => Float},
|
@@ -86,11 +89,11 @@ module Tanita
|
|
86
89
|
end
|
87
90
|
|
88
91
|
class Sphygmomanometer < BaseApiClient
|
89
|
-
def endpoint
|
92
|
+
def self.endpoint
|
90
93
|
'/status/sphygmomanometer.json'
|
91
94
|
end
|
92
95
|
|
93
|
-
def
|
96
|
+
def self.properties
|
94
97
|
{
|
95
98
|
:maximal_pressure => {:code => '622E', :type => Integer},
|
96
99
|
:minimal_pressure => {:code => '622F', :type => Integer},
|
@@ -100,11 +103,11 @@ module Tanita
|
|
100
103
|
end
|
101
104
|
|
102
105
|
class Pedometer < BaseApiClient
|
103
|
-
def endpoint
|
106
|
+
def self.endpoint
|
104
107
|
'/status/pedometer.json'
|
105
108
|
end
|
106
109
|
|
107
|
-
def
|
110
|
+
def self.properties
|
108
111
|
{
|
109
112
|
:steps => {:code => '6331', :type => Integer},
|
110
113
|
:exercise => {:code => '6335', :type => Integer},
|
@@ -114,11 +117,11 @@ module Tanita
|
|
114
117
|
end
|
115
118
|
|
116
119
|
class Smug < BaseApiClient
|
117
|
-
def endpoint
|
120
|
+
def self.endpoint
|
118
121
|
'/status/smug.json'
|
119
122
|
end
|
120
123
|
|
121
|
-
def
|
124
|
+
def self.properties
|
122
125
|
{
|
123
126
|
:urinary_sugar => {:code => '6240', :type => Integer}
|
124
127
|
}
|
@@ -1,11 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'time'
|
4
|
-
require 'tanita/api/client/helpers'
|
5
|
-
|
6
3
|
module Tanita
|
7
4
|
module Api
|
8
5
|
module Client
|
6
|
+
|
9
7
|
module Scope
|
10
8
|
INNERSCAN = 'innerscan'
|
11
9
|
SPHYGMOMANOMETER = 'sphygmomanometer'
|
@@ -19,122 +17,6 @@ module Tanita
|
|
19
17
|
class Error < StandardError
|
20
18
|
end
|
21
19
|
|
22
|
-
DATE_TYPE_REGISTERD_AT = 0
|
23
|
-
DATE_TYPE_MEASURED_AT = 1
|
24
|
-
|
25
|
-
class BaseApiClient
|
26
|
-
include HttpHelper
|
27
|
-
|
28
|
-
def initialize(access_token: nil, date_type: DATE_TYPE_MEASURED_AT)
|
29
|
-
config = Tanita::Api::Client.configuration
|
30
|
-
@access_token = access_token || config.access_token
|
31
|
-
raise Error.new("param:'access_token' is required.'") if @access_token.nil?
|
32
|
-
|
33
|
-
@date_type = date_type
|
34
|
-
raise Error.new("param:'date_type' is invalid.'") unless [DATE_TYPE_REGISTERD_AT, DATE_TYPE_MEASURED_AT].include? date_type
|
35
|
-
end
|
36
|
-
|
37
|
-
def status(
|
38
|
-
from: nil,
|
39
|
-
to: nil
|
40
|
-
)
|
41
|
-
tags = measurement_tags.values.map { |i| i[:code] }.join(',')
|
42
|
-
params = {
|
43
|
-
:access_token => @access_token,
|
44
|
-
:date => @date_type,
|
45
|
-
:tag => tags
|
46
|
-
}
|
47
|
-
params[:from] = time_format(from) unless from.nil?
|
48
|
-
params[:to] = time_format(to) unless to.nil?
|
49
|
-
res = request(endpoint, params)
|
50
|
-
Result.new(:client => self, :response => res)
|
51
|
-
end
|
52
|
-
|
53
|
-
def endpoint
|
54
|
-
raise NotImplementedError
|
55
|
-
end
|
56
|
-
|
57
|
-
def measurement_tags
|
58
|
-
raise NotImplementedError
|
59
|
-
end
|
60
|
-
|
61
|
-
def find_measurement_tag(code:)
|
62
|
-
return @inverted_measurement[code] unless @inverted_measurement.nil?
|
63
|
-
|
64
|
-
@inverted_measurement = {}
|
65
|
-
measurement_tags.each do |m_name, m_info|
|
66
|
-
@inverted_measurement[m_info[:code]] = {:name => m_name, :type => m_info[:type]}
|
67
|
-
end
|
68
|
-
@inverted_measurement[code]
|
69
|
-
end
|
70
|
-
|
71
|
-
def date_key
|
72
|
-
case @date_type
|
73
|
-
when DATE_TYPE_REGISTERD_AT
|
74
|
-
:registered_at
|
75
|
-
when DATE_TYPE_MEASURED_AT
|
76
|
-
:measured_at
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
private
|
81
|
-
|
82
|
-
def time_format(time)
|
83
|
-
time.strftime('%Y%m%d%H%M%S')
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
class Result
|
88
|
-
include HttpHelper
|
89
|
-
|
90
|
-
# [Date]
|
91
|
-
attr_reader :birth_date
|
92
|
-
|
93
|
-
# [Float] (centimeter)
|
94
|
-
attr_reader :height
|
95
|
-
|
96
|
-
# [String] 'male' or 'female'
|
97
|
-
attr_reader :sex
|
98
|
-
|
99
|
-
# [Array<Hash>]
|
100
|
-
attr_reader :items
|
101
|
-
|
102
|
-
def initialize(client:, response:)
|
103
|
-
@client = client
|
104
|
-
result = parse_json(response.body)
|
105
|
-
@birth_date = Date.parse(result[:birth_date])
|
106
|
-
@height = result[:height].to_f
|
107
|
-
@sex = result[:sex]
|
108
|
-
@items = build_items(result[:data])
|
109
|
-
end
|
110
|
-
|
111
|
-
private
|
112
|
-
|
113
|
-
def build_items(raw_items)
|
114
|
-
item_dic = {}
|
115
|
-
raw_items.each do |item|
|
116
|
-
date = item[:date]
|
117
|
-
model = item[:model]
|
118
|
-
key = "#{date}_#{model}"
|
119
|
-
measurement = @client.find_measurement_tag(:code => item[:tag])
|
120
|
-
value = cast(:value => item[:keydata], :type => measurement[:type])
|
121
|
-
item_dic[key] ||= {}
|
122
|
-
item_dic[key][@client.date_key] = Time.parse("#{date} +09:00").to_i unless item_dic[key].key? :date
|
123
|
-
item_dic[key][:model] = model unless item_dic[key].key? :model
|
124
|
-
item_dic[key][measurement[:name]] = value
|
125
|
-
end
|
126
|
-
# sort by date in ascending order
|
127
|
-
item_dic.values.sort_by { |dic| dic[@client.date_key] }
|
128
|
-
end
|
129
|
-
|
130
|
-
def cast(value:, type:)
|
131
|
-
return value if value.nil?
|
132
|
-
return value.to_i if type == Integer
|
133
|
-
return value.to_f if type == Float
|
134
|
-
|
135
|
-
value
|
136
|
-
end
|
137
|
-
end
|
138
20
|
end
|
139
21
|
end
|
140
22
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'tanita/api/client/helpers'
|
5
|
+
|
6
|
+
module Tanita
|
7
|
+
module Api
|
8
|
+
module Client
|
9
|
+
DATE_TYPE_REGISTERD_AT = 0
|
10
|
+
DATE_TYPE_MEASURED_AT = 1
|
11
|
+
|
12
|
+
class BaseApiClient
|
13
|
+
include HttpHelper
|
14
|
+
|
15
|
+
def self.endpoint
|
16
|
+
raise NotImplementedError
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.properties
|
20
|
+
raise NotImplementedError
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(access_token: nil, date_type: DATE_TYPE_MEASURED_AT)
|
24
|
+
config = Tanita::Api::Client.configuration
|
25
|
+
@access_token = access_token || config.access_token
|
26
|
+
raise Error.new("param:'access_token' is required.'") if @access_token.nil?
|
27
|
+
|
28
|
+
@date_type = date_type
|
29
|
+
raise Error.new("param:'date_type' is invalid.'") unless [DATE_TYPE_REGISTERD_AT, DATE_TYPE_MEASURED_AT].include? date_type
|
30
|
+
|
31
|
+
ClassBuilder.load
|
32
|
+
end
|
33
|
+
|
34
|
+
def status(
|
35
|
+
from: nil,
|
36
|
+
to: nil
|
37
|
+
)
|
38
|
+
tags = self.class.properties.values.map { |i| i[:code] }.join(',')
|
39
|
+
params = {
|
40
|
+
:access_token => @access_token,
|
41
|
+
:date => @date_type,
|
42
|
+
:tag => tags
|
43
|
+
}
|
44
|
+
params[:from] = time_format(from) unless from.nil?
|
45
|
+
params[:to] = time_format(to) unless to.nil?
|
46
|
+
res = request(self.class.endpoint, params)
|
47
|
+
build_result(res)
|
48
|
+
end
|
49
|
+
|
50
|
+
def inspect
|
51
|
+
"\#<#{self.class}:#{object_id}>"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def build_result(res)
|
57
|
+
result = parse_json(res.body)
|
58
|
+
Result.new(
|
59
|
+
:birth_date => Date.parse(result[:birth_date]),
|
60
|
+
:height => result[:height].to_f,
|
61
|
+
:sex => result[:sex],
|
62
|
+
:items => build_result_items(:raw_items => result[:data])
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def build_result_items(raw_items:)
|
67
|
+
item_dic = {}
|
68
|
+
raw_items.each do |item|
|
69
|
+
date = item[:date]
|
70
|
+
model = item[:model]
|
71
|
+
key = "#{date}_#{model}"
|
72
|
+
property = find_property_by_code(:code => item[:tag])
|
73
|
+
value = cast(:value => item[:keydata], :type => property[:type])
|
74
|
+
item_dic[key] ||= {}
|
75
|
+
item_dic[key][date_key] = Time.parse("#{date} +09:00").to_i unless item_dic[key].key? :date
|
76
|
+
item_dic[key][:model] = model unless item_dic[key].key? :model
|
77
|
+
item_dic[key][property[:name]] = value
|
78
|
+
end
|
79
|
+
items = item_dic.values.sort_by { |dic| dic[date_key] } # sort by date in ascending order
|
80
|
+
items.map { |_item_dic| eval "#{self.class}Item.new _item_dic" }
|
81
|
+
end
|
82
|
+
|
83
|
+
def cast(value:, type:)
|
84
|
+
return value if value.nil?
|
85
|
+
return value.to_i if type == Integer
|
86
|
+
return value.to_f if type == Float
|
87
|
+
|
88
|
+
value
|
89
|
+
end
|
90
|
+
|
91
|
+
def find_property_by_code(code:)
|
92
|
+
return @property_code_dic[code] unless @property_code_dic.nil?
|
93
|
+
|
94
|
+
@property_code_dic = {}
|
95
|
+
self.class.properties.each do |m_name, m_info|
|
96
|
+
@property_code_dic[m_info[:code]] = {:name => m_name, :type => m_info[:type]}
|
97
|
+
end
|
98
|
+
@property_code_dic[code]
|
99
|
+
end
|
100
|
+
|
101
|
+
def date_key
|
102
|
+
case @date_type
|
103
|
+
when DATE_TYPE_REGISTERD_AT
|
104
|
+
:registered_at
|
105
|
+
when DATE_TYPE_MEASURED_AT
|
106
|
+
:measured_at
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tanita
|
4
|
+
module Api
|
5
|
+
module Client
|
6
|
+
class BaseEntity
|
7
|
+
def initialize(property_values = {})
|
8
|
+
@cached_property_values = {}
|
9
|
+
@cached_property_values.merge!(property_values)
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
ret = {}
|
14
|
+
self.class.properties.each do |property|
|
15
|
+
ret[property.to_sym] = eval property.to_s
|
16
|
+
end
|
17
|
+
ret
|
18
|
+
end
|
19
|
+
|
20
|
+
def inspect
|
21
|
+
"\#<#{self.class}:#{object_id} properties=#{self.class.properties.join(',')}>"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Tanita
|
4
|
+
module Api
|
5
|
+
module Client
|
6
|
+
class ClassBuilder
|
7
|
+
def self.load
|
8
|
+
return if loaded
|
9
|
+
|
10
|
+
create_class('Result', %i[birth_date height sex items])
|
11
|
+
base_properties = %i[measured_at registered_at model]
|
12
|
+
[Innerscan, Sphygmomanometer, Pedometer, Smug].each do |klass|
|
13
|
+
klass_name = klass.to_s.split('::')[-1] + 'Item'
|
14
|
+
properties = base_properties + klass.properties.keys
|
15
|
+
create_class(klass_name, properties)
|
16
|
+
end
|
17
|
+
@loaded = true
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.loaded
|
21
|
+
@loaded || false
|
22
|
+
end
|
23
|
+
private_class_method :loaded
|
24
|
+
|
25
|
+
def self.create_class(class_name, property_names = [])
|
26
|
+
super_klass = Class.new(BaseEntity)
|
27
|
+
klass = Tanita::Api::Client.const_set(class_name, super_klass)
|
28
|
+
define_properties_reader(klass)
|
29
|
+
property_names.each do |property_name|
|
30
|
+
klass.properties << property_name
|
31
|
+
define_getter_and_setter(klass, property_name)
|
32
|
+
end
|
33
|
+
klass.properties.freeze
|
34
|
+
end
|
35
|
+
private_class_method :create_class
|
36
|
+
|
37
|
+
def self.define_properties_reader(klass)
|
38
|
+
klass.class_eval do
|
39
|
+
def self.properties
|
40
|
+
@properties = [] if @properties.nil?
|
41
|
+
@properties
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
private_class_method :define_properties_reader
|
46
|
+
|
47
|
+
def self.define_getter_and_setter(klass, property_name)
|
48
|
+
klass.class_eval do
|
49
|
+
define_method(property_name.to_sym) do
|
50
|
+
@cached_property_values[property_name.to_sym]
|
51
|
+
end
|
52
|
+
define_method("#{property_name}=".to_sym) do |value|
|
53
|
+
@cached_property_values[property_name.to_sym] = value
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
private_class_method :define_getter_and_setter
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -11,7 +11,7 @@ module Tanita
|
|
11
11
|
AUTH_URL_PATH = '/oauth/auth'
|
12
12
|
AUTH_URL = "#{BASE_URL}#{AUTH_URL_PATH}"
|
13
13
|
|
14
|
-
TOKEN_URL_PATH =
|
14
|
+
TOKEN_URL_PATH = '/oauth/token'
|
15
15
|
TOKEN_URL = "#{BASE_URL}#{TOKEN_URL_PATH}"
|
16
16
|
|
17
17
|
DEFAULT_REDIRECT_URI = "#{BASE_URL}/success.html"
|
@@ -37,6 +37,10 @@ module Tanita
|
|
37
37
|
rescue JSON::ParserError => e
|
38
38
|
raise Error.new("JSON::ParseError: '#{e}'\nstr:#{str}")
|
39
39
|
end
|
40
|
+
|
41
|
+
def time_format(time)
|
42
|
+
time.strftime('%Y%m%d%H%M%S')
|
43
|
+
end
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
data/tanita-api-client.gemspec
CHANGED
@@ -7,7 +7,7 @@ require 'tanita/api/client/version'
|
|
7
7
|
Gem::Specification.new do |spec|
|
8
8
|
spec.name = 'tanita-api-client'
|
9
9
|
spec.version = Tanita::Api::Client::VERSION
|
10
|
-
spec.authors
|
10
|
+
spec.authors = ['Kenji Koshikawa']
|
11
11
|
spec.email = ['koshikawa2009@gmail.com']
|
12
12
|
|
13
13
|
spec.description = 'Client for accessing Tanita Health Planet APIs'
|
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.metadata['homepage_uri'] = spec.homepage
|
20
20
|
spec.metadata['source_code_uri'] = 'https://github.com/koshilife/tanita-api-ruby-client'
|
21
21
|
spec.metadata['changelog_uri'] = "#{spec.metadata['source_code_uri']}/blob/master/CHANGELOG.md"
|
22
|
+
spec.metadata['documentation_uri'] = "https://www.rubydoc.info/gems/tanita-api-client/#{spec.version}"
|
22
23
|
|
23
24
|
# Specify which files should be added to the gem when it is released.
|
24
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
@@ -30,7 +31,9 @@ Gem::Specification.new do |spec|
|
|
30
31
|
spec.require_paths = ['lib']
|
31
32
|
|
32
33
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
34
|
+
spec.add_development_dependency 'codecov', '~> 0.1.17'
|
33
35
|
spec.add_development_dependency 'rake', '~> 12.0'
|
34
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
37
|
+
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
35
38
|
spec.add_development_dependency 'webmock', '~> 3.7.6'
|
36
39
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tanita-api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kenji Koshikawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: codecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.17
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.17
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,6 +66,20 @@ dependencies:
|
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
68
|
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.18.5
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.18.5
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: webmock
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,14 +101,14 @@ executables: []
|
|
73
101
|
extensions: []
|
74
102
|
extra_rdoc_files: []
|
75
103
|
files:
|
104
|
+
- ".github/workflows/gem-push.yml"
|
105
|
+
- ".github/workflows/test.yml"
|
76
106
|
- ".gitignore"
|
77
107
|
- ".rspec"
|
78
108
|
- ".rubocop.yml"
|
79
|
-
- ".travis.yml"
|
80
109
|
- CHANGELOG.md
|
81
110
|
- CODE_OF_CONDUCT.md
|
82
111
|
- Gemfile
|
83
|
-
- Gemfile.lock
|
84
112
|
- LICENSE.txt
|
85
113
|
- README.md
|
86
114
|
- Rakefile
|
@@ -88,6 +116,9 @@ files:
|
|
88
116
|
- bin/setup
|
89
117
|
- lib/tanita/api/client.rb
|
90
118
|
- lib/tanita/api/client/base.rb
|
119
|
+
- lib/tanita/api/client/base_api_client.rb
|
120
|
+
- lib/tanita/api/client/base_entity.rb
|
121
|
+
- lib/tanita/api/client/class_builder.rb
|
91
122
|
- lib/tanita/api/client/configuration.rb
|
92
123
|
- lib/tanita/api/client/helpers.rb
|
93
124
|
- lib/tanita/api/client/version.rb
|
@@ -99,6 +130,7 @@ metadata:
|
|
99
130
|
homepage_uri: https://github.com/koshilife/tanita-api-ruby-client
|
100
131
|
source_code_uri: https://github.com/koshilife/tanita-api-ruby-client
|
101
132
|
changelog_uri: https://github.com/koshilife/tanita-api-ruby-client/blob/master/CHANGELOG.md
|
133
|
+
documentation_uri: https://www.rubydoc.info/gems/tanita-api-client/0.4.1
|
102
134
|
post_install_message:
|
103
135
|
rdoc_options: []
|
104
136
|
require_paths:
|
@@ -114,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
146
|
- !ruby/object:Gem::Version
|
115
147
|
version: '0'
|
116
148
|
requirements: []
|
117
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.0.3
|
118
150
|
signing_key:
|
119
151
|
specification_version: 4
|
120
152
|
summary: Client for accessing Tanita Health Planet APIs
|
data/.travis.yml
DELETED
data/Gemfile.lock
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
tanita-api-client (0.2.2)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: https://rubygems.org/
|
8
|
-
specs:
|
9
|
-
addressable (2.7.0)
|
10
|
-
public_suffix (>= 2.0.2, < 5.0)
|
11
|
-
crack (0.4.3)
|
12
|
-
safe_yaml (~> 1.0.0)
|
13
|
-
diff-lcs (1.3)
|
14
|
-
hashdiff (1.0.0)
|
15
|
-
public_suffix (4.0.3)
|
16
|
-
rake (12.3.3)
|
17
|
-
rspec (3.9.0)
|
18
|
-
rspec-core (~> 3.9.0)
|
19
|
-
rspec-expectations (~> 3.9.0)
|
20
|
-
rspec-mocks (~> 3.9.0)
|
21
|
-
rspec-core (3.9.1)
|
22
|
-
rspec-support (~> 3.9.1)
|
23
|
-
rspec-expectations (3.9.0)
|
24
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
-
rspec-support (~> 3.9.0)
|
26
|
-
rspec-mocks (3.9.1)
|
27
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
-
rspec-support (~> 3.9.0)
|
29
|
-
rspec-support (3.9.2)
|
30
|
-
safe_yaml (1.0.5)
|
31
|
-
webmock (3.7.6)
|
32
|
-
addressable (>= 2.3.6)
|
33
|
-
crack (>= 0.3.2)
|
34
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
35
|
-
|
36
|
-
PLATFORMS
|
37
|
-
ruby
|
38
|
-
|
39
|
-
DEPENDENCIES
|
40
|
-
bundler (~> 2.0)
|
41
|
-
rake (~> 12.0)
|
42
|
-
rspec (~> 3.0)
|
43
|
-
tanita-api-client!
|
44
|
-
webmock (~> 3.7.6)
|
45
|
-
|
46
|
-
BUNDLED WITH
|
47
|
-
2.1.3
|