validic 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
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
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --tty
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in validic.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,80 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ validic (0.2.1)
5
+ activesupport
6
+ faraday (~> 0.8)
7
+ faraday_middleware (~> 0.9)
8
+ hashie (~> 2.0.3)
9
+ multi_json
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ activesupport (3.2.13)
15
+ i18n (= 0.6.1)
16
+ multi_json (~> 1.0)
17
+ addressable (2.3.4)
18
+ api_matchers (0.1.1)
19
+ activesupport (>= 3.2.5)
20
+ nokogiri (>= 1.5.2)
21
+ rspec (>= 2.10.0)
22
+ bourne (1.4.0)
23
+ mocha (~> 0.13.2)
24
+ crack (0.3.2)
25
+ diff-lcs (1.2.3)
26
+ faraday (0.8.8)
27
+ multipart-post (~> 1.2.0)
28
+ faraday_middleware (0.9.0)
29
+ faraday (>= 0.7.4, < 0.9)
30
+ hashie (2.0.5)
31
+ i18n (0.6.1)
32
+ metaclass (0.0.1)
33
+ mocha (0.13.3)
34
+ metaclass (~> 0.0.1)
35
+ multi_json (1.7.2)
36
+ multipart-post (1.2.0)
37
+ nokogiri (1.5.9)
38
+ rake (10.0.4)
39
+ rspec (2.13.0)
40
+ rspec-core (~> 2.13.0)
41
+ rspec-expectations (~> 2.13.0)
42
+ rspec-mocks (~> 2.13.0)
43
+ rspec-core (2.13.1)
44
+ rspec-expectations (2.13.0)
45
+ diff-lcs (>= 1.1.3, < 2.0)
46
+ rspec-mocks (2.13.1)
47
+ shoulda (3.4.0)
48
+ shoulda-context (~> 1.0, >= 1.0.1)
49
+ shoulda-matchers (~> 1.0, >= 1.4.1)
50
+ shoulda-context (1.1.1)
51
+ shoulda-matchers (1.5.6)
52
+ activesupport (>= 3.0.0)
53
+ bourne (~> 1.3)
54
+ simplecov (0.7.1)
55
+ multi_json (~> 1.0)
56
+ simplecov-html (~> 0.7.1)
57
+ simplecov-html (0.7.1)
58
+ simplecov-rcov (0.2.3)
59
+ simplecov (>= 0.4.1)
60
+ vcr (2.4.0)
61
+ webmock (1.11.0)
62
+ addressable (>= 2.2.7)
63
+ crack (>= 0.3.2)
64
+ yard (0.8.6.1)
65
+
66
+ PLATFORMS
67
+ ruby
68
+
69
+ DEPENDENCIES
70
+ api_matchers
71
+ bundler (~> 1.3)
72
+ rake
73
+ rspec
74
+ shoulda
75
+ simplecov
76
+ simplecov-rcov
77
+ validic!
78
+ vcr
79
+ webmock
80
+ yard
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Motivation Science
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # Validic
2
+
3
+ Ruby API Wrapper for [Validic](http://www.validic.com)
4
+
5
+ ## Build Status
6
+ [![Codeship Status for Validic/validic](https://www.codeship.io/projects/cc4ff330-9f72-0130-3cf3-0e5a3e2104f7/status?branch=master)](https://www.codeship.io/projects/3456)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'validic'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install validic
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ require 'validic'
26
+
27
+ # If your using Rails 3+
28
+ # config/initializers/validic.rb
29
+ Validic.configure do |config|
30
+ config.api_url = 'https://api.validic.com'
31
+ config.api_version = 'v1'
32
+ end
33
+
34
+ # If your using plain RUBY
35
+ # Create Validic::Client Object
36
+ options = {
37
+ api_url: 'https://api.validic.com',
38
+ api_version: 'v1',
39
+ access_token: 'DEMO_KEY' # Replace this with your key
40
+ }
41
+ client = Validic::Client.new options
42
+
43
+ # Create a Client Object expecting you have an initializer in place
44
+ # Validic::Client Object
45
+ client = Validic::Client.new
46
+
47
+ # => Get Account Activities
48
+ client.get_activities
49
+
50
+ # => Get Organization Activities
51
+ client.get_activites({organization_id: "YOUR_organization_id",
52
+ access_token: "YOUR_ACCESS_TOKEN"})
53
+ ```
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task default: :spec
data/lib/validic.rb ADDED
@@ -0,0 +1,32 @@
1
+ require "faraday"
2
+ require "faraday_middleware"
3
+ require "validic/client"
4
+ require "validic/version"
5
+
6
+ directory = File.expand_path(File.dirname(__FILE__))
7
+
8
+ module Validic
9
+
10
+ class << self
11
+ attr_accessor :api_url, :api_version, :access_token
12
+
13
+ ##
14
+ # Configure default
15
+ #
16
+ # @yield [Validic]
17
+ def configure
18
+ load_defaults
19
+ yield self
20
+ true
21
+ end
22
+
23
+ private
24
+
25
+ def load_defaults
26
+ self.api_url ||= 'https://api.validic.com'
27
+ self.api_version ||= 'v1'
28
+ self.access_token ||= 'DEMO_KEY'
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Activity
5
+
6
+ ##
7
+ # Get Activity base on `access_token`
8
+ # Default data fetched is from yesterday
9
+ #
10
+ # @params :organization_id - for organization specific activity
11
+ # @params :user_id - for user specific activity
12
+ #
13
+ # @params :start_date - optional
14
+ # @params :end_date - optional
15
+ # @params :access_token - override for default access_token
16
+ #
17
+ # @return [Hashie::Mash] with list of Activity
18
+ def get_activities(options={})
19
+ organization_id = options[:organization_id]
20
+ user_id = options[:user_id]
21
+ options = {
22
+ access_token: options[:access_token],
23
+ start_date: options[:start_date],
24
+ end_date: options[:end_date]
25
+ }
26
+
27
+ if organization_id
28
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/fitness.json", options)
29
+ elsif user_id
30
+ response = get("/#{Validic.api_version}/users/#{user_id}/fitness.json", options)
31
+ else
32
+ response = get("/#{Validic.api_version}/fitness.json", options)
33
+ end
34
+
35
+ response if response
36
+ end
37
+
38
+ ##
39
+ # Get the latest Activities base on 'access_token'
40
+ # for organization or for a specific user
41
+ #
42
+ # @activity_type - mandatory - specify what type of activity to fetch
43
+ # List of activity_types
44
+ # [ fitness, routine, weight, nutrition, sleep, diabetes, biometrics, tobacco_cessation ]
45
+ #
46
+ # @params :organization_id - optional - supply only this to get all user's activities belonging to organization
47
+ # @params :user_id - optional - supply only this to get the user's latest activities
48
+ def get_latest_activities(options={})
49
+ activity_type = options[:activity_type]
50
+ organization_id = options[:organization_id]
51
+ user_id = options[:user_id]
52
+ options = {
53
+ access_token: options[:access_token]
54
+ }
55
+
56
+ if activity_type.blank?
57
+ response = "Invalid api request. params[:activity_type] can't be blank."
58
+ else
59
+ if organization_id && user_id
60
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}/#{activity_type}/latest", options)
61
+ elsif organization_id && user_id.blank?
62
+ response = get("/#{Validic.api_version}/organizations/#{organization_id}/#{activity_type}/latest", options)
63
+ elsif user_id && organization_id.blank?
64
+ response = get("/#{Validic.api_version}/users/#{user_id}/#{activity_type}/latest", options)
65
+ else
66
+ response = get("/#{Validic.api_version}/#{activity_type}/latest", options)
67
+ end
68
+ end
69
+ response if response
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+ require 'forwardable'
3
+ require 'validic/request'
4
+ require 'validic/organization'
5
+ require 'validic/activity'
6
+ require 'validic/user'
7
+ require 'validic/profile'
8
+ require 'validic/fitness'
9
+ require 'validic/weight'
10
+ require 'validic/nutrition'
11
+ require 'validic/sleep'
12
+ require 'validic/diabetes'
13
+ require 'validic/general_measurement'
14
+ require 'validic/routine'
15
+ require 'validic/tobacco_cessation'
16
+ require 'validic/third_party_app'
17
+
18
+ module Validic
19
+ class Client
20
+ extend Forwardable
21
+
22
+ include Request
23
+ include Organization
24
+ include Activity
25
+ include User
26
+ include Profile
27
+ include Fitness
28
+ include Weight
29
+ include Nutrition
30
+ include Sleep
31
+ include Diabetes
32
+ include GeneralMeasurement
33
+ include Routine
34
+ include TobaccoCessation
35
+ include ThirdPartyApp
36
+
37
+ attr_reader :api_url, :api_version, :access_token
38
+
39
+ ##
40
+ # Create a new Validic::Client object
41
+ #
42
+ # @params options[Hash]
43
+ def initialize(options={})
44
+ @api_url = options[:api_url] || Validic.api_url
45
+ @api_version = options[:api_version] || Validic.api_version || 'v1'
46
+ @access_token = options[:access_token] || Validic.access_token
47
+ end
48
+
49
+ ##
50
+ # Create a Faraday::Connection object
51
+ #
52
+ # @return [Faraday::Connection]
53
+ def connection
54
+ params = {}
55
+ @connection = Faraday.new(url: api_url, params: params, headers: default_headers, ssl: {verify: false}) do |faraday|
56
+ faraday.use FaradayMiddleware::Mashify
57
+ faraday.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
58
+ faraday.use FaradayMiddleware::FollowRedirects
59
+ faraday.adapter Faraday.default_adapter
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def default_headers
66
+ headers = {
67
+ accept: 'application/json',
68
+ content_type: 'application/json',
69
+ user_agent: "Ruby Gem by Validic #{Validic::VERSION}"
70
+ }
71
+ end
72
+
73
+ end
74
+ end
@@ -0,0 +1,81 @@
1
+ # encoding: utf-8
2
+
3
+ module Validic
4
+ module Diabetes
5
+
6
+ ##
7
+ # Get User Diabetes 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 Diabetes
20
+ def get_diabetes(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}/diabetes.json", options)
33
+ elsif user_id
34
+ response = get("/#{Validic.api_version}/users/#{user_id}/diabetes.json", options)
35
+ else
36
+ response = get("/#{Validic.api_version}/diabetes.json", options)
37
+ end
38
+
39
+ response if response
40
+ end
41
+
42
+ ##
43
+ # Create Diabetes base on `access_token` and `authentication_token`
44
+ #
45
+ # @params :access_token - *required if not specified on your initializer / organization access_token
46
+ # @params :authentication_token - *required / authentication_token of a specific user
47
+ #
48
+ # @params :c_peptide
49
+ # @params :fasting_plasma_glucose_test
50
+ # @params :hba1c
51
+ # @params :insulin
52
+ # @params :oral_glucose_tolerance_test
53
+ # @params :random_plasma_glucose_test
54
+ # @params :triglyceride
55
+ # @params :timestamp
56
+ # @params :source
57
+ #
58
+ # @return success
59
+ def create_diabetes(options={})
60
+ options = {
61
+ authentication_token: options[:authentication_token],
62
+ access_token: options[:access_token],
63
+ diabetes: {
64
+ c_peptide: options[:c_peptide],
65
+ fasting_plasma_glucose_test: options[:fasting_plasma_glucose_test],
66
+ hba1c: options[:hba1c],
67
+ insulin: options[:insulin],
68
+ oral_glucose_tolerance_test: options[:oral_glucose_tolerance_test],
69
+ random_plasma_glucose_test: options[:random_plasma_glucose_test],
70
+ triglyceride: options[:triglyceride],
71
+ timestamp: options[:timestamp],
72
+ source: options[:source]
73
+ }
74
+ }
75
+
76
+ response = post("/#{Validic.api_version}/diabetes.json", options)
77
+ response if response
78
+ end
79
+
80
+ end
81
+ end