validic 0.3.3 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.rspec +0 -1
- data/Gemfile +12 -1
- data/Gemfile.lock +32 -62
- data/README.md +442 -28
- data/lib/validic.rb +3 -20
- data/lib/validic/app.rb +11 -0
- data/lib/validic/biometrics.rb +9 -0
- data/lib/validic/client.rb +35 -77
- data/lib/validic/diabetes.rb +4 -60
- data/lib/validic/error.rb +33 -0
- data/lib/validic/extra.rb +10 -0
- data/lib/validic/fitness.rb +4 -57
- data/lib/validic/nutrition.rb +5 -61
- data/lib/validic/organization.rb +6 -13
- data/lib/validic/profile.rb +4 -39
- data/lib/validic/response.rb +15 -0
- data/lib/validic/rest/apps.rb +21 -0
- data/lib/validic/rest/biometrics.rb +39 -0
- data/lib/validic/rest/diabetes.rb +39 -0
- data/lib/validic/rest/fitness.rb +40 -0
- data/lib/validic/rest/nutrition.rb +40 -0
- data/lib/validic/rest/organizations.rb +12 -0
- data/lib/validic/rest/profile.rb +18 -0
- data/lib/validic/rest/request.rb +95 -0
- data/lib/validic/rest/routine.rb +40 -0
- data/lib/validic/rest/sleep.rb +41 -0
- data/lib/validic/rest/tobacco_cessation.rb +40 -0
- data/lib/validic/rest/users.rb +55 -0
- data/lib/validic/rest/utils.rb +28 -0
- data/lib/validic/rest/weight.rb +43 -0
- data/lib/validic/routine.rb +4 -55
- data/lib/validic/sleep.rb +4 -59
- data/lib/validic/summary.rb +18 -0
- data/lib/validic/tobacco_cessation.rb +4 -53
- data/lib/validic/user.rb +4 -99
- data/lib/validic/utils.rb +13 -0
- data/lib/validic/version.rb +1 -1
- data/lib/validic/weight.rb +4 -57
- data/spec/fixtures/apps.json +32 -0
- data/spec/fixtures/biometrics-expanded.json +56 -0
- data/spec/fixtures/biometrics-extras.json +35 -0
- data/spec/fixtures/biometrics_record.json +36 -0
- data/spec/fixtures/biometrics_records.json +54 -0
- data/spec/fixtures/bulk_biometrics_records.json +55 -0
- data/spec/fixtures/bulk_diabetes_records.json +37 -0
- data/spec/fixtures/bulk_fitnesses.json +35 -0
- data/spec/fixtures/bulk_nutritions.json +37 -0
- data/spec/fixtures/bulk_sleeps.json +35 -0
- data/spec/fixtures/bulk_tobacco_cessations.json +33 -0
- data/spec/fixtures/conflict.json +5 -0
- data/spec/fixtures/diabetes-expanded.json +38 -0
- data/spec/fixtures/diabetes-extras.json +17 -0
- data/spec/fixtures/diabetes_record.json +18 -0
- data/spec/fixtures/diabetes_records.json +36 -0
- data/spec/fixtures/fitness-expanded.json +1521 -0
- data/spec/fixtures/fitness-extras.json +15 -0
- data/spec/fixtures/fitness.json +16 -0
- data/spec/fixtures/fitnesses.json +34 -0
- data/spec/fixtures/forbidden.json +5 -0
- data/spec/fixtures/internal_server.json +4 -0
- data/spec/fixtures/me.json +5 -0
- data/spec/fixtures/not_found.json +5 -0
- data/spec/fixtures/nutrition-expanded.json +123 -0
- data/spec/fixtures/nutrition-extras.json +13 -0
- data/spec/fixtures/nutrition.json +18 -0
- data/spec/fixtures/nutritions-expanded.json +123 -0
- data/spec/fixtures/nutritions.json +36 -0
- data/spec/fixtures/organizations.json +27 -0
- data/spec/fixtures/profile.json +13 -0
- data/spec/fixtures/refresh_token.json +7 -0
- data/spec/fixtures/routine-expanded.json +749 -0
- data/spec/fixtures/routine-extras.json +14 -0
- data/spec/fixtures/routine.json +17 -0
- data/spec/fixtures/routines.json +47 -0
- data/spec/fixtures/sleep-expanded.json +51 -0
- data/spec/fixtures/sleep-extras.json +15 -0
- data/spec/fixtures/sleep.json +16 -0
- data/spec/fixtures/sleeps.json +48 -0
- data/spec/fixtures/synced_apps.json +43 -0
- data/spec/fixtures/tobacco_cessation-expanded.json +33 -0
- data/spec/fixtures/tobacco_cessation-extras.json +12 -0
- data/spec/fixtures/tobacco_cessation.json +14 -0
- data/spec/fixtures/tobacco_cessations.json +32 -0
- data/spec/fixtures/unauthorized.json +4 -0
- data/spec/fixtures/unprocessable_entity.json +5 -0
- data/spec/fixtures/updated_user.json +9 -0
- data/spec/fixtures/user.json +8 -0
- data/spec/fixtures/user_with_profile.json +14 -0
- data/spec/fixtures/users.json +23 -0
- data/spec/fixtures/weight-expanded.json +66 -0
- data/spec/fixtures/weight-extras.json +15 -0
- data/spec/fixtures/weight.json +18 -0
- data/spec/fixtures/weights.json +48 -0
- data/spec/spec_helper.rb +47 -33
- data/spec/validic/client_spec.rb +5 -38
- data/spec/validic/error_spec.rb +73 -0
- data/spec/validic/expanded_spec.rb +87 -0
- data/spec/validic/rest/apps_spec.rb +41 -0
- data/spec/validic/rest/biometrics_spec.rb +131 -0
- data/spec/validic/rest/diabetes_spec.rb +131 -0
- data/spec/validic/rest/fitness_spec.rb +131 -0
- data/spec/validic/rest/nutrition_spec.rb +144 -0
- data/spec/validic/rest/organizations_spec.rb +24 -0
- data/spec/validic/rest/profile_spec.rb +44 -0
- data/spec/validic/rest/routine_spec.rb +129 -0
- data/spec/validic/rest/sleep_spec.rb +148 -0
- data/spec/validic/rest/tobacco_cessation_spec.rb +131 -0
- data/spec/validic/rest/users_spec.rb +170 -0
- data/spec/validic/rest/weight_spec.rb +150 -0
- data/spec/validic/summary_spec.rb +3 -0
- data/spec/validic_spec.rb +19 -31
- data/validic.gemspec +0 -13
- metadata +174 -194
- data/lib/validic/biometric.rb +0 -97
- data/lib/validic/request.rb +0 -46
- data/lib/validic/third_party_app.rb +0 -32
- data/spec/validic/biometrics_spec.rb +0 -43
- data/spec/validic/diabetes_spec.rb +0 -89
- data/spec/validic/fitness_spec.rb +0 -85
- data/spec/validic/nutrition_spec.rb +0 -91
- data/spec/validic/organization_spec.rb +0 -26
- data/spec/validic/profile_spec.rb +0 -19
- data/spec/validic/routine_spec.rb +0 -82
- data/spec/validic/sleep_spec.rb +0 -86
- data/spec/validic/third_party_app_spec.rb +0 -32
- data/spec/validic/tobacco_cessation_spec.rb +0 -81
- data/spec/validic/user_spec.rb +0 -81
- data/spec/validic/weight_spec.rb +0 -88
@@ -0,0 +1,15 @@
|
|
1
|
+
{
|
2
|
+
"weight": {
|
3
|
+
"timestamp": "2013-03-10T07:12:16+00:00",
|
4
|
+
"utc_offset": "+00:00",
|
5
|
+
"weight": 83.9146,
|
6
|
+
"height": 167.5,
|
7
|
+
"free_mass": 83.9146,
|
8
|
+
"fat_percent": 21.4,
|
9
|
+
"mass_weight": 83.9146,
|
10
|
+
"bmi": 29.9,
|
11
|
+
"data_id": "12345",
|
12
|
+
"extras": {"stars": 3}
|
13
|
+
},
|
14
|
+
"access_token": "e7ba1f04e88f25d399a91c8cbcd72300e01309e96b7725e40b49cd1effaa5deb"
|
15
|
+
}
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"code": 201,
|
3
|
+
"message": "Ok",
|
4
|
+
"weight": {
|
5
|
+
"_id": "51552cddfded0807c4000083",
|
6
|
+
"timestamp": "2013-03-10T07:12:16+00:00",
|
7
|
+
"utc_offset": "+00:00",
|
8
|
+
"weight": 83.9146,
|
9
|
+
"height": 167.5,
|
10
|
+
"free_mass": 83.9146,
|
11
|
+
"fat_percent": 21.4,
|
12
|
+
"mass_weight": 83.9146,
|
13
|
+
"bmi": 29.9,
|
14
|
+
"source": "sample_app",
|
15
|
+
"source_name": "Sample App",
|
16
|
+
"last_updated": "2013-03-10T07:12:16+00:00"
|
17
|
+
}
|
18
|
+
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
{
|
2
|
+
"summary": {
|
3
|
+
"status": 200,
|
4
|
+
"message": "OK",
|
5
|
+
"results": 3,
|
6
|
+
"start_date": "2013-03-27T00:00:00+00:00",
|
7
|
+
"end_date": "2013-03-27T23:59:59+00:00",
|
8
|
+
"offset": 0,
|
9
|
+
"limit": 100,
|
10
|
+
"previous": null,
|
11
|
+
"next": null,
|
12
|
+
"params": {
|
13
|
+
"start_date": null,
|
14
|
+
"end_date": null,
|
15
|
+
"offset": null,
|
16
|
+
"limit": null
|
17
|
+
}
|
18
|
+
}, "weight": [
|
19
|
+
{
|
20
|
+
"_id": "51552cdcfded0807c4000075",
|
21
|
+
"timestamp": "2013-03-10T07:12:16+00:00",
|
22
|
+
"utc_offset": "+00:00",
|
23
|
+
"weight": 83.9146,
|
24
|
+
"height": 167.5,
|
25
|
+
"free_mass": 83.9146,
|
26
|
+
"fat_percent": 21.4,
|
27
|
+
"mass_weight": 83.9146,
|
28
|
+
"bmi": 29.9,
|
29
|
+
"source": "sample_app",
|
30
|
+
"source_name": "Sample App",
|
31
|
+
"last_updated": "2013-03-10T07:12:16+00:00"
|
32
|
+
},
|
33
|
+
{
|
34
|
+
"_id": "531552cdcfded0807c4000075",
|
35
|
+
"timestamp": "2013-03-10T07:12:16+00:00",
|
36
|
+
"utc_offset": "+00:00",
|
37
|
+
"weight": 83.9146,
|
38
|
+
"height": 144,
|
39
|
+
"free_mass": 83.9146,
|
40
|
+
"fat_percent": 21.4,
|
41
|
+
"mass_weight": 83.9146,
|
42
|
+
"bmi": 29.9,
|
43
|
+
"source": "sample_app",
|
44
|
+
"source_name": "Sample App",
|
45
|
+
"last_updated": "2013-03-10T07:12:16+00:00"
|
46
|
+
}
|
47
|
+
]
|
48
|
+
}
|
data/spec/spec_helper.rb
CHANGED
@@ -1,44 +1,58 @@
|
|
1
1
|
require 'validic'
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
require 'pry'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
RSpec.configure do |config|
|
7
|
+
config.before(:each) do
|
8
|
+
Validic.configure do |c|
|
9
|
+
c.api_url = 'https://api.validic.com'
|
10
|
+
c.api_version = 'v1'
|
11
|
+
c.access_token = '1'
|
12
|
+
c.organization_id = '1'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
config.expect_with :rspec do |c|
|
16
|
+
c.syntax = :expect
|
11
17
|
end
|
12
18
|
end
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
add_filter '/vendor'
|
20
|
+
def fixture_path
|
21
|
+
File.expand_path('../fixtures', __FILE__)
|
17
22
|
end
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
c.cassette_library_dir = 'spec/cassette'
|
22
|
-
c.hook_into :webmock
|
23
|
-
c.configure_rspec_metadata!
|
24
|
-
c.default_cassette_options = { record: :new_episodes }
|
24
|
+
def fixture(file)
|
25
|
+
File.new(fixture_path + '/' + file)
|
25
26
|
end
|
26
27
|
|
27
|
-
|
28
|
-
|
28
|
+
def a_delete(path)
|
29
|
+
a_request(:delete, Validic::BASE_URL + path)
|
30
|
+
end
|
29
31
|
|
30
|
-
|
32
|
+
def a_get(path)
|
33
|
+
a_request(:get, Validic::BASE_URL + path)
|
34
|
+
end
|
31
35
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
def a_post(path)
|
37
|
+
a_request(:post, Validic::BASE_URL + path)
|
38
|
+
end
|
39
|
+
|
40
|
+
def a_put(path)
|
41
|
+
a_request(:put, Validic::BASE_URL + path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def stub_delete(path)
|
45
|
+
stub_request(:delete, Validic::BASE_URL + path)
|
46
|
+
end
|
47
|
+
|
48
|
+
def stub_get(path)
|
49
|
+
stub_request(:get, Validic::BASE_URL + path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def stub_post(path)
|
53
|
+
stub_request(:post, Validic::BASE_URL + path)
|
54
|
+
end
|
55
|
+
|
56
|
+
def stub_put(path)
|
57
|
+
stub_request(:put, Validic::BASE_URL + path)
|
44
58
|
end
|
data/spec/validic/client_spec.rb
CHANGED
@@ -2,48 +2,15 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Validic::Client do
|
5
|
-
|
6
5
|
let(:client) { Validic::Client.new }
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
context "#latest" do
|
13
|
-
it "#fitness", vcr: true do
|
14
|
-
latest_fitness = client.latest(:fitness)
|
15
|
-
latest_fitness.summary.should_not be_nil
|
16
|
-
end
|
17
|
-
|
18
|
-
it "#sleep", vcr: true do
|
19
|
-
latest_sleep = client.latest(:sleep)
|
20
|
-
latest_sleep.summary.should_not be_nil
|
21
|
-
end
|
22
|
-
|
23
|
-
it "#routine", vcr: true do
|
24
|
-
latest_routine = client.latest(:routine)
|
25
|
-
latest_routine.summary.should_not be_nil
|
7
|
+
describe '#connection' do
|
8
|
+
it 'returns a Faraday::Connection object' do
|
9
|
+
expect(client.connection).to be_kind_of Faraday::Connection
|
26
10
|
end
|
27
11
|
|
28
|
-
it
|
29
|
-
|
30
|
-
latest_weight.summary.should_not be_nil
|
31
|
-
end
|
32
|
-
|
33
|
-
it "#biometrics", vcr: true do
|
34
|
-
latest_biometrics = client.latest(:biometrics)
|
35
|
-
latest_biometrics.summary.should_not be_nil
|
36
|
-
end
|
37
|
-
|
38
|
-
it "#nutrition", vcr: true do
|
39
|
-
latest_nutrition = client.latest(:nutrition)
|
40
|
-
latest_nutrition.summary.should_not be_nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it "#tobacco_cessation", vcr: true do
|
44
|
-
latest_tobacco_cessation = client.latest(:tobacco_cessation)
|
45
|
-
latest_tobacco_cessation.summary.should_not be_nil
|
12
|
+
it 'has SSL enabled' do
|
13
|
+
expect(client.connection.ssl.verify).to be true
|
46
14
|
end
|
47
15
|
end
|
48
|
-
|
49
16
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Validic::Error do
|
4
|
+
let(:client) { Validic::Client.new }
|
5
|
+
|
6
|
+
context 'not found' do
|
7
|
+
%w(weight nutrition biometrics diabetes tobacco_cessation routine fitness weight).each do |activity|
|
8
|
+
before do
|
9
|
+
stub_get("/organizations/1/users/0/#{activity}.json")
|
10
|
+
.with(query: { access_token: '1' })
|
11
|
+
.to_return(status: 404, body: fixture('not_found.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
12
|
+
end
|
13
|
+
it 'raises a NotFound error' do
|
14
|
+
expect { client.send("get_#{activity}", user_id: '0') }.to raise_error(Validic::Error::NotFound)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'forbidden' do
|
20
|
+
before do
|
21
|
+
stub_get("/organizations/0.json")
|
22
|
+
.with(query: { access_token: '0' })
|
23
|
+
.to_return(status: 403, body: fixture('forbidden.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
24
|
+
end
|
25
|
+
it 'raises a Forbidden error' do
|
26
|
+
expect { client.get_organization(organization_id: '0', access_token: '0') }.to raise_error(Validic::Error::Forbidden)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'unprocessable entity' do
|
31
|
+
before do
|
32
|
+
stub_post("/organizations/1/users/1/nutrition.json")
|
33
|
+
.with(body: { nutrition: {}, access_token: '1' })
|
34
|
+
.to_return(status: 422, body: fixture('unprocessable_entity.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
35
|
+
end
|
36
|
+
it 'raises an UnprocessableEntity error' do
|
37
|
+
expect { client.create_nutrition(user_id: '1') }.to raise_error(Validic::Error::UnprocessableEntity)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'conflict' do
|
42
|
+
before do
|
43
|
+
stub_post("/organizations/1/users.json")
|
44
|
+
.with(body: { user: { uid: '123' }, access_token: '1'}.to_json)
|
45
|
+
.to_return(status: 409, body: fixture('conflict.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
46
|
+
end
|
47
|
+
it 'raises a Conflict error' do
|
48
|
+
expect { client.provision_user(uid: '123') }.to raise_error(Validic::Error::Conflict)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context 'internal server error' do
|
53
|
+
before do
|
54
|
+
stub_post("/organizations/1/users.json")
|
55
|
+
.with(body: { user: '123', access_token: '1'}.to_json)
|
56
|
+
.to_return(status: 500, body: fixture('internal_server.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
57
|
+
end
|
58
|
+
it 'raises a Conflict error' do
|
59
|
+
expect { client.provision_user('123') }.to raise_error(Validic::Error::InternalServerError)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'unauthorized' do
|
64
|
+
before do
|
65
|
+
stub_get("/profile.json")
|
66
|
+
.with(query: { access_token: '1' })
|
67
|
+
.to_return(status: 401, body: fixture('unauthorized.json'), headers: {content_type: 'application/json; charset=utf-8'})
|
68
|
+
end
|
69
|
+
it 'raises a Conflict error' do
|
70
|
+
expect { client.get_profile }.to raise_error(Validic::Error::Unauthorized)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'expanded for all objects' do
|
4
|
+
let(:client) { Validic::Client.new }
|
5
|
+
objects = ['nutrition', 'fitness', 'routine', 'sleep', 'weight', 'diabetes',
|
6
|
+
'biometrics', 'tobacco_cessation']
|
7
|
+
|
8
|
+
objects.each do |object|
|
9
|
+
context "#create #{object}" do
|
10
|
+
before do
|
11
|
+
#set up stub request for a create call with extras
|
12
|
+
stub_post("/organizations/1/users/1/#{object}.json")
|
13
|
+
.with(body: { object.to_sym => { timestamp: '2013-03-10T07:12:16+00:00',
|
14
|
+
activity_id: '12345', extras: "{\"stars\": 3}" }, access_token: '1' }.to_json)
|
15
|
+
.to_return(body: fixture("#{object}-extras.json"),
|
16
|
+
headers: { content_type: 'application/json; charset=utf-8'} )
|
17
|
+
|
18
|
+
#use the create_object method
|
19
|
+
@obj = client.send("create_#{object}", user_id: '1', timestamp: '2013-03-10T07:12:16+00:00',
|
20
|
+
activity_id: '12345',
|
21
|
+
extras: "{\"stars\": 3}")
|
22
|
+
end
|
23
|
+
it 'renders correct path' do
|
24
|
+
expect(a_post("/organizations/1/users/1/#{object}.json")
|
25
|
+
.with(body: { object.to_sym => { timestamp: '2013-03-10T07:12:16+00:00',
|
26
|
+
activity_id: '12345', extras: "{\"stars\": 3}"},
|
27
|
+
access_token: '1' }.to_json)).to have_been_made
|
28
|
+
end
|
29
|
+
it 'creates the correct object' do
|
30
|
+
klass = Validic.const_get(camelize_response_key(object))
|
31
|
+
expect(@obj).to be_a klass
|
32
|
+
expect(@obj.timestamp).to eq '2013-03-10T07:12:16+00:00'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "#update #{object}" do
|
36
|
+
before do
|
37
|
+
stub_put("/organizations/1/users/1/#{object}/51552cddfded0807c4000096.json")
|
38
|
+
.with(body: { object.to_sym => { timestamp: '2013-03-10T07:12:16+00:00',
|
39
|
+
extras: "{\"stars\": 3}"}, access_token: '1' }.to_json)
|
40
|
+
.to_return(body: fixture("#{object}-extras.json"),
|
41
|
+
headers: { content_type: 'application/json; charset=utf-8'} )
|
42
|
+
@obj = client.send("update_#{object}", user_id: '1', _id: "51552cddfded0807c4000096",
|
43
|
+
timestamp: '2013-03-10T07:12:16+00:00',
|
44
|
+
extras: "{\"stars\": 3}")
|
45
|
+
end
|
46
|
+
it 'requests the correct resource' do
|
47
|
+
expect(a_put("/organizations/1/users/1/#{object}/51552cddfded0807c4000096.json")
|
48
|
+
.with(body: { object.to_sym => { timestamp: '2013-03-10T07:12:16+00:00',
|
49
|
+
extras: "{\"stars\": 3}"},
|
50
|
+
access_token: '1' }.to_json)).to have_been_made
|
51
|
+
end
|
52
|
+
it 'returns an object' do
|
53
|
+
klass = Validic.const_get(camelize_response_key(object))
|
54
|
+
expect(@obj).to be_a klass
|
55
|
+
expect(@obj.timestamp).to eq '2013-03-10T07:12:16+00:00'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
context "#get #{object}" do
|
59
|
+
before do
|
60
|
+
stub_get("/organizations/1/#{object}.json")
|
61
|
+
.with(query: { access_token: '1', expanded: '1' })
|
62
|
+
.to_return(body: fixture("#{object}-expanded.json"),
|
63
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
64
|
+
|
65
|
+
@obj = client.send("get_#{object}", expanded: '1')
|
66
|
+
end
|
67
|
+
it 'returns a validic response' do
|
68
|
+
expect(@obj).to be_a Validic::Response
|
69
|
+
end
|
70
|
+
it 'makes an object URI request with expanded' do
|
71
|
+
expect(a_get("/organizations/1/#{object}.json")
|
72
|
+
.with(query: { access_token: '1', expanded: '1' }))
|
73
|
+
.to have_been_made
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def camelize_response_key(str)
|
82
|
+
key = str
|
83
|
+
key = key.include?('_') ? key.split('_').map(&:capitalize).join : key.capitalize
|
84
|
+
key.chop! if %w(Users Apps).include?(key) #strip last letter off to match ::User or ::App
|
85
|
+
key
|
86
|
+
end
|
87
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Validic::REST::Apps do
|
4
|
+
let(:client) { Validic::Client.new }
|
5
|
+
|
6
|
+
describe "#get_apps" do
|
7
|
+
before do
|
8
|
+
stub_get("/organizations/1/apps.json")
|
9
|
+
.with(query: { access_token: '1' })
|
10
|
+
.to_return(body: fixture('apps.json'),
|
11
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
12
|
+
@apps = client.get_org_apps
|
13
|
+
end
|
14
|
+
it 'returns a response object' do
|
15
|
+
expect(@apps).to be_a Validic::Response
|
16
|
+
end
|
17
|
+
it 'makes an apps request to the correct url' do
|
18
|
+
expect(a_get('/organizations/1/apps.json')
|
19
|
+
.with(query: { access_token: '1' })).to have_been_made
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#get_user_synced_apps' do
|
24
|
+
before do
|
25
|
+
stub_get('/organizations/1/sync_apps.json')
|
26
|
+
.with(query: { authentication_token: '2', access_token: '1' })
|
27
|
+
.to_return(body: fixture('synced_apps.json'),
|
28
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
29
|
+
@synced_apps = client.get_user_synced_apps(authentication_token: '2')
|
30
|
+
end
|
31
|
+
it 'returns a response object' do
|
32
|
+
expect(@synced_apps).to be_a Validic::Response
|
33
|
+
end
|
34
|
+
it 'makes a sync apps call to the correct url' do
|
35
|
+
expect(a_get('/organizations/1/sync_apps.json')
|
36
|
+
.with(query: { authentication_token: '2', access_token: '1' }))
|
37
|
+
.to have_been_made
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Validic::REST::Biometrics do
|
5
|
+
let(:client) { Validic::Client.new }
|
6
|
+
|
7
|
+
describe "#get_biometrics" do
|
8
|
+
context 'no user_id given' do
|
9
|
+
before do
|
10
|
+
stub_get("/organizations/1/biometrics.json")
|
11
|
+
.with(query: { access_token: '1' })
|
12
|
+
.to_return(body: fixture('biometrics_records.json'),
|
13
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
14
|
+
end
|
15
|
+
it 'returns a validic response object' do
|
16
|
+
biometrics_record = client.get_biometrics
|
17
|
+
expect(biometrics_record).to be_a Validic::Response
|
18
|
+
end
|
19
|
+
it 'makes a biometrics request to the correct url' do
|
20
|
+
client.get_biometrics
|
21
|
+
expect(a_get('/organizations/1/biometrics.json').with(query: { access_token: '1' })).to have_been_made
|
22
|
+
end
|
23
|
+
end
|
24
|
+
context 'with user_id' do
|
25
|
+
before do
|
26
|
+
stub_get("/organizations/1/users/1/biometrics.json")
|
27
|
+
.with(query: { access_token: '1' })
|
28
|
+
.to_return(body: fixture('bulk_biometrics_records.json'),
|
29
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
30
|
+
end
|
31
|
+
it 'returns a Response' do
|
32
|
+
biometrics_record = client.get_biometrics(user_id: '1')
|
33
|
+
expect(biometrics_record).to be_a Validic::Response
|
34
|
+
end
|
35
|
+
it 'makes a biometrics request to the correct url' do
|
36
|
+
client.get_biometrics(user_id: '1')
|
37
|
+
expect(a_get('/organizations/1/users/1/biometrics.json').with(query: { access_token: '1' })).to have_been_made
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#create_biometrics' do
|
43
|
+
before do
|
44
|
+
stub_post("/organizations/1/users/1/biometrics.json")
|
45
|
+
.with(body: { biometrics: { timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345' },
|
46
|
+
access_token: '1' }.to_json)
|
47
|
+
.to_return(body: fixture('biometrics_record.json'),
|
48
|
+
headers: { content_type: 'application/json; charset=utf-8'} )
|
49
|
+
end
|
50
|
+
it 'requests the correct resource' do
|
51
|
+
client.create_biometrics(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
|
52
|
+
expect(a_post('/organizations/1/users/1/biometrics.json')
|
53
|
+
.with(body: { biometrics: { timestamp: '2013-03-10T07:12:16+00:00',
|
54
|
+
activity_id: '12345' },
|
55
|
+
access_token: '1' }.to_json)).to have_been_made
|
56
|
+
end
|
57
|
+
it 'returns a Biometrics' do
|
58
|
+
biometrics_record = client.create_biometrics(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
|
59
|
+
expect(biometrics_record).to be_a Validic::Biometrics
|
60
|
+
expect(biometrics_record.timestamp).to eq '2013-03-10T07:12:16+00:00'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "#update_biometrics" do
|
65
|
+
before do
|
66
|
+
stub_put("/organizations/1/users/1/biometrics/51552cddfded0807c4000096.json")
|
67
|
+
.with(body: { biometrics: { timestamp: '2013-03-10T07:12:16+00:00' },
|
68
|
+
access_token: '1' }.to_json)
|
69
|
+
.to_return(body: fixture('biometrics_record.json'),
|
70
|
+
headers: {content_type: 'application/json; charset=utf-8'})
|
71
|
+
end
|
72
|
+
it 'makes a biometrics request to the correct url' do
|
73
|
+
client.update_biometrics(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
|
74
|
+
expect(a_put('/organizations/1/users/1/biometrics/51552cddfded0807c4000096.json')
|
75
|
+
.with(body: { biometrics: { timestamp: '2013-03-10T07:12:16+00:00' },
|
76
|
+
access_token: '1' }.to_json)).to have_been_made
|
77
|
+
end
|
78
|
+
it 'returns a Biometrics' do
|
79
|
+
biometrics_record = client.update_biometrics(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
|
80
|
+
expect(biometrics_record).to be_a Validic::Biometrics
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#delete_biometrics' do
|
85
|
+
context 'when resource is found' do
|
86
|
+
before do
|
87
|
+
stub_delete("/organizations/1/users/1/biometrics/51552cddfded0807c4000096.json")
|
88
|
+
.to_return(status: 200)
|
89
|
+
end
|
90
|
+
it 'returns true' do
|
91
|
+
biometrics_record = client.delete_biometrics(user_id: '1', _id: '51552cddfded0807c4000096')
|
92
|
+
expect(biometrics_record).to be true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
describe '#latest_biometrics' do
|
98
|
+
context 'with user_id' do
|
99
|
+
before do
|
100
|
+
stub_get("/organizations/1/users/2/biometrics/latest.json").
|
101
|
+
with(query: { access_token: '1' }).
|
102
|
+
to_return(body: fixture('biometrics_records.json'),
|
103
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
104
|
+
end
|
105
|
+
it 'makes a latest for biometrics' do
|
106
|
+
latest = client.latest_biometrics(user_id: '2')
|
107
|
+
expect(latest).to be_a Validic::Response
|
108
|
+
end
|
109
|
+
it 'builds a latest url' do
|
110
|
+
client.latest_biometrics(user_id: '2')
|
111
|
+
expect(a_get('/organizations/1/users/2/biometrics/latest.json').with(query: { access_token: '1' })).to have_been_made
|
112
|
+
end
|
113
|
+
end
|
114
|
+
context 'without user_id' do
|
115
|
+
before do
|
116
|
+
stub_get("/organizations/1/biometrics/latest.json").
|
117
|
+
with(query: { access_token: '1' }).
|
118
|
+
to_return(body: fixture('biometrics_records.json'),
|
119
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
120
|
+
end
|
121
|
+
it 'makes a request for latest biometrics records' do
|
122
|
+
latest = client.latest_biometrics
|
123
|
+
expect(latest).to be_a Validic::Response
|
124
|
+
end
|
125
|
+
it 'builds a latest url' do
|
126
|
+
client.latest_biometrics
|
127
|
+
expect(a_get('/organizations/1/biometrics/latest.json').with(query: { access_token: '1' })).to have_been_made
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|