validic 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 33f8543ef109856fdd4dd43b1596c52489fed422
4
+ data.tar.gz: 8cf5a8e0d41473a58924c9fd8609c1493bfc3b34
5
+ SHA512:
6
+ metadata.gz: 824c8b8d0834310140fd4d77e62efd5911cd8538d460d0d164d470227df8a7890443da8fa95fa628ab9ddb72a70fac51580a76bad7ddf3b0e7bffe91760c1c0f
7
+ data.tar.gz: fdb9bafdf0710abcd37f0d4523ae7d108e40f49d3246b871330e49268acd65b0919c539e8f42312235ac5fe52b40870b79c48073749bc5d911bf2cb7b8e8cd7d
data/.gitignore CHANGED
@@ -8,10 +8,14 @@ lib/bundler/man
8
8
  pkg
9
9
  rdoc
10
10
  spec/reports
11
+ spec/cassette
11
12
  test/tmp
12
13
  test/version_tmp
13
14
  tmp
14
15
 
16
+ # OSX
17
+ .DS_Store
18
+
15
19
  # YARD artifacts
16
20
  .yardoc
17
21
  _yardoc
data/Gemfile.lock CHANGED
@@ -1,80 +1,87 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validic (0.2.1)
4
+ validic (0.3.1)
5
5
  activesupport
6
- faraday (~> 0.8)
7
- faraday_middleware (~> 0.9)
6
+ faraday_middleware (~> 0.9.0)
8
7
  hashie (~> 2.0.3)
9
8
  multi_json
10
9
 
11
10
  GEM
12
11
  remote: https://rubygems.org/
13
12
  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)
13
+ activesupport (4.0.2)
14
+ i18n (~> 0.6, >= 0.6.4)
15
+ minitest (~> 4.2)
16
+ multi_json (~> 1.3)
17
+ thread_safe (~> 0.1)
18
+ tzinfo (~> 0.3.37)
19
+ addressable (2.3.5)
20
+ api_matchers (0.4.0)
19
21
  activesupport (>= 3.2.5)
20
22
  nokogiri (>= 1.5.2)
21
23
  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)
24
+ atomic (1.1.14)
25
+ crack (0.4.1)
26
+ safe_yaml (~> 0.9.0)
27
+ diff-lcs (1.2.5)
28
+ docile (1.1.2)
29
+ faraday (0.8.9)
27
30
  multipart-post (~> 1.2.0)
28
31
  faraday_middleware (0.9.0)
29
32
  faraday (>= 0.7.4, < 0.9)
30
33
  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)
34
+ i18n (0.6.9)
35
+ mini_portile (0.5.2)
36
+ minitest (4.7.5)
37
+ multi_json (1.8.4)
36
38
  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)
39
+ nokogiri (1.6.1)
40
+ mini_portile (~> 0.5.0)
41
+ rake (10.1.1)
42
+ rspec (2.14.1)
43
+ rspec-core (~> 2.14.0)
44
+ rspec-expectations (~> 2.14.0)
45
+ rspec-mocks (~> 2.14.0)
46
+ rspec-core (2.14.7)
47
+ rspec-expectations (2.14.4)
45
48
  diff-lcs (>= 1.1.3, < 2.0)
46
- rspec-mocks (2.13.1)
47
- shoulda (3.4.0)
49
+ rspec-mocks (2.14.4)
50
+ safe_yaml (0.9.7)
51
+ shoulda (3.5.0)
48
52
  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)
53
+ shoulda-matchers (>= 1.4.1, < 3.0)
54
+ shoulda-context (1.1.6)
55
+ shoulda-matchers (2.5.0)
52
56
  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)
57
+ simplecov (0.8.2)
58
+ docile (~> 1.1.0)
59
+ multi_json
60
+ simplecov-html (~> 0.8.0)
61
+ simplecov-html (0.8.0)
58
62
  simplecov-rcov (0.2.3)
59
63
  simplecov (>= 0.4.1)
60
- vcr (2.4.0)
61
- webmock (1.11.0)
64
+ thread_safe (0.1.3)
65
+ atomic
66
+ tzinfo (0.3.38)
67
+ vcr (2.8.0)
68
+ webmock (1.8.11)
62
69
  addressable (>= 2.2.7)
