validic 0.3.3 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
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,131 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::REST::Diabetes do
5
+ let(:client) { Validic::Client.new }
6
+
7
+ describe "#get_diabetes" do
8
+ context 'no user_id given' do
9
+ before do
10
+ stub_get("/organizations/1/diabetes.json")
11
+ .with(query: { access_token: '1' })
12
+ .to_return(body: fixture('diabetes_records.json'),
13
+ headers: { content_type: 'application/json; charset=utf-8' })
14
+ end
15
+ it 'returns a validic response object' do
16
+ diabetes_record = client.get_diabetes
17
+ expect(diabetes_record).to be_a Validic::Response
18
+ end
19
+ it 'makes a diabetes request to the correct url' do
20
+ client.get_diabetes
21
+ expect(a_get('/organizations/1/diabetes.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/diabetes.json")
27
+ .with(query: { access_token: '1' })
28
+ .to_return(body: fixture('bulk_diabetes_records.json'),
29
+ headers: { content_type: 'application/json; charset=utf-8' })
30
+ end
31
+ it 'returns a Response' do
32
+ diabetes_record = client.get_diabetes(user_id: '1')
33
+ expect(diabetes_record).to be_a Validic::Response
34
+ end
35
+ it 'makes a diabetes request to the correct url' do
36
+ client.get_diabetes(user_id: '1')
37
+ expect(a_get('/organizations/1/users/1/diabetes.json').with(query: { access_token: '1' })).to have_been_made
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#create_diabetes' do
43
+ before do
44
+ stub_post("/organizations/1/users/1/diabetes.json")
45
+ .with(body: { diabetes: { timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345' },
46
+ access_token: '1' }.to_json)
47
+ .to_return(body: fixture('diabetes_record.json'),
48
+ headers: { content_type: 'application/json; charset=utf-8'} )
49
+ end
50
+ it 'requests the correct resource' do
51
+ client.create_diabetes(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
52
+ expect(a_post('/organizations/1/users/1/diabetes.json')
53
+ .with(body: { diabetes: { 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 Diabetes' do
58
+ diabetes_record = client.create_diabetes(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
59
+ expect(diabetes_record).to be_a Validic::Diabetes
60
+ expect(diabetes_record.timestamp).to eq '2013-03-10T07:12:16+00:00'
61
+ end
62
+ end
63
+
64
+ describe "#update_diabetes" do
65
+ before do
66
+ stub_put("/organizations/1/users/1/diabetes/51552cddfded0807c4000096.json")
67
+ .with(body: { diabetes: { timestamp: '2013-03-10T07:12:16+00:00' },
68
+ access_token: '1' }.to_json)
69
+ .to_return(body: fixture('diabetes_record.json'),
70
+ headers: {content_type: 'application/json; charset=utf-8'})
71
+ end
72
+ it 'makes a diabetes request to the correct url' do
73
+ client.update_diabetes(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
74
+ expect(a_put('/organizations/1/users/1/diabetes/51552cddfded0807c4000096.json')
75
+ .with(body: { diabetes: { timestamp: '2013-03-10T07:12:16+00:00' },
76
+ access_token: '1' }.to_json)).to have_been_made
77
+ end
78
+ it 'returns a Diabetes' do
79
+ diabetes_record = client.update_diabetes(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
80
+ expect(diabetes_record).to be_a Validic::Diabetes
81
+ end
82
+ end
83
+
84
+ describe '#delete_diabetes' do
85
+ context 'when resource is found' do
86
+ before do
87
+ stub_delete("/organizations/1/users/1/diabetes/51552cddfded0807c4000096.json")
88
+ .to_return(status: 200)
89
+ end
90
+ it 'returns true' do
91
+ diabetes_record = client.delete_diabetes(user_id: '1', _id: '51552cddfded0807c4000096')
92
+ expect(diabetes_record).to be true
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '#latest_diabetes' do
98
+ context 'with user_id' do
99
+ before do
100
+ stub_get("/organizations/1/users/2/diabetes/latest.json").
101
+ with(query: { access_token: '1' }).
102
+ to_return(body: fixture('diabetes_records.json'),
103
+ headers: { content_type: 'application/json; charset=utf-8' })
104
+ end
105
+ it 'makes a latest for diabetes' do
106
+ latest = client.latest_diabetes(user_id: '2')
107
+ expect(latest).to be_a Validic::Response
108
+ end
109
+ it 'builds a latest url' do
110
+ client.latest_diabetes(user_id: '2')
111
+ expect(a_get('/organizations/1/users/2/diabetes/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/diabetes/latest.json").
117
+ with(query: { access_token: '1' }).
118
+ to_return(body: fixture('diabetes_records.json'),
119
+ headers: { content_type: 'application/json; charset=utf-8' })
120
+ end
121
+ it 'makes a request for latest diabetes records' do
122
+ latest = client.latest_diabetes
123
+ expect(latest).to be_a Validic::Response
124
+ end
125
+ it 'builds a latest url' do
126
+ client.latest_diabetes
127
+ expect(a_get('/organizations/1/diabetes/latest.json').with(query: { access_token: '1' })).to have_been_made
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,131 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::REST::Fitness do
5
+ let(:client) { Validic::Client.new }
6
+
7
+ describe "#get_fitness" do
8
+ context 'no user_id given' do
9
+ before do
10
+ stub_get("/organizations/1/fitness.json")
11
+ .with(query: { access_token: '1' })
12
+ .to_return(body: fixture('fitnesses.json'),
13
+ headers: { content_type: 'application/json; charset=utf-8' })
14
+ end
15
+ it 'returns a validic response object' do
16
+ fitness = client.get_fitness
17
+ expect(fitness).to be_a Validic::Response
18
+ end
19
+ it 'makes a fitness request to the correct url' do
20
+ client.get_fitness
21
+ expect(a_get('/organizations/1/fitness.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/fitness.json")
27
+ .with(query: { access_token: '1' })
28
+ .to_return(body: fixture('bulk_fitnesses.json'),
29
+ headers: { content_type: 'application/json; charset=utf-8' })
30
+ end
31
+ it 'returns a Response' do
32
+ fitness = client.get_fitness(user_id: '1')
33
+ expect(fitness).to be_a Validic::Response
34
+ end
35
+ it 'makes a fitness request to the correct url' do
36
+ client.get_fitness(user_id: '1')
37
+ expect(a_get('/organizations/1/users/1/fitness.json').with(query: { access_token: '1' })).to have_been_made
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '#create_fitness' do
43
+ before do
44
+ stub_post("/organizations/1/users/1/fitness.json")
45
+ .with(body: { fitness: { timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345' },
46
+ access_token: '1' }.to_json)
47
+ .to_return(body: fixture('fitness.json'),
48
+ headers: { content_type: 'application/json; charset=utf-8'} )
49
+ end
50
+ it 'requests the correct resource' do
51
+ client.create_fitness(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
52
+ expect(a_post('/organizations/1/users/1/fitness.json')
53
+ .with(body: { fitness: { 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 Fitness' do
58
+ fitness = client.create_fitness(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00', activity_id: '12345')
59
+ expect(fitness).to be_a Validic::Fitness
60
+ expect(fitness.timestamp).to eq '2013-03-10T07:12:16+00:00'
61
+ end
62
+ end
63
+
64
+ describe "#update_fitness" do
65
+ before do
66
+ stub_put("/organizations/1/users/1/fitness/51552cddfded0807c4000096.json")
67
+ .with(body: { fitness: { timestamp: '2013-03-10T07:12:16+00:00' },
68
+ access_token: '1' }.to_json)
69
+ .to_return(body: fixture('fitness.json'),
70
+ headers: {content_type: 'application/json; charset=utf-8'})
71
+ end
72
+ it 'makes a fitness request to the correct url' do
73
+ client.update_fitness(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
74
+ expect(a_put('/organizations/1/users/1/fitness/51552cddfded0807c4000096.json')
75
+ .with(body: { fitness: { timestamp: '2013-03-10T07:12:16+00:00' },
76
+ access_token: '1' }.to_json)).to have_been_made
77
+ end
78
+ it 'returns a Fitness' do
79
+ fitness = client.update_fitness(user_id: '1', _id: '51552cddfded0807c4000096', timestamp: '2013-03-10T07:12:16+00:00')
80
+ expect(fitness).to be_a Validic::Fitness
81
+ end
82
+ end
83
+
84
+ describe '#delete_fitness' do
85
+ context 'when resource is found' do
86
+ before do
87
+ stub_delete("/organizations/1/users/1/fitness/51552cddfded0807c4000096.json")
88
+ .to_return(status: 200)
89
+ end
90
+ it 'returns true' do
91
+ fitness = client.delete_fitness(user_id: '1', _id: '51552cddfded0807c4000096')
92
+ expect(fitness).to be true
93
+ end
94
+ end
95
+ end
96
+
97
+ describe '#latests_fitness' do
98
+ context 'with user_id' do
99
+ before do
100
+ stub_get("/organizations/1/users/2/fitness/latest.json").
101
+ with(query: { access_token: '1' }).
102
+ to_return(body: fixture('fitnesses.json'),
103
+ headers: { content_type: 'application/json; charset=utf-8' })
104
+ end
105
+ it 'makes a latest for fitness' do
106
+ latest = client.latest_fitness(user_id: '2')
107
+ expect(latest).to be_a Validic::Response
108
+ end
109
+ it 'builds a latest url' do
110
+ client.latest_fitness(user_id: '2')
111
+ expect(a_get('/organizations/1/users/2/fitness/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/fitness/latest.json").
117
+ with(query: { access_token: '1' }).
118
+ to_return(body: fixture('fitnesses.json'),
119
+ headers: { content_type: 'application/json; charset=utf-8' })
120
+ end
121
+ it 'makes a latest for fitness' do
122
+ latest = client.latest_fitness
123
+ expect(latest).to be_a Validic::Response
124
+ end
125
+ it 'builds a latest url' do
126
+ client.latest_fitness
127
+ expect(a_get('/organizations/1/fitness/latest.json').with(query: { access_token: '1' })).to have_been_made
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,144 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::REST::Nutrition do
5
+ let(:client) { Validic::Client.new }
6
+
7
+ describe "#get_nutritions" do
8
+ context 'no user_id given' do
9
+ before do
10
+ stub_get("/organizations/1/nutrition.json")
11
+ .with(query: { access_token: '1' })
12
+ .to_return(body: fixture('nutritions.json'),
13
+ headers: { content_type: 'application/json; charset=utf-8' })
14
+ @nutrition = client.get_nutrition
15
+ end
16
+ it 'returns a validic response object' do
17
+ expect(@nutrition).to be_a Validic::Response
18
+ end
19
+ it 'makes a nutrition request to the correct url' do
20
+ expect(a_get('/organizations/1/nutrition.json')
21
+ .with(query: { access_token: '1' }))
22
+ .to have_been_made
23
+ end
24
+ end
25
+ context 'with user_id' do
26
+ before do
27
+ stub_get("/organizations/1/users/1/nutrition.json")
28
+ .with(query: { access_token: '1' })
29
+ .to_return(body: fixture('bulk_nutritions.json'),
30
+ headers: { content_type: 'application/json; charset=utf-8' })
31
+
32
+ @nutrition = client.get_nutrition(user_id: '1')
33
+ end
34
+ it 'returns a Response' do
35
+ expect(@nutrition).to be_a Validic::Response
36
+ end
37
+ it 'makes a nutrition request to the correct url' do
38
+ expect(a_get('/organizations/1/users/1/nutrition.json')
39
+ .with(query: { access_token: '1' }))
40
+ .to have_been_made
41
+ end
42
+ end
43
+ end
44
+
45
+ describe '#create_nutrition' do
46
+ context 'standard data'do
47
+ before do
48
+ stub_post("/organizations/1/users/1/nutrition.json")
49
+ .with(body: { nutrition: { timestamp: '2013-03-10T07:12:16+00:00',
50
+ activity_id: '12345' }, access_token: '1' }.to_json)
51
+ .to_return(body: fixture('nutrition.json'),
52
+ headers: { content_type: 'application/json; charset=utf-8'} )
53
+ end
54
+ it 'requests the correct resource' do
55
+ client.create_nutrition(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00',
56
+ activity_id: '12345')
57
+ expect(a_post('/organizations/1/users/1/nutrition.json')
58
+ .with(body: { nutrition: { timestamp: '2013-03-10T07:12:16+00:00',
59
+ activity_id: '12345' },
60
+ access_token: '1' }.to_json)).to have_been_made
61
+ end
62
+ it 'returns a Nutrition' do
63
+ nutrition = client.create_nutrition(user_id: '1', timestamp: '2013-03-10T07:12:16+00:00',
64
+ activity_id: '12345')
65
+ expect(nutrition).to be_a Validic::Nutrition
66
+ expect(nutrition.timestamp).to eq '2013-03-10T07:12:16+00:00'
67
+ end
68
+ end
69
+ end
70
+
71
+ describe "#update_nutrition" do
72
+ context 'standard data' do
73
+ before do
74
+ stub_put("/organizations/1/users/1/nutrition/51552cddfded0807c4000096.json")
75
+ .with(body: { nutrition: { timestamp: '2013-03-10T07:12:16+00:00' },
76
+ access_token: '1' }.to_json)
77
+ .to_return(body: fixture('nutrition.json'),
78
+ headers: {content_type: 'application/json; charset=utf-8'})
79
+ end
80
+ it 'makes a nutrition request to the correct url' do
81
+ client.update_nutrition(user_id: '1', _id: '51552cddfded0807c4000096',
82
+ timestamp: '2013-03-10T07:12:16+00:00')
83
+ expect(a_put('/organizations/1/users/1/nutrition/51552cddfded0807c4000096.json')
84
+ .with(body: { nutrition: { timestamp: '2013-03-10T07:12:16+00:00' },
85
+ access_token: '1' }.to_json)).to have_been_made
86
+ end
87
+ it 'returns a Nutrition' do
88
+ nutrition = client.update_nutrition(user_id: '1', _id: '51552cddfded0807c4000096',
89
+ timestamp: '2013-03-10T07:12:16+00:00')
90
+ expect(nutrition).to be_a Validic::Nutrition
91
+ end
92
+ end
93
+ end
94
+
95
+ describe '#delete_nutrition' do
96
+ context 'when resource is found' do
97
+ before do
98
+ stub_delete("/organizations/1/users/1/nutrition/51552cddfded0807c4000096.json")
99
+ .to_return(status: 200)
100
+ end
101
+ it 'returns true' do
102
+ nutrition = client.delete_nutrition(user_id: '1', _id: '51552cddfded0807c4000096')
103
+ expect(nutrition).to be true
104
+ end
105
+ end
106
+ end
107
+
108
+ describe '#latest_nutrition' do
109
+ context 'with user_id' do
110
+ before do
111
+ stub_get("/organizations/1/users/2/nutrition/latest.json").
112
+ with(query: { access_token: '1' }).
113
+ to_return(body: fixture('nutritions.json'),
114
+ headers: { content_type: 'application/json; charset=utf-8' })
115
+ end
116
+ it 'makes a latest for nutrition' do
117
+ latest = client.latest_nutrition(user_id: '2')
118
+ expect(latest).to be_a Validic::Response
119
+ end
120
+ it 'builds a latest url' do
121
+ client.latest_nutrition(user_id: '2')
122
+ expect(a_get('/organizations/1/users/2/nutrition/latest.json')
123
+ .with(query: { access_token: '1' })).to have_been_made
124
+ end
125
+ end
126
+ context 'without user_id' do
127
+ before do
128
+ stub_get("/organizations/1/nutrition/latest.json").
129
+ with(query: { access_token: '1' }).
130
+ to_return(body: fixture('nutritions.json'),
131
+ headers: { content_type: 'application/json; charset=utf-8' })
132
+ end
133
+ it 'makes a latest for nutrition' do
134
+ latest = client.latest_nutrition
135
+ expect(latest).to be_a Validic::Response
136
+ end
137
+ it 'builds a latest url' do
138
+ client.latest_nutrition
139
+ expect(a_get('/organizations/1/nutrition/latest.json')
140
+ .with(query: { access_token: '1' })).to have_been_made
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validic::REST::Organizations do
4
+ let(:client) { Validic::Client.new }
5
+
6
+ describe "#get_organization" do
7
+ before do
8
+ stub_get('/organizations/1.json')
9
+ .with(query: { access_token: '1' })
10
+ .to_return(body: fixture('organizations.json'),
11
+ headers: { content_type: 'application/json; charset=utf-8' })
12
+ @org = client.get_organization
13
+ end
14
+ it 'returns an organization object' do
15
+ expect(@org).to be_a Validic::Response
16
+ end
17
+ it 'creates the correct url' do
18
+ expect(a_get('/organizations/1.json')
19
+ .with(query: { access_token: '1' }))
20
+ .to have_been_made
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,44 @@
1
+ require 'spec_helper'
2
+
3
+ describe Validic::REST::Profile do
4
+ let(:client) { Validic::Client.new }
5
+
6
+ describe '#get_profile' do
7
+ before do
8
+ stub_get("/profile.json")
9
+ .with(query: { access_token: '1', authentication_token: '2' })
10
+ .to_return(body: fixture('profile.json'),
11
+ headers: { content_type: 'application/json; charset=utf-8' })
12
+
13
+ @profile = client.get_profile(authentication_token: '2')
14
+ end
15
+ it 'returns a validic profile object' do
16
+ expect(@profile).to be_a Validic::Profile
17
+ end
18
+ it 'builds the correct path for profile' do
19
+ expect(a_get('/profile.json')
20
+ .with(query: { access_token: '1', authentication_token: '2' }))
21
+ .to have_been_made
22
+ end
23
+ end
24
+
25
+ describe '#create_profile' do
26
+ before do
27
+ stub_post("/profile.json")
28
+ .with(
29
+ body: { authentication_token: '2', profile: { gender: "m", location: "NC" }, access_token: '1'}.to_json)
30
+ .to_return(body: fixture('profile.json'),
31
+ headers: { content_type: 'application/json; charset=utf-8' })
32
+ @profile = client.create_profile(authentication_token: '2', gender: 'm', location: 'NC')
33
+ end
34
+ it 'returns a validic profile object' do
35
+ expect(@profile).to be_a Validic::Profile
36
+ end
37
+ it 'builds the correct path for profile' do
38
+ expect(a_post('/profile.json')
39
+ .with(body: { authentication_token: '2',
40
+ profile: { gender: "m", location: "NC" }, access_token: '1'}
41
+ .to_json)).to have_been_made
42
+ end
43
+ end
44
+ end