tanita-api-client 0.2.3 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/gem-push.yml +37 -0
- data/.github/workflows/test.yml +21 -0
- data/CHANGELOG.md +45 -19
- data/README.md +16 -9
- data/bin/console +0 -8
- data/bin/setup +0 -2
- 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 +8 -5
- metadata +53 -20
- data/.travis.yml +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 737f202f36b984c1ed0e834a6268232b876279f95dc5c8ef18c5e050b7bd1c81
|
4
|
+
data.tar.gz: a43bd145e16d174f73cb9b5a1c7fc595eac5c1f2d277df7fca4fc52955b72659
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e1ec5042d3cf0fca881b1080421733e96d56a83bb96e870f37143b63d1a3a4baced1e848f99f22099555afe03ab26ef0cc6444a5e78c38d469080c95af94ef7
|
7
|
+
data.tar.gz: 54bf5cb16391d8ef4a53c3a08f6cef0eec6572640a14c998ac2fae375b5cfe1752d03a97ae901660ea2029abb37a489bc2ba85508268609913284199f88cdefc
|
@@ -0,0 +1,37 @@
|
|
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
|
+
continue-on-error: true
|
36
|
+
env:
|
37
|
+
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/CHANGELOG.md
CHANGED
@@ -1,33 +1,59 @@
|
|
1
|
-
# 0.
|
1
|
+
# 0.5.0
|
2
|
+
|
3
|
+
- refs #12 fix dependencies.
|
4
|
+
|
5
|
+
# 0.4.1
|
6
|
+
|
7
|
+
- refs #4 fix settings for simplecov.
|
8
|
+
|
9
|
+
# 0.4.0
|
10
|
+
|
11
|
+
- refs #4 measure code coverage
|
12
|
+
- refs #5 setup GitHub Actions for rspec and pushing to RubyGems
|
13
|
+
|
14
|
+
# 0.3.0
|
2
15
|
|
3
|
-
|
4
|
-
* `Tanita::Api::Client::AUTH_URL`
|
5
|
-
* `Tanita::Api::Client::AUTH_URL_PATH`
|
6
|
-
* `Tanita::Api::Client::TOKEN_URL`
|
7
|
-
* `Tanita::Api::Client::TOKEN_URL_PATH`
|
16
|
+
changed Result hash to be Object.
|
8
17
|
|
18
|
+
```
|
19
|
+
# before
|
20
|
+
result.items[0][:weight]
|
21
|
+
# after
|
22
|
+
result.items[0].weight
|
23
|
+
```
|
24
|
+
|
25
|
+
# 0.2.3
|
26
|
+
|
27
|
+
remove Gemfile.lock
|
28
|
+
|
29
|
+
# 0.2.2
|
30
|
+
|
31
|
+
- define constants
|
32
|
+
- `Tanita::Api::Client::AUTH_URL`
|
33
|
+
- `Tanita::Api::Client::AUTH_URL_PATH`
|
34
|
+
- `Tanita::Api::Client::TOKEN_URL`
|
35
|
+
- `Tanita::Api::Client::TOKEN_URL_PATH`
|
9
36
|
|
10
37
|
# 0.2.1
|
11
38
|
|
12
|
-
|
13
|
-
|
39
|
+
- rename constant
|
40
|
+
- from `Tanita::Api::Client::HttpHelper::BASE_URL` to `Tanita::Api::Client::BASE_URL`
|
14
41
|
|
15
42
|
# 0.2.0
|
16
43
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
44
|
+
- set required ruby version to greater than or equal to v2.4
|
45
|
+
- added `data_type` argument in BaseApiClient#initialize
|
46
|
+
- set a proper data type in Result class attributes
|
47
|
+
- rename some attributes in Result class
|
48
|
+
- e.g.
|
49
|
+
- `@data` to `@items`
|
50
|
+
- `@data[0][:date]` to `@items[0][:measured_at]` or `@items[0][:registered_at]`
|
24
51
|
|
25
52
|
# 0.1.1
|
26
53
|
|
27
|
-
|
28
|
-
|
54
|
+
- support Tanita::Api::Client.configure
|
55
|
+
- wrote spec
|
29
56
|
|
30
57
|
# 0.1.0
|
31
58
|
|
32
|
-
|
33
|
-
|
59
|
+
- Initial release
|
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
# Tanita::Api::Client
|
2
2
|
|
3
|
+
[![Test](https://github.com/koshilife/tanita-api-ruby-client/workflows/Test/badge.svg)](https://github.com/koshilife/tanita-api-ruby-client/actions?query=workflow%3ATest)
|
4
|
+
[![codecov](https://codecov.io/gh/koshilife/tanita-api-ruby-client/branch/master/graph/badge.svg)](https://codecov.io/gh/koshilife/tanita-api-ruby-client)
|
3
5
|
[![Gem Version](https://badge.fury.io/rb/tanita-api-client.svg)](http://badge.fury.io/rb/tanita-api-client)
|
6
|
+
[![license](https://img.shields.io/github/license/koshilife/tanita-api-ruby-client)](https://github.com/koshilife/tanita-api-ruby-client/blob/master/LICENSE.txt)
|
4
7
|
|
5
8
|
## About
|
6
9
|
|
@@ -92,7 +95,7 @@ result = api.status
|
|
92
95
|
result = api.status(from: Date.current.ago(1.month), to: Date.current)
|
93
96
|
|
94
97
|
# list the body-weight data
|
95
|
-
result.items.each{|item| puts "#{Time.at(item
|
98
|
+
result.items.each{|item| puts "#{Time.at(item.measured_at).strftime('%F %R')} => #{item.weight}" }
|
96
99
|
2019-10-10 08:09 => 66.7
|
97
100
|
2019-10-11 09:02 => 66.5
|
98
101
|
2019-10-13 08:22 => 66.7
|
@@ -101,23 +104,27 @@ result.items.each{|item| puts "#{Time.at(item[:measured_at]).strftime('%F %R')}
|
|
101
104
|
|
102
105
|
# Result of Innerscan Api
|
103
106
|
result = Tanita::Api::Client::Innerscan.new.status
|
104
|
-
|
105
|
-
|
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
|
106
112
|
|
107
113
|
# Result of Sphygmomanometer Api
|
108
114
|
result = Tanita::Api::Client::Sphygmomanometer.new.status
|
109
|
-
result.items[0]
|
110
|
-
=>
|
115
|
+
result.items[0]
|
116
|
+
=> #<Tanita::Api::Client::SphygmomanometerItem:70199592475760 properties=measured_at,registered_at,model,maximal_pressure,minimal_pressure,pulse>
|
111
117
|
|
112
118
|
# Result of Pedometer Api
|
113
119
|
result = Tanita::Api::Client::Pedometer.new.status
|
114
|
-
result.items[0]
|
115
|
-
=>
|
120
|
+
result.items[0]
|
121
|
+
=> #<Tanita::Api::Client::PedometerItem:70199605021160 properties=measured_at,registered_at,model,steps,exercise,calories>
|
122
|
+
|
116
123
|
|
117
124
|
# Result of Smug Api
|
118
125
|
result = Tanita::Api::Client::Smug.new.status
|
119
|
-
result.items[0]
|
120
|
-
=>
|
126
|
+
result.items[0]
|
127
|
+
=> #<Tanita::Api::Client::SmugItem:70199600803680 properties=measured_at,registered_at,model,urinary_sugar>
|
121
128
|
|
122
129
|
# common attributes of Result class
|
123
130
|
result.birth_date # [Date]
|
data/bin/console
CHANGED
@@ -2,13 +2,5 @@
|
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
4
|
require "tanita/api/client"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
5
|
require "irb"
|
14
6
|
IRB.start(__FILE__)
|
data/bin/setup
CHANGED
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.
|
@@ -29,8 +30,10 @@ Gem::Specification.new do |spec|
|
|
29
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
31
|
spec.require_paths = ['lib']
|
31
32
|
|
32
|
-
spec.add_development_dependency 'bundler'
|
33
|
-
spec.add_development_dependency '
|
34
|
-
spec.add_development_dependency '
|
35
|
-
spec.add_development_dependency '
|
33
|
+
spec.add_development_dependency 'bundler'
|
34
|
+
spec.add_development_dependency 'codecov'
|
35
|
+
spec.add_development_dependency 'rake'
|
36
|
+
spec.add_development_dependency 'rspec'
|
37
|
+
spec.add_development_dependency 'simplecov'
|
38
|
+
spec.add_development_dependency 'webmock'
|
36
39
|
end
|
metadata
CHANGED
@@ -1,71 +1,99 @@
|
|
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.5.0
|
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-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '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'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
47
|
+
version: '0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rspec
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
|
-
- - "
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
46
74
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
75
|
+
version: '0'
|
48
76
|
type: :development
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
|
-
- - "
|
80
|
+
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
82
|
+
version: '0'
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: webmock
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
58
86
|
requirements:
|
59
|
-
- - "
|
87
|
+
- - ">="
|
60
88
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
89
|
+
version: '0'
|
62
90
|
type: :development
|
63
91
|
prerelease: false
|
64
92
|
version_requirements: !ruby/object:Gem::Requirement
|
65
93
|
requirements:
|
66
|
-
- - "
|
94
|
+
- - ">="
|
67
95
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
96
|
+
version: '0'
|
69
97
|
description: Client for accessing Tanita Health Planet APIs
|
70
98
|
email:
|
71
99
|
- koshikawa2009@gmail.com
|
@@ -73,10 +101,11 @@ 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
|
@@ -87,6 +116,9 @@ files:
|
|
87
116
|
- bin/setup
|
88
117
|
- lib/tanita/api/client.rb
|
89
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
|
90
122
|
- lib/tanita/api/client/configuration.rb
|
91
123
|
- lib/tanita/api/client/helpers.rb
|
92
124
|
- lib/tanita/api/client/version.rb
|
@@ -98,6 +130,7 @@ metadata:
|
|
98
130
|
homepage_uri: https://github.com/koshilife/tanita-api-ruby-client
|
99
131
|
source_code_uri: https://github.com/koshilife/tanita-api-ruby-client
|
100
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.5.0
|
101
134
|
post_install_message:
|
102
135
|
rdoc_options: []
|
103
136
|
require_paths:
|
@@ -113,7 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
146
|
- !ruby/object:Gem::Version
|
114
147
|
version: '0'
|
115
148
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.0.3
|
117
150
|
signing_key:
|
118
151
|
specification_version: 4
|
119
152
|
summary: Client for accessing Tanita Health Planet APIs
|