validic 0.3.3 → 0.4.1

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.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rspec +0 -1
  4. data/Gemfile +12 -1
  5. data/Gemfile.lock +32 -62
  6. data/README.md +442 -28
  7. data/lib/validic.rb +3 -20
  8. data/lib/validic/app.rb +11 -0
  9. data/lib/validic/biometrics.rb +9 -0
  10. data/lib/validic/client.rb +35 -77
  11. data/lib/validic/diabetes.rb +4 -60
  12. data/lib/validic/error.rb +33 -0
  13. data/lib/validic/extra.rb +10 -0
  14. data/lib/validic/fitness.rb +4 -57
  15. data/lib/validic/nutrition.rb +5 -61
  16. data/lib/validic/organization.rb +6 -13
  17. data/lib/validic/profile.rb +4 -39
  18. data/lib/validic/response.rb +15 -0
  19. data/lib/validic/rest/apps.rb +21 -0
  20. data/lib/validic/rest/biometrics.rb +39 -0
  21. data/lib/validic/rest/diabetes.rb +39 -0
  22. data/lib/validic/rest/fitness.rb +40 -0
  23. data/lib/validic/rest/nutrition.rb +40 -0
  24. data/lib/validic/rest/organizations.rb +12 -0
  25. data/lib/validic/rest/profile.rb +18 -0
  26. data/lib/validic/rest/request.rb +95 -0
  27. data/lib/validic/rest/routine.rb +40 -0
  28. data/lib/validic/rest/sleep.rb +41 -0
  29. data/lib/validic/rest/tobacco_cessation.rb +40 -0
  30. data/lib/validic/rest/users.rb +55 -0
  31. data/lib/validic/rest/utils.rb +28 -0
  32. data/lib/validic/rest/weight.rb +43 -0
  33. data/lib/validic/routine.rb +4 -55
  34. data/lib/validic/sleep.rb +4 -59
  35. data/lib/validic/summary.rb +18 -0
  36. data/lib/validic/tobacco_cessation.rb +4 -53
  37. data/lib/validic/user.rb +4 -99
  38. data/lib/validic/utils.rb +13 -0
  39. data/lib/validic/version.rb +1 -1
  40. data/lib/validic/weight.rb +4 -57
  41. data/spec/fixtures/apps.json +32 -0
  42. data/spec/fixtures/biometrics-expanded.json +56 -0
  43. data/spec/fixtures/biometrics-extras.json +35 -0
  44. data/spec/fixtures/biometrics_record.json +36 -0
  45. data/spec/fixtures/biometrics_records.json +54 -0
  46. data/spec/fixtures/bulk_biometrics_records.json +55 -0
  47. data/spec/fixtures/bulk_diabetes_records.json +37 -0
  48. data/spec/fixtures/bulk_fitnesses.json +35 -0
  49. data/spec/fixtures/bulk_nutritions.json +37 -0
  50. data/spec/fixtures/bulk_sleeps.json +35 -0
  51. data/spec/fixtures/bulk_tobacco_cessations.json +33 -0
  52. data/spec/fixtures/conflict.json +5 -0
  53. data/spec/fixtures/diabetes-expanded.json +38 -0
  54. data/spec/fixtures/diabetes-extras.json +17 -0
  55. data/spec/fixtures/diabetes_record.json +18 -0
  56. data/spec/fixtures/diabetes_records.json +36 -0
  57. data/spec/fixtures/fitness-expanded.json +1521 -0
  58. data/spec/fixtures/fitness-extras.json +15 -0
  59. data/spec/fixtures/fitness.json +16 -0
  60. data/spec/fixtures/fitnesses.json +34 -0
  61. data/spec/fixtures/forbidden.json +5 -0
  62. data/spec/fixtures/internal_server.json +4 -0
  63. data/spec/fixtures/me.json +5 -0
  64. data/spec/fixtures/not_found.json +5 -0
  65. data/spec/fixtures/nutrition-expanded.json +123 -0
  66. data/spec/fixtures/nutrition-extras.json +13 -0
  67. data/spec/fixtures/nutrition.json +18 -0
  68. data/spec/fixtures/nutritions-expanded.json +123 -0
  69. data/spec/fixtures/nutritions.json +36 -0
  70. data/spec/fixtures/organizations.json +27 -0
  71. data/spec/fixtures/profile.json +13 -0
  72. data/spec/fixtures/refresh_token.json +7 -0
  73. data/spec/fixtures/routine-expanded.json +749 -0
  74. data/spec/fixtures/routine-extras.json +14 -0
  75. data/spec/fixtures/routine.json +17 -0
  76. data/spec/fixtures/routines.json +47 -0
  77. data/spec/fixtures/sleep-expanded.json +51 -0
  78. data/spec/fixtures/sleep-extras.json +15 -0
  79. data/spec/fixtures/sleep.json +16 -0
  80. data/spec/fixtures/sleeps.json +48 -0
  81. data/spec/fixtures/synced_apps.json +43 -0
  82. data/spec/fixtures/tobacco_cessation-expanded.json +33 -0
  83. data/spec/fixtures/tobacco_cessation-extras.json +12 -0
  84. data/spec/fixtures/tobacco_cessation.json +14 -0
  85. data/spec/fixtures/tobacco_cessations.json +32 -0
  86. data/spec/fixtures/unauthorized.json +4 -0
  87. data/spec/fixtures/unprocessable_entity.json +5 -0
  88. data/spec/fixtures/updated_user.json +9 -0
  89. data/spec/fixtures/user.json +8 -0
  90. data/spec/fixtures/user_with_profile.json +14 -0
  91. data/spec/fixtures/users.json +23 -0
  92. data/spec/fixtures/weight-expanded.json +66 -0
  93. data/spec/fixtures/weight-extras.json +15 -0
  94. data/spec/fixtures/weight.json +18 -0
  95. data/spec/fixtures/weights.json +48 -0
  96. data/spec/spec_helper.rb +47 -33
  97. data/spec/validic/client_spec.rb +5 -38
  98. data/spec/validic/error_spec.rb +73 -0
  99. data/spec/validic/expanded_spec.rb +87 -0
  100. data/spec/validic/rest/apps_spec.rb +41 -0
  101. data/spec/validic/rest/biometrics_spec.rb +131 -0
  102. data/spec/validic/rest/diabetes_spec.rb +131 -0
  103. data/spec/validic/rest/fitness_spec.rb +131 -0
  104. data/spec/validic/rest/nutrition_spec.rb +144 -0
  105. data/spec/validic/rest/organizations_spec.rb +24 -0
  106. data/spec/validic/rest/profile_spec.rb +44 -0
  107. data/spec/validic/rest/routine_spec.rb +129 -0
  108. data/spec/validic/rest/sleep_spec.rb +148 -0
  109. data/spec/validic/rest/tobacco_cessation_spec.rb +131 -0
  110. data/spec/validic/rest/users_spec.rb +170 -0
  111. data/spec/validic/rest/weight_spec.rb +150 -0
  112. data/spec/validic/summary_spec.rb +3 -0
  113. data/spec/validic_spec.rb +19 -31
  114. data/validic.gemspec +0 -13
  115. metadata +174 -194
  116. data/lib/validic/biometric.rb +0 -97
  117. data/lib/validic/request.rb +0 -46
  118. data/lib/validic/third_party_app.rb +0 -32
  119. data/spec/validic/biometrics_spec.rb +0 -43
  120. data/spec/validic/diabetes_spec.rb +0 -89
  121. data/spec/validic/fitness_spec.rb +0 -85
  122. data/spec/validic/nutrition_spec.rb +0 -91
  123. data/spec/validic/organization_spec.rb +0 -26
  124. data/spec/validic/profile_spec.rb +0 -19
  125. data/spec/validic/routine_spec.rb +0 -82
  126. data/spec/validic/sleep_spec.rb +0 -86
  127. data/spec/validic/third_party_app_spec.rb +0 -32
  128. data/spec/validic/tobacco_cessation_spec.rb +0 -81
  129. data/spec/validic/user_spec.rb +0 -81
  130. 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
