Skip to content
This repository was archived by the owner on Jun 29, 2024. It is now read-only.

Commit

Permalink
Merge pull request #14 from koshilife/develop
Browse files Browse the repository at this point in the history
release 0.5.1
  • Loading branch information
koshilife authored Sep 3, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 2c49933 + 86ad22b commit 6dba38d
Showing 12 changed files with 147 additions and 140 deletions.
20 changes: 11 additions & 9 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -23,12 +23,11 @@ Metrics/BlockNesting:
Max: 2

Layout/LineLength:
AllowURI: true
Enabled: false
Max: 120

Metrics/MethodLength:
CountComments: false
Max: 15
Max: 20

Metrics/ParameterLists:
Max: 4
@@ -39,10 +38,10 @@ Metrics/AbcSize:

Style/CollectionMethods:
PreferredMethods:
map: 'collect'
reduce: 'inject'
find: 'detect'
find_all: 'select'
map: "collect"
reduce: "inject"
find: "detect"
find_all: "select"

Style/Documentation:
Enabled: false
@@ -60,10 +59,13 @@ Style/ExpandPathArguments:
Enabled: false

Style/HashSyntax:
EnforcedStyle: hash_rockets
EnforcedStyle: ruby19

Style/Lambda:
Enabled: false

Style/RaiseArgs:
EnforcedStyle: compact
EnforcedStyle: compact

Style/AsciiComments:
Enabled: false
26 changes: 16 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# 0.5.0
# CHANGELOG

## 0.5.1

- fix rubocop warnings.

## 0.5.0

- refs #12 fix dependencies.

# 0.4.1
## 0.4.1

- refs #4 fix settings for simplecov.

# 0.4.0
## 0.4.0

- refs #4 measure code coverage
- refs #5 setup GitHub Actions for rspec and pushing to RubyGems

# 0.3.0
## 0.3.0

changed Result hash to be Object.

