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,81 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::Routine do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "#get_routines" do
9
+ before do
10
+ @routine = client.get_routines({})
11
+ end
12
+
13
+ it "returns JSON response of Validic::Routine", vcr: true do
14
+ @routine.should_not be_nil
15
+ end
16
+
17
+ it "status 200" do
18
+ @routine.summary.status.should == 200
19
+ end
20
+
21
+ it "has summary node" do
22
+ @routine.summary.should_not be_nil
23
+ end
24
+ end
25
+
26
+ context "#create_routine" do
27
+ it "should create new routine record" do
28
+ @new_routine = client.create_routine({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
+ access_token: "DEMO_KEY",
30
+ timestamp: "2013-05-16 07:12:16 -05:00",
31
+ steps: 10000,
32
+ stairs_climbed: 50,
33
+ calories_burned: 2500,
34
+ calories_consumed: 3000,
35
+ source: "Sample App"})
36
+ @new_routine.should_not be_nil
37
+ @new_routine.routine.timestamp.should eq "2013-05-16 07:12:16 -05:00"
38
+ @new_routine.routine.steps.should eq 10000.0
39
+ @new_routine.routine.stairs_climbed.should eq 50.0
40
+ @new_routine.routine.calories_burned.should eq 2500.0
41
+ @new_routine.routine.calories_consumed.should eq 3000.0
42
+ @new_routine.routine.source.should eq "Sample App"
43
+ end
44
+ end
45
+
46
+ context "#get_routines by organization" do
47
+ before do
48
+ @routine = client.get_routines({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
49
+ end
50
+
51
+ it "returns JSON response of Validic::Routine", vcr: true do
52
+ @routine.should_not be_nil
53
+ end
54
+
55
+ it "status 200" do
56
+ @routine.summary.status.should == 200
57
+ end
58
+
59
+ it "has summary node" do
60
+ @routine.summary.should_not be_nil
61
+ end
62
+ end
63
+
64
+ context "#get_routines by user" do
65
+ before do
66
+ @routine = client.get_routines({user_id: "519e24e16a7e0cc7ef00002c"})
67
+ end
68
+
69
+ it "returns JSON response of Validic::Routine", vcr: true do
70
+ @routine.should_not be_nil
71
+ end
72
+
73
+ it "status 200" do
74
+ @routine.summary.status.should == 200
75
+ end
76
+
77
+ it "has summary node" do
78
+ @routine.summary.should_not be_nil
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::Sleep do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "#get_sleeps" do
9
+ before do
10
+ @sleep = client.get_sleeps({})
11
+ end
12
+
13
+ it "returns JSON response of Validic::Sleep", vcr: true do
14
+ @sleep.should_not be_nil
15
+ end
16
+
17
+ it "status 200" do
18
+ @sleep.summary.status.should == 200
19
+ end
20
+
21
+ it "has summary node" do
22
+ @sleep.summary.should_not be_nil
23
+ end
24
+ end
25
+
26
+ context "#create_sleep" do
27
+ it "should create new sleep record" do
28
+ @new_sleep = client.create_sleep({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
+ access_token: "DEMO_KEY",
30
+ total_sleep: 210,
31
+ awake: 10,
32
+ deep: 120,
33
+ light: 50,
34
+ rem: 30,
35
+ times_woken: 3,
36
+ timestamp: "2013-05-16 07:12:16 -05:00",
37
+ source: "Sample App"})
38
+ @new_sleep.should_not be_nil
39
+ @new_sleep.sleep.timestamp.should eq "2013-05-16 07:12:16 -05:00"
40
+ @new_sleep.sleep.total_sleep.should eq 210.0
41
+ @new_sleep.sleep.awake.should eq 10.0
42
+ @new_sleep.sleep.deep.should eq 120.0
43
+ @new_sleep.sleep.light.should eq 50.0
44
+ @new_sleep.sleep.rem.should eq 30.0
45
+ @new_sleep.sleep.times_woken.should eq 3.0
46
+ @new_sleep.sleep.source.should eq "Sample App"
47
+ end
48
+ end
49
+
50
+ context "#get_sleeps by organization" do
51
+ before do
52
+ @sleep = client.get_sleeps({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
53
+ end
54
+
55
+ it "returns JSON response of Validic::Sleep", vcr: true do
56
+ @sleep.should_not be_nil
57
+ end
58
+
59
+ it "status 200" do
60
+ @sleep.summary.status.should == 200
61
+ end
62
+
63
+ it "has summary node" do
64
+ @sleep.summary.should_not be_nil
65
+ end
66
+ end
67
+
68
+ context "#get_sleeps by user" do
69
+ before do
70
+ @sleep = client.get_sleeps({user_id: "519e24e16a7e0cc7ef00002c"})
71
+ end
72
+
73
+ it "returns JSON response of Validic::Sleep", vcr: true do
74
+ @sleep.should_not be_nil
75
+ end
76
+
77
+ it "status 200" do
78
+ @sleep.summary.status.should == 200
79
+ end
80
+
81
+ it "has summary node" do
82
+ @sleep.summary.should_not be_nil
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::ThirdPartyApp do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "#get_apps" do
9
+ before do
10
+ @app_response = client.get_apps({organization_id: "519e24df6a7e0cc7ef000001", authentication_token: "mqwpDx8RYcmSFBJDmy3J"})
11
+ end
12
+
13
+ it "returns JSON response of Validic::ThirdPartyApp", vcr: true do
14
+ @app_response.should_not be_nil
15
+ end
16
+
17
+ it "has apps node" do
18
+ @app_response.apps.should_not be_nil
19
+ end
20
+ end
21
+
22
+ context "#get_synced_apps" do
23
+ before do
24
+ @synced_app_response = client.get_synced_apps({authentication_token: "mqwpDx8RYcmSFBJDmy3J"})
25
+ end
26
+
27
+ it "returns JSON response of Validic::ThirdPartyApp", vcr: true do
28
+ @synced_app_response.should_not be_nil
29
+ end
30
+ end
31
+
32
+ end
@@ -0,0 +1,80 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::TobaccoCessation do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "#get_tobacco_cessation" do
9
+ before do
10
+ @tobacco_cessation = client.get_tobacco_cessations({})
11
+ end
12
+
13
+ it "returns JSON response of Validic::TobaccoCessation", vcr: true do
14
+ @tobacco_cessation.should_not be_nil
15
+ end
16
+
17
+ it "status 200" do
18
+ @tobacco_cessation.summary.status.should == 200
19
+ end
20
+
21
+ it "has summary node" do
22
+ @tobacco_cessation.summary.should_not be_nil
23
+ end
24
+ end
25
+
26
+ context "#create_tobacco_cessation" do
27
+ it "should create new tobacco_cessation record" do
28
+ @new_tobacco_cessation = client.create_tobacco_cessation({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
+ access_token: "DEMO_KEY",
30
+ timestamp: "2013-05-01 07:12:16 -05:00",
31
+ cigarettes_allowed: 10,
32
+ cigarettes_smoked: 11,
33
+ cravings: 15,
34
+ last_smoked: "2013-05-16 07:12:16 -05:00",
35
+ source: "Sample App"})
36
+ @new_tobacco_cessation.should_not be_nil
37
+ @new_tobacco_cessation.tobacco_cessation.timestamp.should eq "2013-05-01 07:12:16 -05:00"
38
+ @new_tobacco_cessation.tobacco_cessation.cigarettes_allowed.should eq 10.0
39
+ @new_tobacco_cessation.tobacco_cessation.cigarettes_smoked.should eq 11.0
40
+ @new_tobacco_cessation.tobacco_cessation.cravings.should eq 15.0
41
+ @new_tobacco_cessation.tobacco_cessation.last_smoked.should eq "2013-05-16 07:12:16 -05:00"
42
+ end
43
+ end
44
+
45
+ context "#get_tobacco_cessations by organization" do
46
+ before do
47
+ @tobacco_cessation = client.get_tobacco_cessations({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
48
+ end
49
+
50
+ it "returns JSON response of Validic::TobaccoCessation", vcr: true do
51
+ @tobacco_cessation.should_not be_nil
52
+ end
53
+
54
+ it "status 200" do
55
+ @tobacco_cessation.summary.status.should == 200
56
+ end
57
+
58
+ it "has summary node" do
59
+ @tobacco_cessation.summary.should_not be_nil
60
+ end
61
+ end
62
+
63
+ context "#get_tobacco_cessations by user" do
64
+ before do
65
+ @tobacco_cessation = client.get_tobacco_cessations({user_id: "519e24e16a7e0cc7ef00002c"})
66
+ end
67
+
68
+ it "returns JSON response of Validic::TobaccoCessation", vcr: true do
69
+ @tobacco_cessation.should_not be_nil
70
+ end
71
+
72
+ it "status 200" do
73
+ @tobacco_cessation.summary.status.should == 200
74
+ end
75
+
76
+ it "has summary node" do
77
+ @tobacco_cessation.summary.should_not be_nil
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::User do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "#me" do
9
+ before do
10
+ @me = client.me({})
11
+ end
12
+
13
+ it "returns JSON response of Validic::User", vcr: true do
14
+ @me.should_not be_nil
15
+ end
16
+
17
+ it "should return the user id" do
18
+ @me.user._id.should_not be_nil
19
+ end
20
+ end
21
+
22
+ context "#user_provisioning" do
23
+ it "should create a new user under an organization" do
24
+ @new_user = client.user_provision(organization_id: "51964ba56a7e0c2417000029",
25
+ access_token: "ENTERPRISE_KEY",
26
+ uid: "123asdfg",
27
+ height: 167,
28
+ weight: 69,
29
+ location: "TX",
30
+ gender: "M")
31
+ @new_user.users.access_token.should_not be_nil
32
+ @new_user.users.profile.height.should eq "167"
33
+ @new_user.users.profile.weight.should eq 69
34
+ @new_user.users.profile.location.should eq 'TX'
35
+ @new_user.users.profile.gender.should eq 'M'
36
+ end
37
+ end
38
+
39
+ context "#user_suspend" do
40
+ it "should suspend a user" do
41
+ @suspend_user = client.user_suspend(organization_id: "51c30eab6a7e0c1797000002",
42
+ user_id: "51c32e4d6a7e0c89cf000005",
43
+ access_token: "9c03ad2bcb022425944e4686d398ef8398f537c2f7c113495ffa7bc9cfa49286",
44
+ suspend: 1)
45
+ @suspend_user.message.should eq "The user has been suspended successfully"
46
+ end
47
+ end
48
+
49
+ end
@@ -0,0 +1,87 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic::Weight do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "#get_weights" do
9
+ before do
10
+ @weight = client.get_weights({})
11
+ end
12
+
13
+ it "returns JSON response of Validic::Weight", vcr: true do
14
+ @weight.should_not be_nil
15
+ end
16
+
17
+ it "status 200" do
18
+ @weight.summary.status.should == 200
19
+ end
20
+
21
+ it "has summary node" do
22
+ @weight.summary.should_not be_nil
23
+ end
24
+ end
25
+
26
+ context "#create_weight" do
27
+ it "should create new weight record" do
28
+ @new_weight = client.create_weight({authentication_token: "mqwpDx8RYcmSFBJDmy3J",
29
+ access_token: "DEMO_KEY",
30
+ timestamp: "2013-05-16 07:12:16 -05:00",
31
+ bmi: 133.26,
32
+ fat_percent: 130.5,
33
+ mass_weight: 139.45,
34
+ free_mass: 140.50,
35
+ weight: 69.76,
36
+ height: 167.75,
37
+ source: "Sample App"})
38
+
39
+ @new_weight.should_not be_nil
40
+ @new_weight.weight.timestamp.should eq "2013-05-16 07:12:16 -05:00"
41
+ @new_weight.weight.bmi.should eq 133.26
42
+ @new_weight.weight.fat_percent.should eq 130.5
43
+ @new_weight.weight.mass_weight.should eq 139.45
44
+ @new_weight.weight.height.should eq "167.75"
45
+ @new_weight.weight.free_mass.should eq 140.50
46
+ @new_weight.weight.weight.should eq 69.76
47
+ @new_weight.weight.source.should eq "Sample App"
48
+ end
49
+ end
50
+
51
+ context "#get_weights by organization" do
52
+ before do
53
+ @weight = client.get_weights({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
54
+ end
55
+
56
+ it "returns JSON response of Validic::Weight", vcr: true do
57
+ @weight.should_not be_nil
58
+ end
59
+
60
+ it "status 200" do
61
+ @weight.summary.status.should == 200
62
+ end
63
+
64
+ it "has summary node" do
65
+ @weight.summary.should_not be_nil
66
+ end
67
+ end
68
+
69
+ context "#get_weights by user" do
70
+ before do
71
+ @weight = client.get_weights({user_id: "519e24e16a7e0cc7ef00002c"})
72
+ end
73
+
74
+ it "returns JSON response of Validic::Weight", vcr: true do
75
+ @weight.should_not be_nil
76
+ end
77
+
78
+ it "status 200" do
79
+ @weight.summary.status.should == 200
80
+ end
81
+
82
+ it "has summary node" do
83
+ @weight.summary.should_not be_nil
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Validic do
5
+
6
+ let(:client) { Validic::Client.new }
7
+
8
+ context "configure defaults" do
9
+
10
+ it "uses default API URL" do
11
+ # client.api_url.should eq 'https://api.validic.com'
12
+ client.api_url.should eq 'http://api.validic.dev' # Development URL for local testing
13
+ end
14
+
15
+ it "uses default API VERSION" do
16
+ client.api_version.should eq 'v1'
17
+ end
18
+
19
+ end
20
+
21
+ context "handles custom configuration" do
22
+ let(:new_client) { Validic::Client.new(api_url: 'https://api.validic.net', api_version: 'v2')}#, access_token: 'MYTOKEN')}
23
+
24
+ it "::Client API_URL configuration" do
25
+ new_client.api_url.should eq 'https://api.validic.net'
26
+ end
27
+
28
+ # it "::Client ACCESS_TOKEN configuration" do
29
+ # new_client.access_token.should eq 'MYTOKEN'
30
+ # end
31
+
32
+ it "::Client API_VERSION configuration" do
33
+ new_client.api_version.should eq 'v2'
34
+ end
35
+
36
+ end
37
+
38
+ end