health_hero-human_api 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,40 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://APP_ID:@api.humanapi.co/v1/apps/CLIENT_ID/users
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Content-Type:
22
+ - application/json; charset=utf-8
23
+ Date:
24
+ - Tue, 01 Sep 2015 17:46:15 GMT
25
+ Etag:
26
+ - '"-1683128992"'
27
+ Server:
28
+ - nginx/1.4.6 (Ubuntu)
29
+ X-Powered-By:
30
+ - Express
31
+ Content-Length:
32
+ - '96666'
33
+ Connection:
34
+ - keep-alive
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"humanId":"abcd","externalId":"0001","appId":"APP_ID","createdAt":"2014-09-17T23:38:55.073Z","updatedAt":"2015-05-28T16:23:56.859Z"}]'
38
+ http_version:
39
+ recorded_at: Tue, 01 Sep 2015 17:42:32 GMT
40
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.humanapi.co/v1/human/profile?access_token=token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - Content-Type, Authorization, Accept
23
+ Access-Control-Allow-Methods:
24
+ - OPTIONS,GET,HEAD
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Access-Control-Max-Age:
28
+ - '86400'
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Date:
32
+ - Tue, 01 Sep 2015 18:40:17 GMT
33
+ Server:
34
+ - nginx/1.4.6 (Ubuntu)
35
+ X-Powered-By:
36
+ - Express
37
+ Content-Length:
38
+ - '222'
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"userId":"userId","createdAt":"2015-07-23T18:29:18.157Z","email":"justin@humanapi.co","defaultTimeZone":{"name":"UTC"},"humanId":"humanID"}'
44
+ http_version:
45
+ recorded_at: Tue, 01 Sep 2015 18:36:33 GMT
46
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.humanapi.co/v1/human?access_token=token
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - Content-Type, Authorization, Accept
23
+ Access-Control-Allow-Methods:
24
+ - OPTIONS,GET,HEAD
25
+ Access-Control-Allow-Origin:
26
+ - "*"
27
+ Access-Control-Max-Age:
28
+ - '86400'
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Date:
32
+ - Tue, 01 Sep 2015 18:56:45 GMT
33
+ Server:
34
+ - nginx/1.4.6 (Ubuntu)
35
+ X-Powered-By:
36
+ - Express
37
+ Content-Length:
38
+ - '701'
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: '{"userId":"userID","createdAt":"2015-07-23T18:29:18.157Z","bloodGlucose":{},"bloodOxygen":{},"bloodPressure":{},"bmi":{},"bodyFat":{"id":"id","timestamp":"2015-08-14T00:00:00.000Z","source":"runkeeper","value":8.0559,"unit":"%"},"height":{},"heartRate":{},"weight":{"id":"id","timestamp":"2015-08-14T00:00:00.000Z","source":"runkeeper","value":62.483,"unit":"kg"},"activitySummary":{"id":"id","date":"","duration":7076,"distance":21167.628734835,"sedentary":0,"light":0,"moderate":0,"vigorous":0,"total":0,"steps":0,"calories":1436,"source":"runkeeper"},"sleepSummary":{},"humanId":"humanID"}'
44
+ http_version:
45
+ recorded_at: Tue, 01 Sep 2015 18:52:43 GMT
46
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe HumanApi::App do
4
+ let(:app) { described_class }
5
+
6
+ describe ".humans" do
7
+ let(:humans) { app.humans }
8
+ let(:human) { humans[0] }
9
+
10
+ it 'gets a listing of humans as a hash' do
11
+ VCR.use_cassette :get_humans do
12
+ expect(human['humanId']).to eq 'abcd'
13
+ expect(human['externalId']).to eq '0001'
14
+ expect(human['appId']).to eq 'APP_ID'
15
+ expect(human['createdAt']).to eq '2014-09-17T23:38:55.073Z'
16
+ expect(human['updatedAt']).to eq '2015-05-28T16:23:56.859Z'
17
+ end
18
+ end
19
+ end
20
+
21
+ describe ".create_human" do
22
+ let(:human) { app.create_human 'test_user' }
23
+
24
+ context "when successful" do
25
+ it 'returns the parsed response' do
26
+ VCR.use_cassette :create_human_success do
27
+ expect(human['humanId']).to eq 'abcd'
28
+ expect(human['externalId']).to eq 'test_user'
29
+ expect(human['appId']).to eq 'CLIENT_ID'
30
+ expect(human['createdAt']).to eq '2015-09-01T18:18:18.500Z'
31
+ expect(human['updatedAt']).to eq '2015-09-01T18:19:55.177Z'
32
+ end
33
+ end
34
+ end
35
+
36
+ context "when unauthorized" do
37
+ context "with a proc set" do
38
+ before { expect(HumanApi.config).to receive(:handle_access_error).exactly(:twice).and_return ->e { e.class.to_s } }
39
+
40
+ it 'calls the proc' do
41
+ expect(app.create_human 'joe').to eq 'Nestful::UnauthorizedAccess'
42
+ end
43
+ end
44
+
45
+ context "with raise_access_errors set" do
46
+ before { expect(HumanApi.config).to receive(:raise_access_errors).and_return true }
47
+
48
+ it 'raises a Nestful error' do
49
+ expect { app.create_human 'joe' }.to raise_error Nestful::UnauthorizedAccess
50
+ end
51
+ end
52
+
53
+ context "without raise_access_errors set" do
54
+ before { expect(HumanApi.config).to receive(:raise_access_errors).and_return false }
55
+
56
+ it 'just returns false' do
57
+ expect(app.create_human 'joe').to eq false
58
+ end
59
+ end
60
+ end
61
+
62
+ context "when unsuccesful" do
63
+ xit '.. need to think of a way to make this fail :p'
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+
3
+ describe HumanApi::Config do
4
+ let(:config) { described_class.new }
5
+
6
+ it 'sets some defaults' do
7
+ expect(config.hardcore).to be false
8
+ expect(config.raise_access_errors).to be false
9
+ expect(config.handle_access_error).to be nil
10
+ end
11
+
12
+ describe "#rewrite_human_model" do
13
+ xit 'needs testing!'
14
+ end
15
+ end
@@ -0,0 +1,114 @@
1
+ require 'spec_helper'
2
+
3
+ describe HumanApi::Human do
4
+ let(:token) { ENV['HUMAN_API_HUMAN_TOKEN'] || 'token' }
5
+ let(:human) { described_class.new access_token: token }
6
+
7
+ describe "#summary" do
8
+ let(:response) { human.summary.body }
9
+ let(:summary) { JSON.parse response }
10
+
11
+ it 'returns a summary' do
12
+ VCR.use_cassette :get_summary_success do
13
+ expect(summary['humanId']).to eq 'humanID'
14
+ expect(summary['createdAt']).to eq '2015-07-23T18:29:18.157Z'
15
+ expect(summary['bloodGlucose']).to eq Hash.new
16
+ expect(summary['bloodOxygen']).to eq Hash.new
17
+ expect(summary['bloodPressure']).to eq Hash.new
18
+ expect(summary['bmi']).to eq Hash.new
19
+ expect(summary['height']).to eq Hash.new
20
+ expect(summary['heartRate']).to eq Hash.new
21
+ expect(summary['sleepSummary']).to eq Hash.new
22
+ expect(summary['bodyFat']).to eq 'id' => "id", "timestamp" => "2015-08-14T00:00:00.000Z", "source" => "runkeeper", "value" => 8.0559, "unit" => "%"
23
+ expect(summary['weight']).to eq 'id' => "id", "timestamp" => "2015-08-14T00:00:00.000Z", "source" => "runkeeper", "value" => 62.483, "unit" => "kg"
24
+ expect(summary['activitySummary']).to eq 'id' => "id", "date" => "", "duration" => 7076, "distance" => 21167.628734835, "sedentary" => 0, "light" => 0, "moderate" => 0, "vigorous" => 0, "total" => 0, "steps" => 0, "calories" => 1436, "source"=>"runkeeper"
25
+ end
26
+ end
27
+ end
28
+
29
+ describe "#profile" do
30
+ let(:profile) { human.profile }
31
+
32
+ it 'returns the profile as a hash' do
33
+ VCR.use_cassette :get_profile_success do
34
+ expect(profile['userId']).to eq 'userId'
35
+ expect(profile['humanId']).to eq 'humanID'
36
+ expect(profile['email']).to eq 'justin@humanapi.co'
37
+ expect(profile['createdAt']).to eq '2015-07-23T18:29:18.157Z'
38
+ expect(profile['defaultTimeZone']).to eq 'name' => "UTC"
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#activities" do
44
+ let(:response) { human.query :activities, options }
45
+ let(:options) { {} }
46
+ let(:context) { '' }
47
+
48
+ around(:each) do |example|
49
+ VCR.use_cassette("get_activities#{context}") { example.run }
50
+ end
51
+
52
+ context "by default" do
53
+ let(:first_activity) { response[0] }
54
+
55
+ it "returns them as a giant array of hashes" do
56
+ expect(response.class).to eq Array
57
+ expect(response.size).to eq 50
58
+ end
59
+
60
+ it "has activity data" do
61
+ expect(first_activity['id']).to eq "55e37dd14a99f60b00f9ef96"
62
+ expect(first_activity['userId']).to eq "55b1327e7313370100c17161"
63
+ expect(first_activity['startTime']).to eq "2015-08-30T13:40:00.000Z"
64
+ expect(first_activity['endTime']).to eq "2015-08-30T15:37:56.000Z"
65
+ expect(first_activity['tzOffset']).to eq "-06:00"
66
+ expect(first_activity['type']).to eq "running"
67
+ expect(first_activity['source']).to eq "runkeeper"
68
+ expect(first_activity['duration']).to eq 7076
69
+ expect(first_activity['distance']).to eq 21167.628734835
70
+ expect(first_activity['steps']).to eq 0
71
+ expect(first_activity['calories']).to eq 1436
72
+ expect(first_activity['sourceData']).to eq Hash.new
73
+ expect(first_activity['createdAt']).to eq "2015-08-30T22:04:01.355Z"
74
+ expect(first_activity['updatedAt']).to eq "2015-08-30T22:04:01.355Z"
75
+ expect(first_activity['humanId']).to eq "ef30511710618584fb02a34e5b5c1f7f"
76
+ end
77
+ end
78
+
79
+ context "requesting metadata" do
80
+ let(:options) { {return_metadata: true} }
81
+
82
+ it 'returns useful metadata' do
83
+ expect(response.class).to eq Nestful::Response
84
+ expect(response.headers['x-total-count']).to eq '234'
85
+ expect(response.headers['link'][1..73]).to eq "https://api.humanapi.co/v1/human/activities?access_token=token&offset=50>"
86
+ end
87
+ end
88
+
89
+ context "with an offset and limit" do
90
+ let(:options) { {offset: 51, limit: 2} }
91
+ let(:context) { '_a_few' }
92
+
93
+ it "gets just what's requested" do
94
+ expect(response.size).to eq 2
95
+ end
96
+ end
97
+
98
+ context "requesting full set through pagination" do
99
+ let(:options) { {fetch_all: true} }
100
+ let(:context) { '_fetch_all' }
101
+
102
+ it 'goes crazy and gets them all' do
103
+ expect(response.count).to eq 234
104
+ end
105
+ end
106
+ end
107
+
108
+ TESTED = %i{profile activities}
109
+ (described_class::AVAILABLE_METHODS - TESTED).each do |meth|
110
+ describe "##{meth}" do
111
+ xit "needs testing!"
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,28 @@
1
+ require 'human_api'
2
+ require 'webmock'
3
+ require 'vcr'
4
+ require 'pry'
5
+ require 'dotenv'
6
+ # Dotenv.load
7
+
8
+ HUMAN_API_APP_ID = ENV['HUMAN_API_APP_ID'] || 'APP_ID'
9
+ HUMAN_API_CLIENT_ID = ENV['HUMAN_API_CLIENT_ID'] || 'CLIENT_ID'
10
+ HUMAN_API_CLIENT_SECRET = ENV['HUMAN_API_CLIENT_SECRET'] || 'CLIENT_SECRET'
11
+
12
+ HumanApi.config do |c|
13
+ c.app_id = HUMAN_API_CLIENT_ID
14
+ c.query_key = HUMAN_API_APP_ID
15
+ end
16
+
17
+ VCR.configure do |config|
18
+ config.allow_http_connections_when_no_cassette = true
19
+ config.cassette_library_dir = "spec/cassettes"
20
+ config.hook_into :webmock
21
+ end
22
+
23
+ RSpec.configure do |config|
24
+ config.mock_framework = :rspec
25
+ config.filter_run focus: true
26
+ config.run_all_when_everything_filtered = true
27
+ config.color = true
28
+ end
metadata ADDED
@@ -0,0 +1,220 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: health_hero-human_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Aiken
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nestful
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.8.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: vcr
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: dotenv
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: API client for HumanAPI
154
+ email:
155
+ - justin@gohealthhero.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".travis.yml"
162
+ - Gemfile
163
+ - LICENSE.txt
164
+ - README.md
165
+ - Rakefile
166
+ - human_api.gemspec
167
+ - lib/config/initializers/core_ext.rb
168
+ - lib/human_api.rb
169
+ - lib/human_api/app.rb
170
+ - lib/human_api/config.rb
171
+ - lib/human_api/human.rb
172
+ - lib/human_api/version.rb
173
+ - spec/cassettes/create_human_success.yml
174
+ - spec/cassettes/get_activities.yml
175
+ - spec/cassettes/get_activities_a_few.yml
176
+ - spec/cassettes/get_activities_fetch_all.yml
177
+ - spec/cassettes/get_humans.yml
178
+ - spec/cassettes/get_profile_success.yml
179
+ - spec/cassettes/get_summary_success.yml
180
+ - spec/lib/human_api/app_spec.rb
181
+ - spec/lib/human_api/config_spec.rb
182
+ - spec/lib/human_api/human_spec.rb
183
+ - spec/spec_helper.rb
184
+ homepage: https://github.com/HealthHero/humanapi
185
+ licenses:
186
+ - MIT
187
+ metadata: {}
188
+ post_install_message:
189
+ rdoc_options: []
190
+ require_paths:
191
+ - lib
192
+ required_ruby_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">="
195
+ - !ruby/object:Gem::Version
196
+ version: '0'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ requirements: []
203
+ rubyforge_project:
204
+ rubygems_version: 2.4.5
205
+ signing_key:
206
+ specification_version: 4
207
+ summary: API client for HumanAPI
208
+ test_files:
209
+ - spec/cassettes/create_human_success.yml
210
+ - spec/cassettes/get_activities.yml
211
+ - spec/cassettes/get_activities_a_few.yml
212
+ - spec/cassettes/get_activities_fetch_all.yml
213
+ - spec/cassettes/get_humans.yml
214
+ - spec/cassettes/get_profile_success.yml
215
+ - spec/cassettes/get_summary_success.yml
216
+ - spec/lib/human_api/app_spec.rb
217
+ - spec/lib/human_api/config_spec.rb
218
+ - spec/lib/human_api/human_spec.rb
219
+ - spec/spec_helper.rb
220
+ has_rdoc: