softbank-healthcare-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 084ef237f3bbc2bc6bb2a40853ad33252d0c3d81
4
+ data.tar.gz: 5c923928653e8db2d13c878f43c6ac381b9bb3b7
5
+ SHA512:
6
+ metadata.gz: 45e49589da18dd5b417f65079205be7228cfa3612a733e928706da47f548f4052bb5df657fddecd8920e0056c4a88ec6a06f5a3adf3341e953e1b8620b5522ed
7
+ data.tar.gz: c5fe730869bbe8402f49ea6cee445337190e3e0a74f6f8ec3ae0df3fdc9eca4826e8921c6a222f0debba6717716c31cd17cef1d2df4ee40bbc73efae249c1652
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
19
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in healthcare.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Softbank HealthCare Client
2
+
3
+ [Softbank HealthCare](https://healthcare.mb.softbank.jp/pc/) client library for ruby.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'healthcare'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install healthcare
18
+
19
+ ## Usage
20
+
21
+ Require `healthcare` library.
22
+
23
+ ```ruby
24
+ require 'healthcare'
25
+ ```
26
+
27
+ Login to healthcare web service. You can use 301SI tel number and password.
28
+
29
+ ```ruby
30
+ client = HealthCare::Client.new telno: '09012345678', password: '1234'
31
+ ```
32
+
33
+ Fetch and show your health data.
34
+
35
+ ```ruby
36
+ client.weight # 体重(kg)
37
+ client.body_fat # 体脂肪率(%)
38
+ client.bmi # BMI
39
+ client.basal_metabolism # 基礎代謝
40
+ client.physical_age # 身体年齢(歳)
41
+ client.skeletal_muscle_level # 骨格筋レベル
42
+ client.bone_level # 骨レベル
43
+ client.visceral_fat_level # 内臓脂肪レベル
44
+ client.water_content # 水分量 (%)
45
+ ```
46
+
47
+ ## Contributing
48
+
49
+ 1. Fork it ( http://github.com/<my-github-username>/healthcare/fork )
50
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
51
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
52
+ 4. Push to the branch (`git push origin my-new-feature`)
53
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'healthcare/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "softbank-healthcare-client"
8
+ spec.version = HealthCare::VERSION
9
+ spec.authors = ["shunirr"]
10
+ spec.email = ["m@s5r.jp"]
11
+ spec.summary = %q{Softbank HealthCare Client for Ruby}
12
+ spec.description = %q{Softbank HealthCare Client for Ruby}
13
+ spec.homepage = "https://github.com/shunirr/softbank-healthcare-client-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'faraday'
25
+ end
data/lib/healthcare.rb ADDED
@@ -0,0 +1,9 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "healthcare/version"
4
+
5
+ module HealthCare
6
+ autoload :Client, 'healthcare/client'
7
+ autoload :ApiClient, 'healthcare/api_client'
8
+ autoload :Bodycomp, 'healthcare/bodycomp'
9
+ end
@@ -0,0 +1,136 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require 'faraday'
4
+ require 'json'
5
+ require 'date'
6
+
7
+ module HealthCare
8
+ class ApiClient
9
+ def initialize
10
+ @conn = Faraday.new(:url => 'https://healthcare.mb.softbank.jp') do |faraday|
11
+ faraday.request :url_encoded
12
+ faraday.adapter :net_http
13
+ end
14
+ end
15
+
16
+ def login(params = {})
17
+ res = @conn.post '/pc/assets/dispatcher/Register.php', {
18
+ userid: 1,
19
+ register_type: 3,
20
+ api_pattern: 'web_login.php',
21
+ telno: params[:telno],
22
+ passwd: params[:password]
23
+ }
24
+ @cookie = res.headers['set-cookie']
25
+
26
+ res.headers['location'].include? '../home/home.php'
27
+ end
28
+
29
+ def user_data
30
+ get get_type: 11, api_pattern: 'get_user_data.php'
31
+ end
32
+
33
+ def present_top
34
+ get get_type: 10, api_pattern: 'get_present_top.php'
35
+ end
36
+
37
+ def url_master_1
38
+ get get_type: 12, api_pattern: 'get_url_master.php', view_url: 1
39
+ end
40
+
41
+ def url_master_2
42
+ get get_type: 12, api_pattern: 'get_url_master.php', view_url: 2
43
+ end
44
+
45
+ def home_summary(date = Date.today)
46
+ get get_type: 0, api_pattern: 'get_home_summary.php', date: date.strftime('%Y%m%d')
47
+ end
48
+
49
+ def information(last_update_time = Time.new)
50
+ get get_type: 6, api_pattern: 'get_information.php', last_update_time: last_update_time.strftime('%Y%m%d%H%M')
51
+ end
52
+
53
+ def friend_requested_list(params = {})
54
+ get(
55
+ get_type: 5,
56
+ api_pattern: 'friend_requested_list.php',
57
+ page: params[:page] || 0,
58
+ get_uncheck_mode: params[:get_uncheck_mode] || 0
59
+ )
60
+ end
61
+
62
+ def current_goal
63
+ get get_type: 1, api_pattern: 'get_current_goal.php'
64
+ end
65
+
66
+ def friend_list
67
+ get get_type: 5, api_pattern: 'friend_list.php'
68
+ end
69
+
70
+ def balance
71
+ get get_type: 3, api_pattern: 'get_balance.php'
72
+ end
73
+
74
+ def mg_steps_weight
75
+ get get_type: 0, api_pattern: 'get_mg_steps_weight.php'
76
+ end
77
+
78
+ def ac_steps
79
+ get get_type: 0, api_pattern: 'get_ac_steps.php'
80
+ end
81
+
82
+ def event
83
+ get get_type: 9, api_pattern: 'get_event.php'
84
+ end
85
+
86
+ def bmr(params = {})
87
+ bodycomp :bmr, params
88
+ end
89
+
90
+ def bodyage(params = {})
91
+ bodycomp :bodyage, params
92
+ end
93
+
94
+ def muscle(params = {})
95
+ bodycomp :muscle, params
96
+ end
97
+
98
+ def bone(params = {})
99
+ bodycomp :bone, params
100
+ end
101
+
102
+ def visceralfat_lv(params = {})
103
+ bodycomp :visceralfat_lv, params
104
+ end
105
+
106
+ def tbw(params = {})
107
+ bodycomp :tbw, params
108
+ end
109
+
110
+ def bodycomp(type = :bmr, params = {})
111
+ get(
112
+ get_type: 14,
113
+ api_pattern: 'get_ac_bodycomp.php',
114
+ str_date: params[:str_date] || Date.today.strftime('%Y%m%d'),
115
+ end_date: params[:end_date] || '',
116
+ type: type.to_s
117
+ )
118
+ end
119
+
120
+ private
121
+ def get(params = {})
122
+ res = @conn.get do |req|
123
+ req.url '/pc/assets/dispatcher/Dispatcher.php'
124
+ req.headers['cookie'] = @cookie
125
+ req.params[:dispatcher_type] = 0
126
+ req.params.merge! params
127
+ end
128
+ begin
129
+ JSON.parse res.body
130
+ rescue => e
131
+ res.body
132
+ end
133
+ end
134
+ end
135
+ end
136
+
@@ -0,0 +1,22 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module HealthCare
4
+ class Bodycomp
5
+ attr_accessor :weight, :bodyfat, :number, :value, :level
6
+
7
+ def initialize(data)
8
+ @weight = data['weight'] if data['weight']
9
+ @bodyfat = data['bodyfat'] if data['bodyfat']
10
+ @number = data['number'].split(',').map{|m| m.to_f} if data['number']
11
+ @value = data['value'].split(',').map{|m| m.to_f} if data['value']
12
+ @level = data['level'].split(',').map{|m| m.to_f} if data['level']
13
+ end
14
+
15
+ def latest
16
+ @value.reverse.each do |v|
17
+ return v if v > 0
18
+ end
19
+ -1
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module HealthCare
4
+ class Client
5
+ def initialize(params)
6
+ @api = ApiClient.new
7
+ @api.login params
8
+ refresh
9
+ end
10
+
11
+ def refresh
12
+ @summary = @api.home_summary['root']
13
+ end
14
+
15
+ def weight
16
+ @summary['weight']
17
+ end
18
+
19
+ def body_fat
20
+ @summary['bodyfat']
21
+ end
22
+
23
+ def bmi
24
+ @summary['bmi']
25
+ end
26
+
27
+ def basal_metabolism
28
+ @summary['bmr']
29
+ end
30
+
31
+ def physical_age
32
+ @summary['bodyage']
33
+ end
34
+
35
+ def skeletal_muscle_level
36
+ @summary['muscle']
37
+ end
38
+
39
+ def bone_level
40
+ @summary['bone']
41
+ end
42
+
43
+ def visceral_fat_level
44
+ @summary['viscerafal']
45
+ end
46
+
47
+ def water_content
48
+ @summary['tbw']
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module HealthCare
4
+ VERSION = "0.0.1"
5
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: softbank-healthcare-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - shunirr
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
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'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faraday
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Softbank HealthCare Client for Ruby
56
+ email:
57
+ - m@s5r.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - healthcare.gemspec
68
+ - lib/healthcare.rb
69
+ - lib/healthcare/api_client.rb
70
+ - lib/healthcare/bodycomp.rb
71
+ - lib/healthcare/client.rb
72
+ - lib/healthcare/version.rb
73
+ homepage: https://github.com/shunirr/softbank-healthcare-client-ruby
74
+ licenses:
75
+ - MIT
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.2.0
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Softbank HealthCare Client for Ruby
97
+ test_files: []