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 +4 -4
- data/README.md +9 -5
- data/lib/human_api/config.rb +1 -1
- data/lib/human_api/human.rb +2 -1
- data/lib/human_api/user.rb +21 -0
- data/lib/human_api/version.rb +1 -1
- data/lib/human_api.rb +1 -0
- data/spec/cassettes/get_public_token.yml +43 -0
- data/spec/lib/human_api/user_spec.rb +13 -0
- data/spec/spec_helper.rb +3 -2
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b3794f4fdc16f8ff0488af021bec476e514a607
|
4
|
+
data.tar.gz: 85df138268da3635d8740e36145e0f832d92dae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ac5c037fbcc722d438c990e27ae82bf6caa242ccf4c68651b01c37fa5615bb519d19baec4db9eebdd0b55db66e85bd23d2aced6b1e9a0c94661ee6f0dad95ca
|
7
|
+
data.tar.gz: 252c37a5edec1642f79b8a51d23e55f9f14236ccdee188bbba2858b737f1b92590a1fadf47632cd91f754a4e9c14b1b23199a77346d0cd78965540e8234f4862
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
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
|
43
|
-
c.query_key
|
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
|
54
|
-
c.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
|
data/lib/human_api/config.rb
CHANGED
@@ -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
|
|
data/lib/human_api/human.rb
CHANGED
@@ -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
|
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
|
data/lib/human_api/version.rb
CHANGED
data/lib/human_api.rb
CHANGED
@@ -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
|
14
|
-
c.
|
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.
|
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:
|