validic 0.2.1 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,6 +5,12 @@ require 'multi_json'
5
5
  module Validic
6
6
  module Request
7
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
+
8
14
  def get(path, options)
9
15
  request(:get, path, options)
10
16
  end
@@ -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 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
20
+ def get_routine(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:routine, params)
39
23
  end
40
24
 
25
+ alias :get_routines :get_routine
26
+
41
27
  ##
42
28
  # Create Routine base on `access_token` and `authentication_token`
43
29
  #
data/lib/validic/sleep.rb CHANGED
@@ -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 Sleep
20
- def get_sleeps(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}/sleep.json", options)
33
- elsif user_id
34
- response = get("/#{Validic.api_version}/users/#{user_id}/sleep.json", options)
35
- else
36
- response = get("/#{Validic.api_version}/sleep.json", options)
37
- end
38
- response if response
20
+ def get_sleep(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:sleep, params)
39
23
  end
40
24
 
25
+ alias :get_sleeps :get_sleep
26
+
41
27
  ##
42
28
  # Create Sleep base on `access_token` and `authentication_token`
43
29
  #
@@ -10,14 +10,9 @@ module Validic
10
10
  # params[:access_token] required parameter
11
11
  #
12
12
  # @return [Hashie::Mash] with list of Organization
13
- def get_apps(options={})
14
- organization_id = options[:organization_id]
15
- options = {
16
- access_token: options[:access_token],
17
- authentication_token: options[:authentication_token]
18
- }
19
- response = get("/#{Validic.api_version}/organizations/#{organization_id}/apps.json", options)
20
- response if response
13
+ def get_apps(params={})
14
+ params = extract_params(params)
15
+ get_endpoint(:apps, params)
21
16
  end
22
17
 
23
18
  ##
@@ -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 TobaccoCessation
20
- def get_tobacco_cessations(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}/tobacco_cessation.json", options)
33
- elsif user_id
34
- response = get("/#{Validic.api_version}/users/#{user_id}/tobacco_cessation.json", options)
35
- else
36
- response = get("/#{Validic.api_version}/tobacco_cessation.json", options)
37
- end
38
- response if response
20
+ def get_tobacco_cessations(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:tobacco_cessation, params)
39
23
  end
40
24
 
41
25
  ##
@@ -1,3 +1,3 @@
1
1
  module Validic
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -17,26 +17,13 @@ module Validic
17
17
  # @params :expanded - optional - will show the raw data
18
18
  #
19
19
  # @return [Hashie::Mash] with list of Weight
20
- def get_weights(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}/weight.json", options)
33
- elsif user_id
34
- response = get("/#{Validic.api_version}/users/#{user_id}/weight.json", options)
35
- else
36
- response = get("/#{Validic.api_version}/weight.json", options)
37
- end
20
+ def get_weight(params={})
21
+ params = extract_params(params)
22
+ get_endpoint(:weight, params)
38
23
  end
39
24
 
25
+ alias :get_weights :get_weight
26
+
40
27
  ##
41
28
  # Create Weight base on `access_token` and `authentication_token`
42
29
  #
data/spec/spec_helper.rb CHANGED
@@ -34,10 +34,11 @@ RSpec.configure do |c|
34
34
  #
35
35
  c.before(:each) do
36
36
  Validic.configure do |config|
37
- # config.api_url = 'https://api.validic.com'
38
- config.api_url = 'http://api.validic.dev' #development config
39
- config.api_version = 'v1'
40
- config.access_token = '9c03ad2bcb022425944e4686d398ef8398f537c2f7c113495ffa7bc9cfa49286'
37
+ # This is using ACME Corp Credentials as per Documentation
38
+ config.api_url = 'https://api.validic.com'
39
+ config.api_version = 'v1'
40
+ config.access_token = 'ef617d9d3bb39b4112f60dc65ee40061165c1ab4375e3ea63896f63a7390c4db'
41
+ config.organization_id = '51aca5a06dedda916400002b'
41
42
  end
42
43
  end
43
44
  end
@@ -0,0 +1,43 @@
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: '52967e076dedda5d4300000b'
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
@@ -3,9 +3,47 @@ require 'spec_helper'
3
3
 
4
4
  describe Validic::Client do
5
5
 
6
+ let(:client) { Validic::Client.new }
7
+
6
8
  it "creates a Faraday::Connection" do
7
- client = Validic::Client.new
8
9
  client.connection.should be_kind_of Faraday::Connection
9
10
  end
10
11
 