+ }
@@ -1,44 +1,58 @@
1
1
  require 'validic'
2
- require 'vcr'
3
- require 'simplecov'
4
- require 'simplecov-rcov'
5
- require 'api_matchers'
6
-
7
- class SimpleCov::Formatter::MergedFormatter
8
- def format(result)
9
- SimpleCov::Formatter::HTMLFormatter.new.format(result)
10
- SimpleCov::Formatter::RcovFormatter.new.format(result)
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
- SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
15
- SimpleCov.start do
16
- add_filter '/vendor'
20
+ def fixture_path
21
+ File.expand_path('../fixtures', __FILE__)
17
22
  end
18
23
 
19
- VCR.configure do |c|
20
- c.allow_http_connections_when_no_cassette = true
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
- RSpec.configure do |c|
28
- c.include APIMatchers::RSpecMatchers
28
+ def a_delete(path)
29
+ a_request(:delete, Validic::BASE_URL + path)
30
+ end
29
31
 
30
- c.treat_symbols_as_metadata_keys_with_true_values = true
32
+ def a_get(path)
33
+ a_request(:get, Validic::BASE_URL + path)
34
+ end
31
35
 
32
- ##
33
- # Add gem specific configuration for easy access
34
- #
35
- c.before(:each) do
36
- Validic.configure do |config|
37
- # This is using ACME Corp Credentials as per Documentation
38
- config.api_url = 'https://api.validic.com'
39
- config.api_version = 'v1'
40
- config.access_token = ENV['TEST_ORG_TOKEN']
41
- config.organization_id = '51aca5a06dedda916400002b'
42
- end
43
- end
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
@@ -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
- it "creates a Faraday::Connection" do
9
- client.connection.should be_kind_of Faraday::Connection
10
- end
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 "#weight", vcr: true do
29
- latest_weight = client.latest(:weight)
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