63
- crack (>= 0.3.2)
64
- yard (0.8.6.1)
70
+ crack (>= 0.1.7)
71
+ yard (0.8.7.3)
65
72
 
66
73
  PLATFORMS
67
74
  ruby
68
75
 
69
76
  DEPENDENCIES
70
77
  api_matchers
71
- bundler (~> 1.3)
78
+ bundler
72
79
  rake
73
80
  rspec
74
81
  shoulda
75
82
  simplecov
76
83
  simplecov-rcov
77
84
  validic!
78
- vcr
79
- webmock
85
+ vcr (~> 2.8.0)
86
+ webmock (~> 1.8.0)
80
87
  yard
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013 Motivation Science
1
+ Copyright (c) 2013 Validic
2
2
 
3
3
  MIT License
4
4
 
data/lib/validic.rb CHANGED
@@ -8,7 +8,11 @@ directory = File.expand_path(File.dirname(__FILE__))
8
8
  module Validic
9
9
 
10
10
  class << self
11
- attr_accessor :api_url, :api_version, :access_token
11
+ attr_accessor :api_url,
12
+ :api_version,
13
+ :access_token,
14
+ :organization_id,
15
+ :user_id
12
16
 
13
17
  ##
14
18
  # Configure default
@@ -23,9 +27,10 @@ module Validic
23
27
  private
24
28
 
25
29
  def load_defaults
26
- self.api_url ||= 'https://api.validic.com'
27
- self.api_version ||= 'v1'
28
- self.access_token ||= 'DEMO_KEY'
30
+ self.api_url ||= 'https://api.validic.com'
31
+ self.api_version ||= 'v1'
32
+ self.access_token ||= 'ENTERPRISE_KEY'
33
+ self.organization_id ||= '51aca5a06dedda916400002b'
29
34
  end
30
35
  end
31
36
 
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Validic
4
- module GeneralMeasurement
4
+ module Biometric
5
5
 
6
6
  ##
7
7
  # Get GeneralMeasurement Activities base on `access_token`
8
8
  # Default data fetched is from yesterday
9
9
  #
10
- # @params :organization_id - for organization specific
10
+ # @params :org_id - for organization specific
11
11
  # @params :user_id - for user specific
12
12
  #
13
13
  # @params :start_date - optional
@@ -17,25 +17,9 @@ module Validic
17
17
  # @params :expanded - optional - will show the raw data
18
18
  #
19
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
20
+ def get_biometrics(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:biometrics, params)
39
23
  end
40
24
 
41
25
  ##
@@ -72,7 +56,7 @@ module Validic
72
56
  # @params :source
73
57
  #
74
58
  # @return success