@@ -22,24 +28,24 @@ result.items[0][:weight]
result.items[0].weight
```

# 0.2.3
## 0.2.3

remove Gemfile.lock

# 0.2.2
## 0.2.2

- define constants
- `Tanita::Api::Client::AUTH_URL`
- `Tanita::Api::Client::AUTH_URL_PATH`
- `Tanita::Api::Client::TOKEN_URL`
- `Tanita::Api::Client::TOKEN_URL_PATH`

# 0.2.1
## 0.2.1

- rename constant
- from `Tanita::Api::Client::HttpHelper::BASE_URL` to `Tanita::Api::Client::BASE_URL`

# 0.2.0
## 0.2.0

- set required ruby version to greater than or equal to v2.4
- added `data_type` argument in BaseApiClient#initialize
@@ -49,11 +55,11 @@ remove Gemfile.lock
- `@data` to `@items`
- `@data[0][:date]` to `@items[0][:measured_at]` or `@items[0][:registered_at]`

# 0.1.1
## 0.1.1

- support Tanita::Api::Client.configure
- wrote spec

# 0.1.0
## 0.1.0

- Initial release
8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
7 changes: 4 additions & 3 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require "bundler/setup"
require "tanita/api/client"
require "irb"
require 'bundler/setup'
require 'tanita/api/client'
require 'irb'
IRB.start(__FILE__)
48 changes: 24 additions & 24 deletions lib/tanita/api/client.rb
Original file line number Diff line number Diff line change
@@ -35,21 +35,21 @@ def initialize(client_id: nil, client_secret: nil, redirect_uri: nil, scopes: ni

def auth_uri
params = {
:client_id => @client_id,
:redirect_uri => @redirect_uri,
:scope => @scopes.join(','),
:response_type => 'code'
client_id: @client_id,
redirect_uri: @redirect_uri,
scope: @scopes.join(','),
response_type: 'code'
}
generate_uri(AUTH_URL_PATH, params)
end

def exchange_token(auth_code:)
params = {
:client_id => @client_id,
:client_secret => @client_secret,
:redirect_uri => DEFAULT_REDIRECT_URI,
:code => auth_code,
:grant_type => 'authorization_code'
client_id: @client_id,
client_secret: @client_secret,
redirect_uri: DEFAULT_REDIRECT_URI,
code: auth_code,
grant_type: 'authorization_code'
}
res = request(TOKEN_URL_PATH, params)
token = parse_json(res.body)
@@ -76,14 +76,14 @@ def self.endpoint

def self.properties
{
:weight => {:code => '6021', :type => Float},
:body_fat => {:code => '6022', :type => Float},
:muscle_mass => {:code => '6023', :type => Float},
:physique_rating => {:code => '6024', :type => Integer},
:visceral_fat_rating => {:code => '6025', :type => Float},
:basal_metabolic_rate => {:code => '6027', :type => Integer},
:metabolic_age => {:code => '6028', :type => Integer},
:bone_mass => {:code => '6029', :type => Float}
weight: {code: '6021', type: Float},
body_fat: {code: '6022', type: Float},
muscle_mass: {code: '6023', type: Float},
physique_rating: {code: '6024', type: Integer},
visceral_fat_rating: {code: '6025', type: Float},
basal_metabolic_rate: {code: '6027', type: Integer},
metabolic_age: {code: '6028', type: Integer},
bone_mass: {code: '6029', type: Float}
}
end
end
@@ -95,9 +95,9 @@ def self.endpoint

def self.properties
{
:maximal_pressure => {:code => '622E', :type => Integer},
:minimal_pressure => {:code => '622F', :type => Integer},
:pulse => {:code => '6230', :type => Integer}
maximal_pressure: {code: '622E', type: Integer},
minimal_pressure: {code: '622F', type: Integer},
pulse: {code: '6230', type: Integer}
}
end
end
@@ -109,9 +109,9 @@ def self.endpoint

def self.properties
{
:steps => {:code => '6331', :type => Integer},
:exercise => {:code => '6335', :type => Integer},
:calories => {:code => '6336', :type => Integer}
steps: {code: '6331', type: Integer},
exercise: {code: '6335', type: Integer},
calories: {code: '6336', type: Integer}
}
end
end
@@ -123,7 +123,7 @@ def self.endpoint

def self.properties
{
:urinary_sugar => {:code => '6240', :type => Integer}
urinary_sugar: {code: '6240', type: Integer}
}
end
end
2 changes: 0 additions & 2 deletions lib/tanita/api/client/base.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
module Tanita
module Api
module Client

module Scope
INNERSCAN = 'innerscan'
SPHYGMOMANOMETER = 'sphygmomanometer'
@@ -16,7 +15,6 @@ def self.all

class Error < StandardError
end

end
end
end
24 changes: 13 additions & 11 deletions lib/tanita/api/client/base_api_client.rb
Original file line number Diff line number Diff line change
@@ -26,7 +26,9 @@ def initialize(access_token: nil, date_type: DATE_TYPE_MEASURED_AT)
raise Error.new("param:'access_token' is required.'") if @access_token.nil?

@date_type = date_type
raise Error.new("param:'date_type' is invalid.'") unless [DATE_TYPE_REGISTERD_AT, DATE_TYPE_MEASURED_AT].include? date_type
unless [DATE_TYPE_REGISTERD_AT, DATE_TYPE_MEASURED_AT].include? date_type
raise Error.new("param:'date_type' is invalid.'")
end

ClassBuilder.load
end
@@ -37,9 +39,9 @@ def status(
)
tags = self.class.properties.values.map { |i| i[:code] }.join(',')
params = {
:access_token => @access_token,
:date => @date_type,
:tag => tags
access_token: @access_token,
date: @date_type,
tag: tags
}
params[:from] = time_format(from) unless from.nil?
params[:to] = time_format(to) unless to.nil?
@@ -56,10 +58,10 @@ def inspect
def build_result(res)
result = parse_json(res.body)
Result.new(
:birth_date => Date.parse(result[:birth_date]),
:height => result[:height].to_f,
:sex => result[:sex],
:items => build_result_items(:raw_items => result[:data])
birth_date: Date.parse(result[:birth_date]),
height: result[:height].to_f,
sex: result[:sex],
items: build_result_items(raw_items: result[:data])
)
end

@@ -69,8 +71,8 @@ def build_result_items(raw_items:)
date = item[:date]
model = item[:model]
key = "#{date}_#{model}"
property = find_property_by_code(:code => item[:tag])
value = cast(:value => item[:keydata], :type => property[:type])
property = find_property_by_code(code: item[:tag])
value = cast(value: item[:keydata], type: property[:type])
item_dic[key] ||= {}
item_dic[key][date_key] = Time.parse("#{date} +09:00").to_i unless item_dic[key].key? :date
item_dic[key][:model] = model unless item_dic[key].key? :model
@@ -93,7 +95,7 @@ def find_property_by_code(code:)

@property_code_dic = {}
self.class.properties.each do |m_name, m_info|
@property_code_dic[m_info[:code]] = {:name => m_name, :type => m_info[:type]}
@property_code_dic[m_info[:code]] = {name: m_name, type: m_info[:type]}
end
@property_code_dic[code]
end
2 changes: 1 addition & 1 deletion lib/tanita/api/client/base_entity.rb
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ def initialize(property_values = {})
def to_h
ret = {}
self.class.properties.each do |property|
ret[property.to_sym] = eval property.to_s
ret[property.to_sym] = eval property.to_s # rubocop:disable Security/Eval
end
ret
end
14 changes: 5 additions & 9 deletions lib/tanita/api/client/configuration.rb
Original file line number Diff line number Diff line change
@@ -4,19 +4,15 @@ module Tanita
module Api
module Client
class Configuration
# [String]
# @return [String]
attr_accessor :client_id

# [String]
# @return [String]
attr_accessor :client_secret

# [String]
# @return [String]
attr_accessor :redirect_uri

# [String]
# @return [String]
attr_accessor :access_token

# [Array<Tanita::Api::Client::Scope>]
# @return [Array<Tanita::Api::Client::Scope>]
attr_accessor :scopes
end
end
2 changes: 1 addition & 1 deletion lib/tanita/api/client/helpers.rb
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def request(path, params)
end

def parse_json(str)
JSON.parse(str, :symbolize_names => true)
JSON.parse(str, symbolize_names: true)
rescue JSON::ParserError => e
raise Error.new("JSON::ParseError: '#{e}'\nstr:#{str}")
end
2 changes: 1 addition & 1 deletion lib/tanita/api/client/version.rb
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
module Tanita
module Api
module Client
VERSION = '0.5.0'
VERSION = '0.5.1'
end
end
end
Loading
Oops, something went wrong.

0 comments on commit 6dba38d

Please sign in to comment.