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
@@ -1,97 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Validic
4
- module Biometric
5
-
6
- ##
7
- # Get GeneralMeasurement Activities base on `access_token`
8
- # Default data fetched is from yesterday
9
- #
10
- # @params :org_id - for organization specific
11
- # @params :user_id - for user specific
12
- #
13
- # @params :start_date - optional
14
- # @params :end_date - optional
15
- # @params :access_token - override for default access_token
16
- # @params :source - optional - data per source (e.g 'fitbit')
17
- # @params :expanded - optional - will show the raw data
18
- #
19
- # @return [Hashie::Mash] with list of GeneralMeasurement
20
- def get_biometrics(params={})
21
- params = extract_params(params)
22
- get_endpoint(:biometrics, params)
23
- end
24
-
25
- ##
26
- # Create GeneralMeasurement base on `access_token` and `authentication_token`
27
- #
28
- # @params :access_token - *required if not specified on your initializer / organization access_token
29
- # @params :authentication_token - *required / authentication_token of a specific user
30
- #
31
- # @params :blood_calcium
32
- # @params :blood_chromium
33
- # @params :blood_folic_acid
34
- # @params :blood_magnesium
35
- # @params :blood_potassium
36
- # @params :blood_sodium
37
- # @params :blood_vitamin_b12
38
- # @params :blood_zinc
39
- # @params :creatine_kinase
40
- # @params :crp
41
- # @params :diastolic
42
- # @params :ferritin
43
- # @params :hdl
44
- # @params :hscrp
45
- # @params :il6
46
- # @params :ldl
47
- # @params :resting_heartrate
48
- # @params :systolic
49
- # @params :testosterone
50
- # @params :total_cholesterol
51
- # @params :tsh
52
- # @params :uric_acid
53
- # @params :vitamin_d
54
- # @params :white_cell_count
55
- # @params :timestamp
56
- # @params :source
57
- #
58
- # @return success
59
- def create_biometric(options={})
60
- options = {
61
- access_token: options[:access_token],
62
- general_measurement: {
63
- blood_calcium: options[:blood_calcium],
64
- blood_chromium: options[:blood_chromium],
65
- blood_folic_acid: options[:blood_folic_acid],
66
- blood_magnesium: options[:blood_magnesium],
67
- blood_potassium: options[:blood_potassium],
68
- blood_sodium: options[:blood_sodium],
69
- blood_vitamin_b12: options[:blood_vitamin_b12],
70
- blood_zinc: options[:blood_zinc],
71
- creatine_kinase: options[:creatine_kinase],
72
- crp: options[:crp],
73
- diastolic: options[:diastolic],
74
- ferritin: options[:ferritin],
75
- hdl: options[:hdl],
76
- hscrp: options[:hscrp],
77
- il6: options[:il6],
78
- ldl: options[:ldl],
79
- resting_heartrate: options[:resting_heartrate],
80
- systolic: options[:systolic],
81
- testosterone: options[:testosterone],
82
- total_cholesterol: options[:total_cholesterol],
83
- tsh: options[:tsh],
84
- uric_acid: options[:uric_acid],
85
- vitamin_d: options[:vitamin_d],
86
- white_cell_count: options[:white_cell_count],
87
- timestamp: options[:timestamp],
88
- source: options[:source]
89
- }
90
- }
91
-
92
- response = post("/#{Validic.api_version}/biometrics.json", options)
93
- response if response
94
- end
95
-
96
- end
97
- end
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
- require 'active_support/core_ext'
3
- require 'multi_json'
4
-
5
- module Validic
6
- module Request
7
-
8
- def extract_params(params)
9
- Validic.organization_id = params.delete(:organization_id) if params[:organization_id]
10
- Validic.user_id = params.delete(:user_id) if params[:user_id]
11
- params
12
- end
13
-
14
- def get(path, options)
15
- request(:get, path, options)
16
- end
17
-
18
- def post(path, options)
19
- request(:post, path, options)
20
- end
21
-
22
- def put(path, options)
23
- request(:put, path, options)
24
- end
25
-
26
- def delete(path, options)
27
- request(:delete, path, options)
28
- end
29
-
30
- def request(method, path, options)
31
- options[:access_token] = options[:access_token].nil? ? Validic.access_token : options[:access_token]
32
- response = connection.send(method) do |request|
33
- case method
34
- when :get, :delete
35
- request.url(path, options)
36
- when :post, :put
37
- request.path = path
38
- request.body = MultiJson.encode(options) unless options.empty?
39
- end
40
- end
41
-
42
- response.body
43
- end
44
-
45
- end
46
- end
@@ -1,32 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Validic
4
- module ThirdPartyApp
5
-
6
- ##
7
- # Get List of Third Party Apps available base on `access_token` and organization_id
8
- #
9
- # params[:organization_id] required parameter
10
- # params[:access_token] required parameter
11
- #
12
- # @return [Hashie::Mash] with list of Organization
13
- def get_apps(params={})
14
- params = extract_params(params)
15
- get_endpoint(:apps, params)
16
- end
17
-
18
- ##
19
- # Get User List of Third Party Synced Apps available base on `authentication_token`
20
- #
21
- # params[:auth_token] User authentication parameter
22
- #
23
- # @return [Hashie::Mash] with list of Organization
24
- def get_synced_apps(options={})
25
- options = {
26
- authentication_token: options[:authentication_token]
27
- }
28
- response = get("/#{Validic.api_version}/sync_apps.json", options)
29
- response if response
30
- end
31
- end
32
- end
@@ -1,43 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Validic::Biometric do
5
-
6
- let(:client) { Validic::Client.new }
7
-
8
- context "#get_biometrics" do
9
- before do
10
- @user_biometrics = client
11
- .get_biometrics({
12
- start_date: '2014-01-01',
13
- user_id: ENV['TEST_USER_ID']
14
- })
15
- end
16
-
17
- it "returns JSON response of Validic::Biometrics", vcr: true do
18
- @user_biometrics.should_not be_nil
19
- end
20
-
21
- it "status 200" do
22
- @user_biometrics.summary.status.should == 200
23
- end
24
-
25
- context "#summary response" do
26
- it "not nil" do
27
- @user_biometrics.summary.should_not be_nil
28
- end
29
-
30
- it "results not 0" do
31
- @user_biometrics.summary.results.should_not == 0
32
- end
33
- end
34
-
35
- context "#biometrics collection" do
36
- it "has a collection" do
37
- @user_biometrics.biometrics.should be_a(Array)
38
- end
39
- end
40
-
41
- end
42
-
43
- end
@@ -1,89 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Validic::Diabetes do
5
-
6
- let(:client) { Validic::Client.new }
7
-
8
- context "#get_diabetes" do
9
- before do
10
- @user_diabetes = client.get_diabetes({})
11
- end
12
-
13
- it "returns JSON response of Validic::Diabetes", vcr: true do
14
- @user_diabetes.should_not be_nil
15
- end
16
-
17
- it "status 200" do
18
- @user_diabetes.summary.status.should == 200
19
- end
20
-
21
- it "has summary node" do
22
- @user_diabetes.summary.should_not be_nil
23
- end
24
- end
25
-
26
- context "#create_diabetes" do
27
- it "should create new diabetes record", vcr: true do
28
- pending
29
- @new_diabetes = client.create_diabetes({authentication_token: ENV['TEST_USER_AUTHENTICATION_TOKEN'],
30
- access_token: "DEMO_KEY",
31
- c_peptide: 1,
32
- fasting_plasma_glucose_test: 50,
33
- hba1c: 100,
34
- insulin: 350,
35
- oral_glucose_tolerance_test: 100,
36
- random_plasma_glucose_test: 200,
37
- triglyceride: 100,
38
- timestamp: "2013-05-16 07:12:16 -05:00",
39
- source: "Sample App"})
40
- @new_diabetes.should_not be_nil
41
- @new_diabetes.diabetes.timestamp.should eq "2013-05-16 07:12:16 -05:00"
42
- @new_diabetes.diabetes.c_peptide.should eq 1.0
43
- @new_diabetes.diabetes.fasting_plasma_glucose_test.should eq 50.0
44
- @new_diabetes.diabetes.hba1c.should eq 100.0
45
- @new_diabetes.diabetes.insulin.should eq 350.0
46
- @new_diabetes.diabetes.oral_glucose_tolerance_test.should eq 100.0
47
- @new_diabetes.diabetes.random_plasma_glucose_test.should eq 200.0
48
- @new_diabetes.diabetes.triglyceride 100.0
49
- @new_diabetes.diabetes.source.should eq "Sample App"
50
- end
51
- end
52
-
53
- context "#get_diabetes by organization" do
54
- before do
55
- @org_diabetes = client.get_diabetes({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
56
- end
57
-
58
- it "returns JSON response of Validic::Diabetes", vcr: true do
59
- @org_diabetes.should_not be_nil
60
- end
61
-
62
- it "status 200" do
63
- @org_diabetes.summary.status.should == 200
64
- end
65
-
66
- it "has summary node" do
67
- @org_diabetes.summary.should_not be_nil
68
- end
69
- end
70
-
71
- context "#get_diabetes by user" do
72
- before do
73
- @user_diabetes = client.get_diabetes({user_id: ENV['TEST_USER_ID']})
74
- end
75
-
76
- it "returns JSON response of Validic::Diabetes", vcr: true do
77
- @user_diabetes.should_not be_nil
78
- end
79
-
80
- it "status 200" do
81
- @user_diabetes.summary.status.should == 200
82
- end
83
-
84
- it "has summary node" do
85
- @user_diabetes.summary.should_not be_nil
86
- end
87
- end
88
-
89
- end
@@ -1,85 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Validic::Fitness do
5
-
6
- let(:client) { Validic::Client.new }
7
-
8
- context "#get_fitnesses" do
9
- before do
10
- @fitness = client.get_fitnesses({})
11
- end
12
-
13
- it "returns JSON response of Validic::Fitness", vcr: true do
14
- @fitness.should_not be_nil
15
- end
16
-
17
- it "status 200" do
18
- @fitness.summary.status.should == 200
19
- end
20
-
21
- it "has summary node" do
22
- @fitness.summary.should_not be_nil
23
- end
24
- end
25
-
26
- context "#create_fitness" do
27
- it "should create new fitness record" do
28
- pending
29
- @new_fitness = client.create_fitness({authentication_token: ENV['TEST_USER_AUTHENTICATION_TOKEN'],
30
- access_token: "DEMO_KEY",
31
- timestamp: "2013-03-10 07:12:16 -05:00",
32
- primary_type: "Running",
33
- intensity: "medium",
34
- start_time: "2013-03-09 13:55:36 -05:00",
35
- total_distance: 5149.9,
36
- duration: 1959.90,
37
- source: "Sample App"})
38
-
39
- @new_fitness.fitness.timestamp.should eq "2013-03-10 07:12:16 -05:00"
40
- @new_fitness.fitness.type.should eq "Running"
41
- @new_fitness.fitness.intensity.should eq "medium"
42
- @new_fitness.fitness.start_time.should eq "2013-03-09 13:55:36 -05:00"
43
- @new_fitness.fitness.total_distance.should eq 5149.9
44
- @new_fitness.fitness.duration.should eq 1959.90
45
- @new_fitness.fitness.source.should eq "Sample App"
46
- end
47
- end
48
-
49
- context "#get_fitnesses by organization" do
50
- before do
51
- @fitness = client.get_fitnesses({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
52
- end
53
-
54
- it "returns JSON response of Validic::Fitness", vcr: true do
55
- @fitness.should_not be_nil
56
- end
57
-
58
- it "status 200" do
59
- @fitness.summary.status.should == 200
60
- end
61
-
62
- it "has summary node" do
63
- @fitness.summary.should_not be_nil
64
- end
65
- end
66
-
67
- context "#get_fitnesses by user" do
68
- before do
69
- @fitness = client.get_fitnesses({user_id: ENV['TEST_USER_ID']})
70
- end
71
-
72
- it "returns JSON response of Validic::Fitness", vcr: true do
73
- @fitness.should_not be_nil
74
- end
75
-
76
- it "status 200" do
77
- @fitness.summary.status.should == 200
78
- end
79
-
80
- it "has summary node" do
81
- @fitness.summary.should_not be_nil
82
- end
83
- end
84
-
85
- end
@@ -1,91 +0,0 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
-
4
- describe Validic::Nutrition do
5
-
6
- let(:client) { Validic::Client.new }
7
-
8
- context "#get_nutritions" do
9
- before do
10
- @nutrition = client.get_nutritions({})
11
- end
12
-
13
- it "returns JSON response of Validic::Nutrition", vcr: true do
14
- @nutrition.should_not be_nil
15
- end
16
-
17
- it "status 200" do
18
- @nutrition.summary.status.should == 200
19
- end
20
-
21
- it "has summary node" do
22
- @nutrition.summary.should_not be_nil
23
- end
24
- end
25
-
26
- context "#create_nutrition" do
27
- it "should create new nutrition record" do
28
- pending
29
- @new_nutrition = client.create_nutrition({authentication_token: ENV['TEST_USER_AUTHENTICATION_TOKEN'],
30
- access_token: "DEMO_KEY",
31
- calories: 850,
32
- carbohydrates: 351,
33
- fat: 52,
34
- fiber: 35,
35
- protein: 54,
36
- sodium: 855,
37
- water: 36,
38
- timestamp: "2013-05-16 07:12:16 -05:00",
39
- meal: "Dinner",
40
- source: "Sample App"})
41
- @new_nutrition.should_not be_nil
42
- @new_nutrition.nutrition.timestamp.should eq "2013-05-16 07:12:16 -05:00"
43
- @new_nutrition.nutrition.calories.should eq 850.0
44
- @new_nutrition.nutrition.carbohydrates.should eq 351.0
45
- @new_nutrition.nutrition.fat.should eq 52.0
46
- @new_nutrition.nutrition.fiber.should eq 35.0
47
- @new_nutrition.nutrition.protein.should eq 54.0
48
- @new_nutrition.nutrition.sodium.should eq 855.0
49
- @new_nutrition.nutrition.water.should eq 36.0
50
- @new_nutrition.nutrition.meal.should eq "Dinner"
51
- @new_nutrition.nutrition.source.should eq "Sample App"
52
- end
53
- end
54
-
55
- context "#get_nutritions by organization" do
56
- before do
57
- @nutrition = client.get_nutritions({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
58
- end
59
-
60
- it "returns JSON response of Validic::Nutrition", vcr: true do
61
- @nutrition.should_not be_nil
62
- end
63
-
64
- it "status 200" do
65
- @nutrition.summary.status.should == 200
66
- end
67
-
68
- it "has summary node" do
69
- @nutrition.summary.should_not be_nil
70
- end
71
- end
72
-
73
- context "#get_nutritions by user" do
74
- before do
75
- @nutrition = client.get_nutritions({user_id: ENV['TEST_USER_ID']})
76
- end
77
-
78
- it "returns JSON response of Validic::Nutrition", vcr: true do
79
- @nutrition.should_not be_nil
80
- end
81
-
82
- it "status 200" do
83
- @nutrition.summary.status.should == 200
84
- end
85
-
86
- it "has summary node" do
87
- @nutrition.summary.should_not be_nil
88
- end
89
- end
90
-
91
- end