validic 0.2.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 (43) hide show
  1. data/.gitignore +18 -0
  2. data/.rspec +3 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +80 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +61 -0
  7. data/Rakefile +7 -0
  8. data/lib/validic.rb +32 -0
  9. data/lib/validic/activity.rb +73 -0
  10. data/lib/validic/client.rb +74 -0
  11. data/lib/validic/diabetes.rb +81 -0
  12. data/lib/validic/fitness.rb +75 -0
  13. data/lib/validic/general_measurement.rb +113 -0
  14. data/lib/validic/nutrition.rb +81 -0
  15. data/lib/validic/organization.rb +46 -0
  16. data/lib/validic/profile.rb +43 -0
  17. data/lib/validic/request.rb +36 -0
  18. data/lib/validic/routine.rb +73 -0
  19. data/lib/validic/sleep.rb +77 -0
  20. data/lib/validic/third_party_app.rb +37 -0
  21. data/lib/validic/tobacco_cessation.rb +73 -0
  22. data/lib/validic/user.rb +71 -0
  23. data/lib/validic/version.rb +3 -0
  24. data/lib/validic/weight.rb +74 -0
  25. data/spec/.DS_Store +0 -0
  26. data/spec/spec_helper.rb +43 -0
  27. data/spec/validic/activity_spec.rb +97 -0
  28. data/spec/validic/client_spec.rb +11 -0
  29. data/spec/validic/diabetes_spec.rb +88 -0
  30. data/spec/validic/fitness_spec.rb +84 -0
  31. data/spec/validic/general_measurement_spec.rb +120 -0
  32. data/spec/validic/nutrition_spec.rb +90 -0
  33. data/spec/validic/organization_spec.rb +46 -0
  34. data/spec/validic/profile_spec.rb +46 -0
  35. data/spec/validic/routine_spec.rb +81 -0
  36. data/spec/validic/sleep_spec.rb +85 -0
  37. data/spec/validic/third_party_app_spec.rb +32 -0
  38. data/spec/validic/tobacco_cessation_spec.rb +80 -0
  39. data/spec/validic/user_spec.rb +49 -0
  40. data/spec/validic/weight_spec.rb +87 -0
  41. data/spec/validic_spec.rb +38 -0
  42. data/validic.gemspec +37 -0
  43. metadata +353 -0
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Fitness
5
+
6
+ ##
7
+ # Get Fitness 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
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 Fitness
20
+ def get_fitnesses(options={})
21
+ organization_id = options[:organization_id]
22
+ user_id = options[:user_id]
23
+ options = {
24
+ start_date: options[:start_date],
25
+ end_date: options[:end_date],
26
+ access_token: options[:access_token],
27
+ source: options[:source],
28
+ expanded: options[:expanded]
29
+ }
30
+
31
+ if options[:access_token] && organization_id
32
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/fitness.json", options)
33
+ elsif user_id
34
+ response = get("/#{Validic.api_version}/users/#{user_id}/fitness.json", options)
35
+ else
36
+ response = get("/#{Validic.api_version}/fitness.json", options)
37
+ end
38
+ response if response
39
+ end
40
+
41
+ ##
42
+ # Create Fitness base on `access_token` and `authentication_token`
43
+ #
44
+ # @params :access_token - *required if not specified on your initializer / organization access_token
45
+ # @params :authentication_token - *required / authentication_token of a specific user
46
+ #
47
+ # @params :timestamp
48
+ # @params :primary_type
49
+ # @params :intensity
50
+ # @params :start_time
51
+ # @params :total_distance
52
+ # @params :duration
53
+ # @params :source
54
+ #
55
+ # @return success
56
+ def create_fitness(options={})
57
+ options = {
58
+ access_token: options[:access_token],
59
+ fitness: {
60
+ timestamp: options[:timestamp],
61
+ primary_type: options[:primary_type],
62
+ intensity: options[:intensity],
63
+ start_time: options[:start_time],
64
+ total_distance: options[:total_distance],
65
+ duration: options[:duration],
66
+ source: options[:source]
67
+ }
68
+ }
69
+
70
+ response = post("/#{Validic.api_version}/fitness.json", options)
71
+ response if response
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,113 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module GeneralMeasurement
5
+
6
+ ##
7
+ # Get GeneralMeasurement 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
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_general_measurements(options={})
21
+ organization_id = options[:organization_id]
22
+ user_id = options[:user_id]
23
+ options = {
24
+ start_date: options[:start_date],
25
+ end_date: options[:end_date],
26
+ access_token: options[:access_token],
27
+ source: options[:source],
28
+ expanded: options[:expanded]
29
+ }
30
+
31
+ if organization_id
32
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/biometrics.json", options)
33
+ elsif user_id
34
+ response = get("/#{Validic.api_version}/users/#{user_id}/biometrics.json", options)
35
+ else
36
+ response = get("/#{Validic.api_version}/biometrics.json", options)
37
+ end
38
+ response if response
39
+ end
40
+
41
+ ##
42
+ # Create GeneralMeasurement base on `access_token` and `authentication_token`
43
+ #
44
+ # @params :access_token - *required if not specified on your initializer / organization access_token
45
+ # @params :authentication_token - *required / authentication_token of a specific user
46
+ #
47
+ # @params :blood_calcium
48
+ # @params :blood_chromium
49
+ # @params :blood_folic_acid
50
+ # @params :blood_magnesium
51
+ # @params :blood_potassium
52
+ # @params :blood_sodium
53
+ # @params :blood_vitamin_b12
54
+ # @params :blood_zinc
55
+ # @params :creatine_kinase
56
+ # @params :crp
57
+ # @params :diastolic
58
+ # @params :ferritin
59
+ # @params :hdl
60
+ # @params :hscrp
61
+ # @params :il6
62
+ # @params :ldl
63
+ # @params :resting_heartrate
64
+ # @params :systolic
65
+ # @params :testosterone
66
+ # @params :total_cholesterol
67
+ # @params :tsh
68
+ # @params :uric_acid
69
+ # @params :vitamin_d
70
+ # @params :white_cell_count
71
+ # @params :timestamp
72
+ # @params :source
73
+ #
74
+ # @return success
75
+ def create_general_measurement(options={})
76
+ options = {
77
+ access_token: options[:access_token],
78
+ general_measurement: {
79
+ blood_calcium: options[:blood_calcium],
80
+ blood_chromium: options[:blood_chromium],
81
+ blood_folic_acid: options[:blood_folic_acid],
82
+ blood_magnesium: options[:blood_magnesium],
83
+ blood_potassium: options[:blood_potassium],
84
+ blood_sodium: options[:blood_sodium],
85
+ blood_vitamin_b12: options[:blood_vitamin_b12],
86
+ blood_zinc: options[:blood_zinc],
87
+ creatine_kinase: options[:creatine_kinase],
88
+ crp: options[:crp],
89
+ diastolic: options[:diastolic],
90
+ ferritin: options[:ferritin],
91
+ hdl: options[:hdl],
92
+ hscrp: options[:hscrp],
93
+ il6: options[:il6],
94
+ ldl: options[:ldl],
95
+ resting_heartrate: options[:resting_heartrate],
96
+ systolic: options[:systolic],
97
+ testosterone: options[:testosterone],
98
+ total_cholesterol: options[:total_cholesterol],
99
+ tsh: options[:tsh],
100
+ uric_acid: options[:uric_acid],
101
+ vitamin_d: options[:vitamin_d],
102
+ white_cell_count: options[:white_cell_count],
103
+ timestamp: options[:timestamp],
104
+ source: options[:source]
105
+ }
106
+ }
107
+
108
+ response = post("/#{Validic.api_version}/biometrics.json", options)
109
+ response if response
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Nutrition
5
+
6
+ ##
7
+ # Get Nutrition 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
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 Nutrition
20
+ def get_nutritions(options={})
21
+ organization_id = options[:organization_id]
22
+ user_id = options[:user_id]
23
+ options = {
24
+ start_date: options[:start_date],
25
+ end_date: options[:end_date],
26
+ access_token: options[:access_token],
27
+ source: options[:source],
28
+ expanded: options[:expanded]
29
+ }
30
+
31
+ if organization_id
32
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/nutrition.json", options)
33
+ elsif user_id
34
+ response = get("/#{Validic.api_version}/users/#{user_id}/nutrition.json", options)
35
+ else
36
+ response = get("/#{Validic.api_version}/nutrition.json", options)
37
+ end
38
+ response if response
39
+ end
40
+
41
+ ##
42
+ # Create Nutrition base on `access_token` and `authentication_token`
43
+ #
44
+ # @params :access_token - *required if not specified on your initializer / organization access_token
45
+ # @params :authentication_token - *required / authentication_token of a specific user
46
+ #
47
+ # @params :calories
48
+ # @params :carbohydrates
49
+ # @params :fat
50
+ # @params :fiber
51
+ # @params :protein
52
+ # @params :sodium
53
+ # @params :water
54
+ # @params :timestamp
55
+ # @params :meal
56
+ # @params :source
57
+ #
58
+ # @return success
59
+ def create_nutrition(options={})
60
+ options = {
61
+ access_token: options[:access_token],
62
+ nutrition: {
63
+ calories: options[:calories],
64
+ carbohydrates: options[:carbohydrates],
65
+ fat: options[:fat],
66
+ fiber: options[:fiber],
67
+ protein: options[:protein],
68
+ sodium: options[:sodium],
69
+ water: options[:water],
70
+ timestamp: options[:timestamp],
71
+ meal: options[:meal],
72
+ source: options[:source]
73
+ }
74
+ }
75
+
76
+ response = post("/#{Validic.api_version}/nutrition.json", options)
77
+ response if response
78
+ end
79
+
80
+ end
81
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Organization
5
+
6
+ ##
7
+ # Get Organization base on `access_token` and organization_id
8
+ #
9
+ # @params :access_token
10
+ # @return [Hashie::Mash] with list of Organization
11
+ def get_organization(options={})
12
+ organization_id = options[:organization_id]
13
+ options = {
14
+ access_token: options[:access_token]
15
+ }
16
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}.json", options)
17
+ response if response
18
+ end
19
+
20
+ ##
21
+ # Get Users base on `access_token` and organization_id
22
+ #
23
+ # @params :status - optional (active or inactive) default :all
24
+ # @params :access_token - optional
25
+ # @params :start_date - optional
26
+ # @params :end_date - optional
27
+ # @params :offset - optional
28
+ # @params :limit - optional
29
+ #
30
+ # @return [Hashie::Mash] with list of Organization
31
+ def get_users(options={})
32
+ organization_id = options[:organization_id]
33
+ options = {
34
+ access_token: options[:access_token],
35
+ start_data: options[:start_date],
36
+ end_date: options[:end_date],
37
+ offset: options[:offset],
38
+ limit: options[:limit],
39
+ status: options[:status]
40
+ }
41
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/users.json", options)
42
+ response if response
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Profile
5
+
6
+ ##
7
+ # Get Profile base on `access_token`
8
+ #
9
+ # @params :access_token - override for default access_token
10
+ # @return [Hashie::Mash] with list of Profile
11
+ def get_profile(options={})
12
+ options = {
13
+ access_token: options[:access_token]
14
+ }
15
+ response = get("/#{Validic.api_version}/profile.json", options)
16
+ response if response
17
+ end
18
+
19
+ ##
20
+ # Update Profile base on `access_token`
21
+ #
22
+ # @return success
23
+ # def update_profile(options={})
24
+ # options = {
25
+ # profile: {
26
+ # gender: options[:gender],
27
+ # location: options[:location],
28
+ # birth_year: options[:birth_year],
29
+ # height: options[:height],
30
+ # weight: options[:weight],
31
+ # first_name: options[:first_name],
32
+ # last_name: options[:last_name]
33
+ # }
34
+ # }
35
+
36
+ # response = post("/#{Validic.api_version}/profile.json", options)
37
+ # response if response
38
+ # end
39
+
40
+ end
41
+ end
42
+
43
+
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+ require 'active_support/core_ext'
3
+ require 'multi_json'
4
+
5
+ module Validic
6
+ module Request
7
+
8
+ def get(path, options)
9
+ request(:get, path, options)
10
+ end
11
+
12
+ def post(path, options)
13
+ request(:post, path, options)
14
+ end
15
+
16
+ def put(path, options)
17
+ request(:put, path, options)
18
+ end
19
+
20
+ def request(method, path, options)
21
+ options[:access_token] = options[:access_token].nil? ? Validic.access_token : options[:access_token]
22
+ response = connection.send(method) do |request|
23
+ case method
24
+ when :get
25
+ request.url(path, options)
26
+ when :post, :put
27
+ request.path = path
28
+ request.body = MultiJson.encode(options) unless options.empty?
29
+ end
30
+ end
31
+
32
+ response.body
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Routine
5
+
6
+ ##
7
+ # Get Routine 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
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 Routine
20
+ def get_routines(options={})
21
+ organization_id = options[:organization_id]
22
+ user_id = options[:user_id]
23
+ options = {
24
+ start_date: options[:start_date],
25
+ end_date: options[:end_date],
26
+ access_token: options[:access_token],
27
+ source: options[:source],
28
+ expanded: options[:expanded]
29
+ }
30
+
31
+ if organization_id
32
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/routine.json", options)
33
+ elsif user_id
34
+ response = get("/#{Validic.api_version}/users/#{user_id}/routine.json", options)
35
+ else
36
+ response = get("/#{Validic.api_version}/routine.json", options)
37
+ end
38
+ response if response
39
+ end
40
+
41
+ ##
42
+ # Create Routine base on `access_token` and `authentication_token`
43
+ #
44
+ # @params :access_token - *required if not specified on your initializer / organization access_token
45
+ # @params :authentication_token - *required / authentication_token of a specific user
46
+ #
47
+ # @params :steps
48
+ # @params :stairs_climbed
49
+ # @params :calories_burned
50
+ # @params :calories_consumed
51
+ # @params :timestamp
52
+ # @params :source
53
+ #
54
+ # @return success
55
+ def create_routine(options={})
56
+ options = {
57
+ access_token: options[:access_token],
58
+ routine: {
59
+ steps: options[:steps],
60
+ stairs_climbed: options[:stairs_climbed],
61
+ calories_burned: options[:calories_burned],
62
+ calories_consumed: options[:calories_consumed],
63
+ timestamp: options[:timestamp],
64
+ source: options[:source]
65
+ }
66
+ }
67
+
68
+ response = post("/#{Validic.api_version}/routine.json", options)
69
+ response if response
70
+ end
71
+
72
+ end
73
+ end