health_hero-human_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e96aae7b7516f6ea34360d49f1ba1410248d4307
4
- data.tar.gz: 6018041870317fde160e9a04fa3cfaa84f334ee3
3
+ metadata.gz: 1b3794f4fdc16f8ff0488af021bec476e514a607
4
+ data.tar.gz: 85df138268da3635d8740e36145e0f832d92dae2
5
5
  SHA512:
6
- metadata.gz: f095c7f3a356d39c995e78d39d71b35c834cdeac9d90ad30dfa71e0ba5bdda41a21fd3070d713378655c01cf9ab22b21f7e75577c3343822d022dfca3551ac6e
7
- data.tar.gz: c72328901f30426a1de5343d6ddb4ef3ce7205a7c1eb44017268b05034c3bdc91e32056ea576ca2b14814c432903017caa15c1cbaf478560d3aa969546e2fd85
6
+ metadata.gz: 9ac5c037fbcc722d438c990e27ae82bf6caa242ccf4c68651b01c37fa5615bb519d19baec4db9eebdd0b55db66e85bd23d2aced6b1e9a0c94661ee6f0dad95ca
7
+ data.tar.gz: 252c37a5edec1642f79b8a51d23e55f9f14236ccdee188bbba2858b737f1b92590a1fadf47632cd91f754a4e9c14b1b23199a77346d0cd78965540e8234f4862
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- [![Build Status](https://travis-ci.org/HealthHero/humanapi.svg?branch=master)][travis][![Gem Version](https://badge.fury.io/rb/health_hero-human_api.png)](http://badge.fury.io/rb/health_hero-human_api)
1
+ ![Build Status](https://img.shields.io/travis/HealthHero/humanapi.svg)
2
+ ![Gem Version](https://img.shields.io/gem/v/health_hero-human_api.svg)
2
3
 
3
4
  # HumanApi
4
5
 
@@ -39,8 +40,9 @@ This configuration is really simple. I suggest it over the second one.
39
40
  Always remember to configure the initializer with the access keys:
40
41
  ```ruby
41
42
  HumanApi.config do |c|
42
- c.app_id = ENV['HUMANAPI_KEY']
43
- c.query_key = ENV['HUMANAPI_SECRET']
43
+ c.app_id = ENV['HUMANAPI_KEY']
44
+ c.query_key = ENV['HUMANAPI_SECRET']
45
+ c.client_secret = ENV['HUMANAPI_CLIENT_SECRET']
44
46
  end
45
47
  ```
46
48
 
@@ -50,8 +52,9 @@ If you don't like that configuration, you can use a different one, writing right
50
52
 
51
53
  ```ruby
52
54
  HumanApi.config do |c|
53
- c.app_id = "<YOUR_APP_ID>"
54
- c.query_key = "<YOUR_QUERY_KEY>"
55
+ c.app_id = "<YOUR_APP_ID>"
56
+ c.query_key = "<YOUR_QUERY_KEY>"
57
+ c.client_secret = "<YOUR__CLIENT_SECRET>"
55
58
 
56
59
  # This is the part where the magics happen
57
60
  c.human_model = User # Tell me what is the model you want to use
@@ -88,6 +91,7 @@ The query method is meant to ask whatever you want whenever you want. Here are s
88
91
  :sleeps
89
92
  :weight
90
93
  :bmi
94
+ :sources
91
95
  ```
92
96
 
93
97
  ### Query Options
@@ -1,6 +1,6 @@
1
1
  module HumanApi
2
2
  class Config
3
- attr_accessor :app_id, :query_key, :human_model, :token_method_name, :hardcore, :raise_access_errors, :handle_access_error
3
+ attr_accessor :app_id, :query_key, :client_secret, :human_model, :token_method_name, :hardcore, :raise_access_errors, :handle_access_error
4
4
 
5
5
  CHECK_THE_GUIDE = "Read the guide for more information. (https://github.com/Pazienti/humanapi)"
6
6
 
@@ -8,7 +8,8 @@ module HumanApi
8
8
 
9
9
  # The available methods for this api
10
10
  AVAILABLE_METHODS = %i{
11
- profile activities blood_glucose blood_oxygen blood_pressure body_fat genetic_traits heart_rate height locations sleeps weight bmi
11
+ profile activities blood_glucose blood_oxygen blood_pressure body_fat genetic_traits
12
+ heart_rate height locations sleeps weight bmi sources
12
13
  }.freeze
13
14
 
14
15
  def initialize(options)
@@ -0,0 +1,21 @@
1
+ module HumanApi
2
+ class User < Nestful::Resource
3
+
4
+ endpoint 'https://user.humanapi.co'
5
+ path '/v1/connect'
6
+ options auth_type: :basic, user: HumanApi.config.query_key, password: ''
7
+
8
+ # Get a public token:
9
+ def self.get_public_token(human_id)
10
+ response = post 'publictokens', humanId: human_id, clientId: HumanApi.config.app_id, clientSecret: HumanApi.config.client_secret
11
+ JSON.parse(response.body)['publicToken']
12
+ rescue Nestful::UnauthorizedAccess => e
13
+ if HumanApi.config.handle_access_error
14
+ HumanApi.config.handle_access_error.call e
15
+ else
16
+ raise if HumanApi.config.raise_access_errors
17
+ nil
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module HumanApi
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/human_api.rb CHANGED
@@ -20,4 +20,5 @@ module HumanApi
20
20
 
21
21
  autoload :Human, 'human_api/human'
22
22
  autoload :App, 'human_api/app'
23
+ autoload :User, 'human_api/user'
23
24
  end
@@ -0,0 +1,43 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://APP_ID:@user.humanapi.co/v1/connect/publictokens
6
+ body:
7
+ encoding: US-ASCII
8
+ string: humanId=human_id&clientId=client_id&clientSecret=client_secret
9
+ headers:
10
+ Content-Type:
11
+ - application/x-www-form-urlencoded
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Content-Type:
24
+ - application/json; charset=utf-8
25
+ Date:
26
+ - Tue, 01 Sep 2015 21:41:35 GMT
27
+ Server:
28
+ - nginx/1.4.6 (Ubuntu)
29
+ Set-Cookie:
30
+ - hapi_times=s%3AcxN8MwFyJVkjp2lQUDn4%2B2H%2B.FLE20PVLD%2BJffZhkP7s5E%2F6UFQdunbR3vpSvll1NHvw;
31
+ Path=/; HttpOnly
32
+ X-Powered-By:
33
+ - Express
34
+ Content-Length:
35
+ - '95'
36
+ Connection:
37
+ - keep-alive
38
+ body:
39
+ encoding: UTF-8
40
+ string: '{"humanId":"human_id","publicToken":"public_token"}'
41
+ http_version:
42
+ recorded_at: Tue, 01 Sep 2015 21:37:51 GMT
43
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe HumanApi::User do
4
+ let(:user) { described_class }
5
+
6
+ describe ".get_public_token" do
7
+ it 'gets a public token' do
8
+ VCR.use_cassette :get_public_token do
9
+ expect(user.get_public_token 'human_id').to eq 'public_token'
10
+ end
11
+ end
12
+ end
13
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,8 +10,9 @@ HUMAN_API_CLIENT_ID = ENV['HUMAN_API_CLIENT_ID'] || 'CLIENT_ID'
10
10
  HUMAN_API_CLIENT_SECRET = ENV['HUMAN_API_CLIENT_SECRET'] || 'CLIENT_SECRET'
11
11
 
12
12
  HumanApi.config do |c|
13
- c.app_id = HUMAN_API_CLIENT_ID
14
- c.query_key = HUMAN_API_APP_ID
13
+ c.app_id = HUMAN_API_CLIENT_ID
14
+ c.client_secret = HUMAN_API_CLIENT_SECRET
15
+ c.query_key = HUMAN_API_APP_ID
15
16
  end
16
17
 
17
18
  VCR.configure do |config|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health_hero-human_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Aiken
@@ -169,6 +169,7 @@ files:
169
169
  - lib/human_api/app.rb
170
170
  - lib/human_api/config.rb
171
171
  - lib/human_api/human.rb
172
+ - lib/human_api/user.rb
172
173
  - lib/human_api/version.rb
173
174
  - spec/cassettes/create_human_success.yml
174
175
  - spec/cassettes/get_activities.yml
@@ -176,10 +177,12 @@ files:
176
177
  - spec/cassettes/get_activities_fetch_all.yml
177
178
  - spec/cassettes/get_humans.yml
178
179
  - spec/cassettes/get_profile_success.yml
180
+ - spec/cassettes/get_public_token.yml
179
181
  - spec/cassettes/get_summary_success.yml
180
182
  - spec/lib/human_api/app_spec.rb
181
183
  - spec/lib/human_api/config_spec.rb
182
184
  - spec/lib/human_api/human_spec.rb
185
+ - spec/lib/human_api/user_spec.rb
183
186
  - spec/spec_helper.rb
184
187
  homepage: https://github.com/HealthHero/humanapi
185
188
  licenses:
@@ -212,9 +215,11 @@ test_files:
212
215
  - spec/cassettes/get_activities_fetch_all.yml
213
216
  - spec/cassettes/get_humans.yml
214
217
  - spec/cassettes/get_profile_success.yml
218
+ - spec/cassettes/get_public_token.yml
215
219
  - spec/cassettes/get_summary_success.yml
216
220
  - spec/lib/human_api/app_spec.rb
217
221
  - spec/lib/human_api/config_spec.rb
218
222
  - spec/lib/human_api/human_spec.rb
223
+ - spec/lib/human_api/user_spec.rb
219
224
  - spec/spec_helper.rb
220
225
  has_rdoc: