omniauth-ihealth 1.0.4

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b4e4cebeb9d279a853f95f536a0125229cd8097
4
+ data.tar.gz: c2afc5f618ffa4197a0d7c131087b9c0b3a8d436
5
+ SHA512:
6
+ metadata.gz: 657d1b6a28228a15c5fc36cf678c240f5b3effb869edbc7e32c281ec6467274486044ab3345ae65f3a094e94d60edb89cdeccd7b1bdea818baa7f989ea8aa711
7
+ data.tar.gz: 74a8370597d96e6b57346edad6d01ecc3c758e55d5f9a843841c52821e75d612f4f44388bf45b837dd1b2d450ab49288ff7eaa4df75c029ab6b953d4714f82a3
@@ -0,0 +1,16 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ # Ignore the default SQLite database.
11
+ /db/*.sqlite3
12
+
13
+ # Ignore all logfiles and tempfiles.
14
+ /log/*.log
15
+ /tmp
16
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-SForce.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'guard'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'rb-fsevent'
11
+ gem 'growl'
12
+ end
@@ -0,0 +1,112 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ actionmailer (3.2.12)
5
+ actionpack (= 3.2.12)
6
+ mail (~> 2.4.4)
7
+ actionpack (3.2.12)
8
+ activemodel (= 3.2.12)
9
+ activesupport (= 3.2.12)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ journey (~> 1.0.4)
13
+ rack (~> 1.4.5)
14
+ rack-cache (~> 1.2)
15
+ rack-test (~> 0.6.1)
16
+ sprockets (~> 2.2.1)
17
+ activemodel (3.2.12)
18
+ activesupport (= 3.2.12)
19
+ builder (~> 3.0.0)
20
+ activerecord (3.2.12)
21
+ activemodel (= 3.2.12)
22
+ activesupport (= 3.2.12)
23
+ arel (~> 3.0.2)
24
+ tzinfo (~> 0.3.29)
25
+ activeresource (3.2.12)
26
+ activemodel (= 3.2.12)
27
+ activesupport (= 3.2.12)
28
+ activesupport (3.2.12)
29
+ i18n (~> 0.6)
30
+ multi_json (~> 1.0)
31
+ arel (3.0.2)
32
+ builder (3.0.4)
33
+ coffee-rails (3.2.2)
34
+ coffee-script (>= 2.2.0)
35
+ railties (~> 3.2.0)
36
+ coffee-script (2.2.0)
37
+ coffee-script-source
38
+ execjs
39
+ coffee-script-source (1.6.1)
40
+ erubis (2.7.0)
41
+ execjs (1.4.0)
42
+ multi_json (~> 1.0)
43
+ hike (1.2.1)
44
+ i18n (0.6.4)
45
+ journey (1.0.4)
46
+ jquery-rails (2.2.1)
47
+ railties (>= 3.0, < 5.0)
48
+ thor (>= 0.14, < 2.0)
49
+ json (1.7.7)
50
+ mail (2.4.4)
51
+ i18n (>= 0.4.0)
52
+ mime-types (~> 1.16)
53
+ treetop (~> 1.4.8)
54
+ mime-types (1.21)
55
+ multi_json (1.6.1)
56
+ polyglot (0.3.3)
57
+ rack (1.4.5)
58
+ rack-cache (1.2)
59
+ rack (>= 0.4)
60
+ rack-ssl (1.3.3)
61
+ rack
62
+ rack-test (0.6.2)
63
+ rack (>= 1.0)
64
+ rails (3.2.12)
65
+ actionmailer (= 3.2.12)
66
+ actionpack (= 3.2.12)
67
+ activerecord (= 3.2.12)
68
+ activeresource (= 3.2.12)
69
+ activesupport (= 3.2.12)
70
+ bundler (~> 1.0)
71
+ railties (= 3.2.12)
72
+ railties (3.2.12)
73
+ actionpack (= 3.2.12)
74
+ activesupport (= 3.2.12)
75
+ rack-ssl (~> 1.3.2)
76
+ rake (>= 0.8.7)
77
+ rdoc (~> 3.4)
78
+ thor (>= 0.14.6, < 2.0)
79
+ rake (10.0.3)
80
+ rdoc (3.12.2)
81
+ json (~> 1.4)
82
+ sass (3.2.7)
83
+ sass-rails (3.2.6)
84
+ railties (~> 3.2.0)
85
+ sass (>= 3.1.10)
86
+ tilt (~> 1.3)
87
+ sprockets (2.2.2)
88
+ hike (~> 1.2)
89
+ multi_json (~> 1.0)
90
+ rack (~> 1.0)
91
+ tilt (~> 1.1, != 1.3.0)
92
+ sqlite3 (1.3.7)
93
+ thor (0.17.0)
94
+ tilt (1.3.5)
95
+ treetop (1.4.12)
96
+ polyglot
97
+ polyglot (>= 0.3.1)
98
+ tzinfo (0.3.37)
99
+ uglifier (1.3.0)
100
+ execjs (>= 0.3.0)
101
+ multi_json (~> 1.0, >= 1.0.2)
102
+
103
+ PLATFORMS
104
+ ruby
105
+
106
+ DEPENDENCIES
107
+ coffee-rails (~> 3.2.1)
108
+ jquery-rails
109
+ rails (= 3.2.12)
110
+ sass-rails (~> 3.2.3)
111
+ sqlite3
112
+ uglifier (>= 1.0.3)
@@ -0,0 +1,10 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+ guard 'bundler' do
8
+ watch('Gemfile')
9
+ watch('omniauth-ihealth.gemspec')
10
+ end
@@ -0,0 +1,80 @@
1
+ # Omniauth Strategy for iHealth
2
+ This is a strategy to connect with iHealth using Ommniauth and OAuth 2.0. Originally written by [ArturKarbone](https://github.com/ArturKarbone), up to date as of Feb 13, 2014 for iHealth's API.
3
+
4
+ You can apply for API access on iHealth's developer website [here](http://developer.ihealthlabs.com).
5
+
6
+
7
+ ## Installing
8
+
9
+ Add to your `Gemfile`:
10
+
11
+ ```ruby
12
+ gem 'omniauth-ihealth', :git=>'https://github.com/hspinks/omniauth-ihealth.git'
13
+ ```
14
+
15
+ Then `bundle install`.
16
+
17
+ ## Usage
18
+
19
+ `OmniAuth::Strategies::IHealth` is a Rack middleware. Read the OmniAuth docs for detailed instructions: https://github.com/intridea/omniauth
20
+
21
+ Here's a quick example, adding the middleware to a Rails app in `config/initializers/omniauth.rb`:
22
+
23
+ ```ruby
24
+ Rails.application.config.middleware.use OmniAuth::Builder do
25
+ provider :ihealth, ENV['KEY'], ENV['SECRET']
26
+ end
27
+ ```
28
+
29
+
30
+ ## Configuring
31
+
32
+ You can configure several options, which you pass in to the `provider` method via a `Hash`:
33
+
34
+ * `scope`: A list of permissions you want to request from the user, separated by spaces. Options are `OpenApiUserInfo`, `OpenApiActivity`, `OpenApiBG`, `OpenApiBP`, `OpenApiSleep`, `OpenApiSpO2`, and `OpenApiWeight`. You must include `OpenApiUserInfo`. Defaults to `OpenApiUserInfo`.
35
+ * `sc`: The Serial Code for the client. You can find this on the developer detail page on iHealth's website [here](http://developer.ihealthlabs.com/developerdetailpage.htm).
36
+ * `sv`: The SV value listed for OpenApiUserInfo on the [developer detail page](http://developer.ihealthlabs.com/developerdetailpage.htm).
37
+
38
+ ## Auth Hash
39
+
40
+ Here's an example Auth Hash available in `request.env['omniauth.auth']`:
41
+
42
+ ```ruby
43
+ {
44
+ "provider" => "ihealth",
45
+ "uid" => "12345",
46
+ "info" => {
47
+ "name" => "John Doe",
48
+ "nickname" => "John Doe",
49
+ "image" => "https://cloud.ihealthlabs.com/logos/12345.png"
50
+ },
51
+ "credentials" => {
52
+ "token" => "ABCDEF...", # OAuth 2.0 access_token
53
+ "refresh_token" => "ABCDEF...",
54
+ "expires_at" => 1392501884,
55
+ "expires" => true
56
+ },
57
+ "extra" => {
58
+ "user_info" => {
59
+ "name" => "John Doe",
60
+ "gender" => "male",
61
+ "birthday" => "2013-12-31",
62
+ "image" => "https://cloud.ihealthlabs.com/logos/12345.png",
63
+ "nickname" => "John Doe",
64
+ "height" => 72.00, # height in inches
65
+ "weight" => 180.00 # weight in pounds
66
+ },
67
+ "raw_info" => {
68
+ "HeightUnit" => 0, # 0 for cm, 1 for ft
69
+ "WeightUnit" => 0, # 0 for kg, 1 for lbs, 2 for stone
70
+ "dateofbirth" => 1388534400,
71
+ "gender" => "Male",
72
+ "height" => 182.88,
73
+ "logo" => "https%3a%2f%2fcloud.ihealthlabs.com%2flogos%2f12345.png",
74
+ "nickname" => "John Doe",
75
+ "userid" => "12345",
76
+ "weight" => 81.6
77
+ }
78
+ }
79
+ }
80
+ ```
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rspec/core/rake_task'
4
+
5
+ desc 'Default: run specs.'
6
+ task :default => :spec
7
+
8
+ desc "Run specs"
9
+ RSpec::Core::RakeTask.new
10
+
11
+ desc 'Run specs'
12
+ task :default => :spec
@@ -0,0 +1,4 @@
1
+ # This file is used by Rack-based servers to start the application.
2
+
3
+ require ::File.expand_path('../config/environment', __FILE__)
4
+ run OmniauthIhealth::Application
@@ -0,0 +1,2 @@
1
+ require "omniauth-ihealth/version"
2
+ require 'omniauth/strategies/ihealth'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module IHealth
3
+ VERSION = "1.0.4"
4
+ end
5
+ end
@@ -0,0 +1,114 @@
1
+ require 'omniauth-oauth2'
2
+ # require 'oauth2'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class IHealth < OmniAuth::Strategies::OAuth2
7
+
8
+ AVAILABLE_API_NAMES = "OpenApiActivity OpenApiBG OpenApiBP OpenApiSleep OpenApiSpO2 OpenApiUserInfo OpenApiWeight"
9
+ DEFAULT_API_NAMES = "OpenApiUserInfo"
10
+
11
+ option :name, 'ihealth'
12
+ option :scope, DEFAULT_API_NAMES
13
+ option :provider_ignores_state, true
14
+
15
+ option :client_options, {
16
+ :site => 'https://api.ihealthlabs.com:8443',
17
+ :authorize_url => '/OpenApiV2/OAuthv2/userauthorization/',
18
+ :token_url => '/OpenApiV2/OAuthv2/userauthorization/',
19
+ :token_method => :get,
20
+ :parse => :json
21
+ }
22
+
23
+ def authorize_params
24
+ super.tap do |params|
25
+ params[:response_type] = 'code'
26
+ params[:APIName] = options.scope
27
+ end
28
+ end
29
+
30
+ def token_params
31
+ super.tap do |params|
32
+ params[:client_id] = client.id
33
+ params[:client_secret] = client.secret
34
+ params[:grant_type] = "authorization_code"
35
+ end
36
+ end
37
+
38
+ def build_access_token
39
+ token_url_params = {:code => request.params['code'], :redirect_uri => callback_url}.merge(token_params.to_hash(:symbolize_keys => true))
40
+ parsed_response = client.request(options.client_options.token_method, client.token_url(token_url_params), parse: :json).parsed
41
+ hash = {
42
+ :access_token => parsed_response["AccessToken"],
43
+ :expires_in => parsed_response["Expires"],
44
+ :refresh_token => parsed_response["RefreshToken"],
45
+ :user_id => parsed_response["UserID"],
46
+ :api_name => parsed_response["APIName"],
47
+ :client_para => parsed_response["client_para"]
48
+ }
49
+ ::OAuth2::AccessToken.from_hash(client, hash)
50
+ end
51
+
52
+ uid { access_token[:user_id] }
53
+
54
+ info { user_data.slice(:name, :nickname, :image) }
55
+
56
+ extra do
57
+ { :user_info => user_data, :raw_info => raw_info }
58
+ end
59
+
60
+ def raw_info
61
+ access_token.options[:mode] = :query
62
+ user_profile_params = {:client_id => client.id, :client_secret => client.secret, :access_token => access_token.token}
63
+ user_profile_params.merge({:sc => options.sc, :sv => options.sv}) if options.sc && options.sv
64
+ @raw_info ||= access_token.get("/openapiv2/user/#{access_token[:user_id]}.json/?#{user_profile_params.to_param}", parse: :json).parsed
65
+ end
66
+
67
+ def user_data
68
+ info = raw_info
69
+ user_data ||= {
70
+ :name => info["nickname"],
71
+ :gender => info["gender"].downcase,
72
+ :birthday => Time.at(info["dateofbirth"]).to_date.strftime("%Y-%m-%d"),
73
+ :image => URI.unescape(info["logo"]),
74
+ :nickname => info["nickname"],
75
+ :height => calc_height(info["height"], info["HeightUnit"]),
76
+ :weight => calc_weight(info["weight"], info["WeightUnit"])
77
+ }
78
+ end
79
+
80
+ protected
81
+ CM_TO_IN_CONVERSION = 0.393701
82
+ FT_TO_IN_CONVERSION = 12
83
+ def calc_height(value, unit)
84
+ case(unit)
85
+ when 0 # value is in cm
86
+ return value * CM_TO_IN_CONVERSION
87
+ when 1 # value is in feet
88
+ return value * FT_TO_IN_CONVERSION
89
+ else # unrecognized unit
90
+ return value
91
+ end
92
+ end
93
+
94
+ KG_TO_LBS_CONVERSION = 2.20462
95
+ STONE_TO_LBS_CONVERSION = 14
96
+ def calc_weight(value, unit)
97
+ case(unit)
98
+ when 0 # value is in kg
99
+ return value * KG_TO_LBS_CONVERSION
100
+ when 1 # value is in lbs
101
+ return value
102
+ when 2 # value is in stone
103
+ return value * STONE_TO_LBS_CONVERSION
104
+ else # unrecognized unit
105
+ return value
106
+ end
107
+ end
108
+
109
+ end
110
+ end
111
+ end
112
+
113
+
114
+ OmniAuth.config.add_camelization 'ihealth', 'IHealth'
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/omniauth-ihealth/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Hunter Spinks", "Artur Karbone", "Victor Vargas"]
6
+ gem.email = ["hspinks@gmail.com"]
7
+ gem.description = %q{OmniAuth strategy for iHealth.com.}
8
+ gem.summary = %q{OmniAuth strategy for iHealth.com.}
9
+ gem.homepage = "https://github.com/hspinks/omniauth-ihealth"
10
+
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "omniauth-ihealth"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = OmniAuth::IHealth::VERSION
17
+
18
+ gem.add_dependency 'omniauth', '~> 1.0'
19
+ gem.add_dependency 'omniauth-oauth2', '~> 1.0'
20
+ gem.add_development_dependency 'rspec', '~> 2.7'
21
+ gem.add_development_dependency 'rack-test'
22
+ gem.add_development_dependency 'simplecov'
23
+ gem.add_development_dependency 'webmock'
24
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-iHealth'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-ihealth
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Hunter Spinks
8
+ - Artur Karbone
9
+ - Victor Vargas
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2014-02-13 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: omniauth
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: '1.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: omniauth-oauth2
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: '1.0'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ version: '1.0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: rspec
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '2.7'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ~>
55
+ - !ruby/object:Gem::Version
56
+ version: '2.7'
57
+ - !ruby/object:Gem::Dependency
58
+ name: rack-test
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: simplecov
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: webmock
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ description: OmniAuth strategy for iHealth.com.
100
+ email:
101
+ - hspinks@gmail.com
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - .gitignore
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - Guardfile
110
+ - README.md
111
+ - Rakefile
112
+ - config.ru
113
+ - lib/omniauth-ihealth.rb
114
+ - lib/omniauth-ihealth/version.rb
115
+ - lib/omniauth/strategies/ihealth.rb
116
+ - omniauth-ihealth.gemspec
117
+ - spec/spec_helper.rb
118
+ homepage: https://github.com/hspinks/omniauth-ihealth
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project:
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: OmniAuth strategy for iHealth.com.
141
+ test_files:
142
+ - spec/spec_helper.rb