75
- def create_general_measurement(options={})
59
+ def create_biometric(options={})
76
60
  options = {
77
61
  access_token: options[:access_token],
78
62
  general_measurement: {
@@ -2,7 +2,6 @@
2
2
  require 'forwardable'
3
3
  require 'validic/request'
4
4
  require 'validic/organization'
5
- require 'validic/activity'
6
5
  require 'validic/user'
7
6
  require 'validic/profile'
8
7
  require 'validic/fitness'
@@ -10,7 +9,7 @@ require 'validic/weight'
10
9
  require 'validic/nutrition'
11
10
  require 'validic/sleep'
12
11
  require 'validic/diabetes'
13
- require 'validic/general_measurement'
12
+ require 'validic/biometric'
14
13
  require 'validic/routine'
15
14
  require 'validic/tobacco_cessation'
16
15
  require 'validic/third_party_app'
@@ -21,7 +20,6 @@ module Validic
21
20
 
22
21
  include Request
23
22
  include Organization
24
- include Activity
25
23
  include User
26
24
  include Profile
27
25
  include Fitness
@@ -29,12 +27,15 @@ module Validic
29
27
  include Nutrition
30
28
  include Sleep
31
29
  include Diabetes
32
- include GeneralMeasurement
30
+ include Biometric
33
31
  include Routine
34
32
  include TobaccoCessation
35
33
  include ThirdPartyApp
36
34
 
37
- attr_reader :api_url, :api_version, :access_token
35
+ attr_reader :api_url,
36
+ :api_version,
37
+ :access_token,
38
+ :organization_id
38
39
 
39
40
  ##
40
41
  # Create a new Validic::Client object
@@ -44,6 +45,7 @@ module Validic
44
45
  @api_url = options[:api_url] || Validic.api_url
45
46
  @api_version = options[:api_version] || Validic.api_version || 'v1'
46
47
  @access_token = options[:access_token] || Validic.access_token
48
+ @organization_id = options[:organization_id] || Validic.organization_id
47
49
  end
48
50
 
49
51
  ##
@@ -52,7 +54,7 @@ module Validic
52
54
  # @return [Faraday::Connection]
53
55
  def connection
54
56
  params = {}
55
- @connection = Faraday.new(url: api_url, params: params, headers: default_headers, ssl: {verify: false}) do |faraday|
57
+ @connection = Faraday.new(url: api_url, params: params, headers: default_headers, ssl: {verify: true}) do |faraday|
56
58
  faraday.use FaradayMiddleware::Mashify
57
59
  faraday.use FaradayMiddleware::ParseJson, content_type: /\bjson$/
58
60
  faraday.use FaradayMiddleware::FollowRedirects
@@ -60,10 +62,49 @@ module Validic
60
62
  end
61
63
  end
62
64
 
65
+ ##
66
+ # Pull the latest endpoint
67
+ def latest(type, org_id=nil, user_id=nil, params={})
68
+ organization_id = org_id.nil? ? Validic.organization_id : org_id
69
+ user_id = org_id.nil? ? Validic.user_id : org_id
70
+
71
+ url = "/#{Validic.api_version}/organizations/#{organization_id}/#{type.to_s}/latest.json"
72
+
73
+ if user_id
74
+ url = "/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}/#{type.to_s}/latest.json"
75
+ end
76
+
77
+ get(url, params)
78
+ end
79
+
80
+ ##
81
+ # Generic Pull of Validic Objects
82
+ def get_endpoint(type, params={})
83
+
84
+ url = "/#{Validic.api_version}/organizations/#{Validic.organization_id}/#{type.to_s}.json"
85
+
86
+ if Validic.user_id
87
+ url = "/#{Validic.api_version}/organizations/#{Validic.organization_id}/users/#{Validic.user_id}/#{type.to_s}.json"
88
+ end
89
+
90
+ get(url, params)
91
+ end
92
+
93
+ ##
94
+ # Generic POST to Validic
95
+ def post_to_validic(type, params={})
96
+ url = "/#{Validic.api_version}/organizations/#{Validic.organization_id}/#{type.to_s}.json"
97
+
98
+ if Validic.user_id
99
+ url = "/#{Validic.api_version}/organizations/#{Validic.organization_id}/users/#{Validic.user_id}/#{type.to_s}.json"
100
+ end
101
+ post(url, params)
102
+ end
103
+
63
104
  private
64
105
 
65
106
  def default_headers
66
- headers = {
107
+ {
67
108
  accept: 'application/json',
68
109
  content_type: 'application/json',
69
110
  user_agent: "Ruby Gem by Validic #{Validic::VERSION}"
@@ -17,26 +17,9 @@ module Validic
17
17
  # @params :expanded - optional - will show the raw data
18
18
  #
19
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
20
+ def get_diabetes(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:diabetes, params)
40
23
  end
41
24
 
42
25
  ##
@@ -17,27 +17,13 @@ module Validic
17
17
  # @params :expanded - optional - will show the raw data
18
18
  #
19
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
20
+ def get_fitness(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:fitness, params)
39
23
  end
40
24
 
25
+ alias :get_fitnesses :get_fitness
26
+
41
27
  ##
42
28
  # Create Fitness base on `access_token` and `authentication_token`
43
29
  #
@@ -17,25 +17,9 @@ module Validic
17
17
  # @params :expanded - optional - will show the raw data
18
18
  #
19
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
20
+ def get_nutritions(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:nutrition, params)
39
23
  end
40
24
 
41
25
  ##
@@ -8,13 +8,9 @@ module Validic
8
8
  #
9
9
  # @params :access_token
10
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
11
+ def get_organization(params={})
12
+ params = extract_params(params)
13
+ get("/#{Validic.api_version}/organizations/#{Validic.organization_id}.json", params)
18
14
  end
19
15
 
20
16
  ##