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,13 @@
1
+ require 'validic/extra'
2
+ module Validic
3
+ module Utils
4
+ def attributes_builder(attrs, obj)
5
+ attrs.each do |k, v|
6
+ v = Validic::Extra.new(v) if k == "extras" && !v.nil?
7
+ v = Validic::Profile.new(v) if k == "profile" && !v.nil?
8
+ instance_variable_set("@#{k}", v)
9
+ obj.class.send(:attr_reader, k)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,3 @@
1
1
  module Validic
2
- VERSION = "0.3.3"
2
+ VERSION = '0.4.1'
3
3
  end
@@ -1,61 +1,8 @@
1
- # encoding: utf-8
2
-
3
1
  module Validic
4
- module Weight
5
-
6
- ##
7
- # Get Weight Activities base on `access_token`
8
- # Default data fetched is from yesterday
9
- #
10
- # @params :organization_id - for organization specific
11
- # @params :user_id - for user specific
12
- #
13
- # @params :start_date - optional for date range beyond yesterday
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 Weight
20
- def get_weight(params={})
21
- params = extract_params(params)
22
- get_endpoint(:weight, params)
2
+ class Weight
3
+ include Validic::Utils
4
+ def initialize(attrs = {})
5
+ attributes_builder(attrs, self)
23
6
  end
24
-
25
- alias :get_weights :get_weight
26
-
27
- ##
28
- # Create Weight base on `access_token` and `authentication_token`
29
- #
30
- # @params :access_token - *required if not specified on your initializer / organization access_token
31
- # @params :authentication_token - *required / authentication_token of a specific user
32
- #
33
- # @params :timestamp
34
- # @params :weight
35
- # @params :bmi
36
- # @params :fat_percent
37
- # @params :mass_weight
38
- # @params :free_mass
39
- # @params :source
40
- #
41
- # @return success
42
- def create_weight(options={})
43
- options = {
44
- access_token: options[:access_token],
45
- weight: {
46
- timestamp: options[:timestamp],
47
- weight: options[:weight],
48
- bmi: options[:bmi],
49
- fat_percent: options[:fat_percent],
50
- mass_weight: options[:mass_weight],
51
- free_mass: options[:free_mass],
52
- source: options[:source]
53
- }
54
- }
55
-
56
- response = post("/#{Validic.api_version}/weight.json", options)
57
- response if response
58
- end
59
-
60
7
  end
61
8
  end