12
+ context "#latest" do
13
+ it "#fitness", vcr: true do
14
+ latest_fitness = client.latest(:fitness)
15
+ latest_fitness.summary.should_not be_nil
16
+ end
17
+
18
+ it "#sleep", vcr: true do
19
+ latest_sleep = client.latest(:sleep)
20
+ latest_sleep.summary.should_not be_nil
21
+ end
22
+
23
+ it "#routine", vcr: true do
24
+ latest_routine = client.latest(:routine)
25
+ latest_routine.summary.should_not be_nil
26
+ end
27
+
28
+ it "#weight", vcr: true do
29
+ latest_weight = client.latest(:weight)
30
+ latest_weight.summary.should_not be_nil
31
+ end
32
+
33
+ it "#biometrics", vcr: true do
34
+ latest_biometrics = client.latest(:biometrics)
35
+ latest_biometrics.summary.should_not be_nil
36
+ end
37
+
38
+ it "#nutrition", vcr: true do
39
+ latest_nutrition = client.latest(:nutrition)
40
+ latest_nutrition.summary.should_not be_nil
41
+ end
42
+
43
+ it "#tobacco_cessation", vcr: true do
44
+ latest_tobacco_cessation = client.latest(:tobacco_cessation)
45
+ latest_tobacco_cessation.summary.should_not be_nil
46
+ end
47
+ end
48
+
11
49
  end
@@ -24,7 +24,8 @@ describe Validic::Diabetes do
24
24
  end
25
25
 
26
26
  context "#create_diabetes" do