@@ -0,0 +1,32 @@
1
+ {"summary":
2
+ {"status":200,
3
+ "message":"Ok",
4
+ "results":1,
5
+ "start_date":"2015-01-13T00:00:00+00:00",
6
+ "end_date":"2015-01-15T23:59:59+00:00",
7
+ "offset":0,
8
+ "limit":null,
9
+ "previous":null,
10
+ "next":null,
11
+ "params":{"start_date":null,
12
+ "end_date":null,
13
+ "offset":0,
14
+ "limit":0
15
+ }
16
+ },
17
+ "apps": [
18
+ {"name":"Healthy Yet",
19
+ "sync_url":"https://app.validic.com/organizations/549826e48ee42168f1000045/auth/healthy_yet?user_token=Z7CL7JtMgwmtNXcoza6j&format_redirect=json",
20
+ "unsync_url":"",
21
+ "refresh_url":"",
22
+ "download_link":"",
23
+ "excerpt":"Healthy Yet app",
24
+ "extra_excerpt":"Healthy Yet app",
25
+ "subname":"healthy_yet",
26
+ "kind":null,
27
+ "logo_url":"https://s3.amazonaws.com/healthyyet/healthyyet-logo-blue.png",
28
+ "platform_types":null,
29
+ "synced":false,
30
+ "last_sync":null}
31
+ ]
32
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "summary": {
3
+ "status": 200,
4
+ "message": "Ok",
5
+ "results": 1,
6
+ "start_date": "2015-01-14T00:00:00+00:00",
7
+ "end_date": "2015-01-16T23: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": 0,
16
+ "limit": 0
17
+ }
18
+ },
19
+ "biometrics": [
20
+ {
21
+ "_id": "54b670e07b361fb5c7000353",
22
+ "timestamp": "2015-01-14T13:22:55+00:00",
23
+ "utc_offset": "+00:00",
24
+ "blood_calcium": null,
25
+ "blood_chromium": null,
26
+ "blood_folic_acid": null,
27
+ "blood_magnesium": null,
28
+ "blood_potassium": null,
29
+ "blood_sodium": null,
30
+ "blood_vitamin_b12": null,
31
+ "blood_zinc": null,
32
+ "creatine_kinase": null,
33
+ "crp": null,
34
+ "diastolic": 58,
35
+ "ferritin": null,
36
+ "hdl": null,
37
+ "hscrp": null,
38
+ "il6": null,
39
+ "ldl": null,
40
+ "resting_heartrate": 88,
41
+ "systolic": 118,
42
+ "testosterone": null,
43
+ "total_cholesterol": null,
44
+ "tsh": null,
45
+ "uric_acid": null,
46
+ "vitamin_d": null,
47
+ "white_cell_count": null,
48
+ "spo2": null,
49
+ "temperature": null,
50
+ "source": "vitadock",
51
+ "source_name": "Vitadock",
52
+ "last_updated": "2015-01-14T13:36:32+00:00",
53
+ "user_id": "52ffcb4bf1f70eefba000004"
54
+ }
55
+ ]
56
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "biometrics": {
3
+ "timestamp": "2013-03-10T07:12:16+00:00",
4
+ "utc_offset": "+00:00",
5
+ "blood_calcium": 9.2,
6
+ "blood_chromium": 1.32,
7
+ "blood_folic_acid": 8.1,
8
+ "blood_magnesium": 1.89,
9
+ "blood_potassium": 3.9,
10
+ "blood_sodium": 137.8,
11
+ "blood_vitamin_b12": 612,
12
+ "blood_zinc": 93,
13
+ "creatine_kinase": 87,
14
+ "crp": 0,
15
+ "diastolic": 73,
16
+ "ferritin": 189,
17
+ "hdl": 44,
18
+ "hscrp": 0.3,
19
+ "il6": 6.4,
20
+ "ldl": 156,
21
+ "resting_heartrate": 74,
22
+ "systolic": 122,
23
+ "testosterone": 457,
24
+ "total_cholesterol": 208,
25
+ "tsh": 0.6,
26
+ "uric_acid": 4.2,
27
+ "vitamin_d": 54.8,
28
+ "white_cell_count": 7453,
29
+ "spo2": 96,
30
+ "temperature": 37,
31
+ "data_id": "12345",
32
+ "extras": {"stars": 3}
33
+ },
34
+ "access_token": "e7ba1f04e88f25d399a91c8cbcd72300e01309e96b7725e40b49cd1effaa5deb"
35
+ }
@@ -0,0 +1,36 @@
1
+ {
2
+ "biometrics": {
3
+ "_id": "51552cdcfded0807c4000075",
4
+ "timestamp": "2013-03-10T07:12:16+00:00",
5
+ "utc_offset": "+00:00",
6
+ "blood_calcium": 9.2,
7
+ "blood_chromium": 1.32,
8
+ "blood_folic_acid": 8.1,
9
+ "blood_magnesium": 1.89,
10
+ "blood_potassium": 3.9,
11
+ "blood_sodium": 137.8,
12
+ "blood_vitamin_b12": 612,
13
+ "blood_zinc": 93,
14
+ "creatine_kinase": 87,
15
+ "crp": 0,
16
+ "diastolic": 73,
17
+ "ferritin": 189,
18
+ "hdl": 44,
19
+ "hscrp": 0.3,
20
+ "il6": 6.4,
21
+ "ldl": 156,
22
+ "resting_heartrate": 74,
23
+ "systolic": 122,
24
+ "testosterone": 457,
25
+ "total_cholesterol": 208,
26
+ "tsh": 0.6,
27
+ "uric_acid": 4.2,
28
+ "vitamin_d": 54.8,
29
+ "white_cell_count": 7453,
30
+ "spo2": 96,
31
+ "temperature": 37,
32
+ "source": "sample_app",
33
+ "source_name": "Sample App",
34
+ "last_updated": "2013-03-10T07:12:16+00:00"
35
+ }
36
+ }
@@ -0,0 +1,54 @@
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
+ }, "biometrics": [
19
+ {
20
+ "_id": "51552cdcfded0807c4000075",
21
+ "timestamp": "2013-03-10T07:12:16+00:00",
22
+ "utc_offset": "+00:00",
23
+ "blood_calcium": 9.2,
24
+ "blood_chromium": 1.32,
25
+ "blood_folic_acid": 8.1,
26
+ "blood_magnesium": 1.89,
27
+ "blood_potassium": 3.9,
28
+ "blood_sodium": 137.8,
29
+ "blood_vitamin_b12": 612,
30
+ "blood_zinc": 93,
31
+ "creatine_kinase": 87,
32
+ "crp": 0,
33
+ "diastolic": 73,
34
+ "ferritin": 189,
35
+ "hdl": 44,
36
+ "hscrp": 0.3,
37
+ "il6": 6.4,
38
+ "ldl": 156,
39
+ "resting_heartrate": 74,
40
+ "systolic": 122,
41
+ "testosterone": 457,
42
+ "total_cholesterol": 208,
43
+ "tsh": 0.6,
44
+ "uric_acid": 4.2,
45
+ "vitamin_d": 54.8,
46
+ "white_cell_count": 7453,
47
+ "spo2": 96,
48
+ "temperature": 37,
49
+ "source": "sample_app",
50
+ "source_name": "Sample App",
51
+ "last_updated": "2013-03-10T07:12:16+00:00"
52
+ }
53
+ ]
54
+ }
@@ -0,0 +1,55 @@
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
+ }, "biometrics": [
19
+ {
20
+ "_id": "51552cdcfded0807c4000075",
21
+ "timestamp": "2013-03-10T07:12:16+00:00",
22
+ "utc_offset": "+00:00",
23
+ "blood_calcium": 9.2,
24
+ "blood_chromium": 1.32,
25
+ "blood_folic_acid": 8.1,
26
+ "blood_magnesium": 1.89,
27
+ "blood_potassium": 3.9,
28
+ "blood_sodium": 137.8,
29
+ "blood_vitamin_b12": 612,
30
+ "blood_zinc": 93,
31
+ "creatine_kinase": 87,
32
+ "crp": 0,
33
+ "diastolic": 73,
34
+ "ferritin": 189,
35
+ "hdl": 44,
36
+ "hscrp": 0.3,
37
+ "il6": 6.4,
38
+ "ldl": 156,
39
+ "resting_heartrate": 74,
40
+ "systolic": 122,
41
+ "testosterone": 457,
42
+ "total_cholesterol": 208,
43
+ "tsh": 0.6,
44
+ "uric_acid": 4.2,
45
+ "vitamin_d": 54.8,
46
+ "white_cell_count": 7453,
47
+ "spo2": 96,
48
+ "temperature": 37,
49
+ "source": "sample_app",
50
+ "source_name": "Sample App",
51
+ "last_updated": "2013-03-10T07:12:16+00:00",
52
+ "user_id": "51552cd7fded0807c4000017"
53
+ }
54
+ ]
55
+ }
@@ -0,0 +1,37 @@
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
+ }, "diabetes": [
19
+ {
20
+ "_id": "51552cd6fded0807c4000007",
21
+ "timestamp": "2013-03-10T07:12:16+00:00",
22
+ "utc_offset": "+00:00",
23
+ "c_peptide": 0.6,
24
+ "fasting_plasma_glucose_test": 95,
25
+ "hba1c": 4.8,
26
+ "insulin": 460,
27
+ "oral_glucose_tolerance_test": 137,
28
+ "random_plasma_glucose_test": 256,
29
+ "triglyceride": 128,
30
+ "blood_glucose": 120,
31
+ "source": "sample_app",
32
+ "source_name": "Sample App",
33
+ "last_updated": "2013-03-10T07:12:16+00:00",
34
+ "user_id": "51552cd7fded0807c4000017"
35
+ }
36
+ ]
37
+ }
@@ -0,0 +1,35 @@
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
+ }, "fitness": [
19
+ {
20
+ "_id": "51552cd7fded0807c400001f",
21
+ "timestamp": "2013-03-10T07:12:16+00:00",
22
+ "utc_offset": "+00:00",
23
+ "type": "Walking",
24
+ "intensity": "low",
25
+ "start_time": "2013-03-10T07:12:16+00:00",
26
+ "distance": 2600,
27
+ "duration": 2460,
28
+ "calories": 350,
29
+ "source": "sample_app",
30
+ "source_name": "Sample App",
31
+ "last_updated": "2013-03-10T07:12:16+00:00",
32
+ "user_id": "51552cd7fded0807c4000017"
33
+ }
34
+ ]
35
+ }
@@ -0,0 +1,37 @@
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
+ }, "nutrition": [
19
+ {
20
+ "_id": "51552cd9fded0807c4000043",
21
+ "timestamp": "2013-03-10T07:12:16+00:00",
22
+ "utc_offset": "+00:00",
23
+ "calories": 865,
24
+ "carbohydrates": 121,
25
+ "fat": 31,
26
+ "fiber": 9,
27
+ "protein": 21,
28
+ "sodium": 1129,
29
+ "water": 14,
30
+ "meal": "lunch",
31
+ "source": "sample_app",
32
+ "source_name": "Sample App",
33
+ "last_updated": "2013-03-10T07:12:16+00:00",
34
+ "user_id": "51552cd7fded0807c4000017"
35
+ }
36
+ ]
37
+ }