27
- it "should create new diabetes record" do
27
+ it "should create new diabetes record", vcr: true do
28
+ pending
28
29
  @new_diabetes = client.create_diabetes({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
30
  access_token: "DEMO_KEY",
30
31
  c_peptide: 1,
@@ -51,7 +52,7 @@ describe Validic::Diabetes do
51
52
 
52
53
  context "#get_diabetes by organization" do
53
54
  before do
54
- @org_diabetes = client.get_diabetes({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
55
+ @org_diabetes = client.get_diabetes({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
55
56
  end
56
57
 
57
58
  it "returns JSON response of Validic::Diabetes", vcr: true do
@@ -69,7 +70,7 @@ describe Validic::Diabetes do
69
70
 
70
71
  context "#get_diabetes by user" do
71
72
  before do
72
- @user_diabetes = client.get_diabetes({user_id: "519e24e16a7e0cc7ef00002c"})
73
+ @user_diabetes = client.get_diabetes({user_id: "52967e076dedda5d4300000b"})
73
74
  end
74
75
 
75
76
  it "returns JSON response of Validic::Diabetes", vcr: true do
@@ -25,6 +25,7 @@ describe Validic::Fitness do
25
25
 
26
26
  context "#create_fitness" do
27
27
  it "should create new fitness record" do
28
+ pending
28
29
  @new_fitness = client.create_fitness({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
30
  access_token: "DEMO_KEY",
30
31
  timestamp: "2013-03-10 07:12:16 -05:00",
@@ -47,7 +48,7 @@ describe Validic::Fitness do
47
48
 
48
49
  context "#get_fitnesses by organization" do
49
50
  before do
50
- @fitness = client.get_fitnesses({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
51
+ @fitness = client.get_fitnesses({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
51
52
  end
52
53
 
53
54
  it "returns JSON response of Validic::Fitness", vcr: true do
@@ -65,7 +66,7 @@ describe Validic::Fitness do
65
66
 
66
67
  context "#get_fitnesses by user" do
67
68
  before do
68
- @fitness = client.get_fitnesses({user_id: "519e24e16a7e0cc7ef00002c"})
69
+ @fitness = client.get_fitnesses({user_id: "52967e076dedda5d4300000b"})
69
70
  end
70
71
 
71
72
  it "returns JSON response of Validic::Fitness", vcr: true do
@@ -25,6 +25,7 @@ describe Validic::Nutrition do
25
25
 
26
26
  context "#create_nutrition" do
27
27
  it "should create new nutrition record" do
28
+ pending
28
29
  @new_nutrition = client.create_nutrition({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
30
  access_token: "DEMO_KEY",
30
31
  calories: 850,
@@ -53,7 +54,7 @@ describe Validic::Nutrition do
53
54
 
54
55
  context "#get_nutritions by organization" do
55
56
  before do
56
- @nutrition = client.get_nutritions({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
57
+ @nutrition = client.get_nutritions({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
57
58
  end
58
59
 
59
60
  it "returns JSON response of Validic::Nutrition", vcr: true do
@@ -71,7 +72,7 @@ describe Validic::Nutrition do
71
72
 
72
73
  context "#get_nutritions by user" do
73
74
  before do
74
- @nutrition = client.get_nutritions({user_id: "519e24e16a7e0cc7ef00002c"})
75
+ @nutrition = client.get_nutritions({user_id: "52967e076dedda5d4300000b"})
75
76
  end
76
77
 
77
78
  it "returns JSON response of Validic::Nutrition", vcr: true do
@@ -7,7 +7,7 @@ describe Validic::Organization do
7
7
 
8
8
  context "#get_organization" do
9
9
  before do
10
- @organization_response = client.get_organization({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
10
+ @organization_response = client.get_organization({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
11
11
  end
12
12
 
13
13
  it "returns JSON response of Validic::Organization", vcr: true do
@@ -25,7 +25,7 @@ describe Validic::Organization do
25
25
 
26
26
  context "#get_users" do
27
27
  before do
28
- @users_response = client.get_users({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
28
+ @users_response = client.get_users({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
29
29
  end
30
30
 
31
31
  it "returns JSON response of Validic::Organization", vcr: true do
@@ -11,36 +11,9 @@ describe Validic::Profile do
11
11
  end
12
12
 
13
13
  it "returns JSON response of Validic::Profile", vcr: true do
14
+ pending
14
15
  @profile.should_not be_nil
15
16
  end
16
17
  end
17
18
 
18
- # context "#update_profile" do
19
- # before do
20
- # @updated_profile = client.update_profile({gender: "M",
21
- # location: "TX",
22
- # birth_year: "1985",
23
- # height: 168.75,
24
- # weight: 69,
25
- # first_name: "Demo",
26
- # last_name: "User"})
27
- # end
28
-
29
- # it "should return gender" do
30
- # @updated_profile.profile.gender.should eq 'M'
31
- # end
32
-
33
- # it "should return location" do
34
- # @updated_profile.profile.location.should eq 'TX'
35
- # end
36
-
37
- # it "should return height" do
38
- # @updated_profile.profile.height.should eq "168.75"
39
- # end
40
-
41
- # it "should return weight" do
42
- # @updated_profile.profile.weight.should eq 69
43
- # end
44
- # end
45
-
46
19
  end
@@ -25,6 +25,7 @@ describe Validic::Routine do
25
25
 
26
26
  context "#create_routine" do
27
27
  it "should create new routine record" do
28
+ pending
28
29
  @new_routine = client.create_routine({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
30
  access_token: "DEMO_KEY",
30
31
  timestamp: "2013-05-16 07:12:16 -05:00",
@@ -45,7 +46,7 @@ describe Validic::Routine do
45
46
 
46
47
  context "#get_routines by organization" do
47
48
  before do
48
- @routine = client.get_routines({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
49
+ @routine = client.get_routines({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
49
50
  end
50
51
 
51
52
  it "returns JSON response of Validic::Routine", vcr: true do
@@ -63,7 +64,7 @@ describe Validic::Routine do
63
64
 
64
65
  context "#get_routines by user" do
65
66
  before do
66
- @routine = client.get_routines({user_id: "519e24e16a7e0cc7ef00002c"})
67
+ @routine = client.get_routines({user_id: "52967e076dedda5d4300000b"})
67
68
  end
68
69
 
69
70
  it "returns JSON response of Validic::Routine", vcr: true do
@@ -25,6 +25,7 @@ describe Validic::Sleep do
25
25
 
26
26
  context "#create_sleep" do
27
27
  it "should create new sleep record" do
28
+ pending
28
29
  @new_sleep = client.create_sleep({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
30
  access_token: "DEMO_KEY",
30
31
  total_sleep: 210,
@@ -49,7 +50,7 @@ describe Validic::Sleep do
49
50
 
50
51
  context "#get_sleeps by organization" do
51
52
  before do
52
- @sleep = client.get_sleeps({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
53
+ @sleep = client.get_sleeps({organization_id: "51aca5a06dedda916400002b", access_token: "ENTERPRISE_KEY"})
53
54
  end
54
55
 
55
56
  it "returns JSON response of Validic::Sleep", vcr: true do
@@ -67,7 +68,7 @@ describe Validic::Sleep do
67
68
 
68
69
  context "#get_sleeps by user" do
69
70
  before do
70
- @sleep = client.get_sleeps({user_id: "519e24e16a7e0cc7ef00002c"})
71
+ @sleep = client.get_sleeps({user_id: "52967e076dedda5d4300000b"})
71
72
  end
72
73
 
73
74
  it "returns JSON response of Validic::Sleep", vcr: true do