validic 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +80 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +7 -0
- data/lib/validic.rb +32 -0
- data/lib/validic/activity.rb +73 -0
- data/lib/validic/client.rb +74 -0
- data/lib/validic/diabetes.rb +81 -0
- data/lib/validic/fitness.rb +75 -0
- data/lib/validic/general_measurement.rb +113 -0
- data/lib/validic/nutrition.rb +81 -0
- data/lib/validic/organization.rb +46 -0
- data/lib/validic/profile.rb +43 -0
- data/lib/validic/request.rb +36 -0
- data/lib/validic/routine.rb +73 -0
- data/lib/validic/sleep.rb +77 -0
- data/lib/validic/third_party_app.rb +37 -0
- data/lib/validic/tobacco_cessation.rb +73 -0
- data/lib/validic/user.rb +71 -0
- data/lib/validic/version.rb +3 -0
- data/lib/validic/weight.rb +74 -0
- data/spec/.DS_Store +0 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/validic/activity_spec.rb +97 -0
- data/spec/validic/client_spec.rb +11 -0
- data/spec/validic/diabetes_spec.rb +88 -0
- data/spec/validic/fitness_spec.rb +84 -0
- data/spec/validic/general_measurement_spec.rb +120 -0
- data/spec/validic/nutrition_spec.rb +90 -0
- data/spec/validic/organization_spec.rb +46 -0
- data/spec/validic/profile_spec.rb +46 -0
- data/spec/validic/routine_spec.rb +81 -0
- data/spec/validic/sleep_spec.rb +85 -0
- data/spec/validic/third_party_app_spec.rb +32 -0
- data/spec/validic/tobacco_cessation_spec.rb +80 -0
- data/spec/validic/user_spec.rb +49 -0
- data/spec/validic/weight_spec.rb +87 -0
- data/spec/validic_spec.rb +38 -0
- data/validic.gemspec +37 -0
- metadata +353 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Validic
|
4
|
+
module Sleep
|
5
|
+
|
6
|
+
##
|
7
|
+
# Get Sleep 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 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
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Create Sleep 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 :total_sleep
|
48
|
+
# @params :awake
|
49
|
+
# @params :deep
|
50
|
+
# @params :light
|
51
|
+
# @params :rem
|
52
|
+
# @params :times_woken
|
53
|
+
# @params :timestamp
|
54
|
+
# @params :source
|
55
|
+
#
|
56
|
+
# @return success
|
57
|
+
def create_sleep(options={})
|
58
|
+
options = {
|
59
|
+
access_token: options[:access_token],
|
60
|
+
sleep: {
|
61
|
+
total_sleep: options[:total_sleep],
|
62
|
+
awake: options[:awake],
|
63
|
+
deep: options[:deep],
|
64
|
+
light: options[:light],
|
65
|
+
rem: options[:rem],
|
66
|
+
times_woken: options[:times_woken],
|
67
|
+
timestamp: options[:timestamp],
|
68
|
+
source: options[:source]
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
response = post("/#{Validic.api_version}/sleep.json", options)
|
73
|
+
response if response
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Validic
|
4
|
+
module ThirdPartyApp
|
5
|
+
|
6
|
+
##
|
7
|
+
# Get List of Third Party Apps available base on `access_token` and organization_id
|
8
|
+
#
|
9
|
+
# params[:organization_id] required parameter
|
10
|
+
# params[:access_token] required parameter
|
11
|
+
#
|
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
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Get User List of Third Party Synced Apps available base on `authentication_token`
|
25
|
+
#
|
26
|
+
# params[:auth_token] User authentication parameter
|
27
|
+
#
|
28
|
+
# @return [Hashie::Mash] with list of Organization
|
29
|
+
def get_synced_apps(options={})
|
30
|
+
options = {
|
31
|
+
authentication_token: options[:authentication_token]
|
32
|
+
}
|
33
|
+
response = get("/#{Validic.api_version}/sync_apps.json", options)
|
34
|
+
response if response
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Validic
|
4
|
+
module TobaccoCessation
|
5
|
+
|
6
|
+
##
|
7
|
+
# Get TobaccoCessation 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 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
|
39
|
+
end
|
40
|
+
|
41
|
+
##
|
42
|
+
# Create TobaccoCessation 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 :cigarettes_allowed
|
48
|
+
# @params :cigarettes_smoked
|
49
|
+
# @params :cravings
|
50
|
+
# @params :last_smoked
|
51
|
+
# @params :timestamp
|
52
|
+
# @params :source
|
53
|
+
#
|
54
|
+
# @return success
|
55
|
+
def create_tobacco_cessation(options={})
|
56
|
+
options = {
|
57
|
+
access_token: options[:access_token],
|
58
|
+
tobacco_cessation: {
|
59
|
+
cigarettes_allowed: options[:cigarettes_allowed],
|
60
|
+
cigarettes_smoked: options[:cigarettes_smoked],
|
61
|
+
cravings: options[:cravings],
|
62
|
+
last_smoked: options[:last_smoked],
|
63
|
+
timestamp: options[:timestamp],
|
64
|
+
source: options[:source]
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
response = post("/#{Validic.api_version}/tobacco_cessation.json", options)
|
69
|
+
response if response
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
end
|
data/lib/validic/user.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Validic
|
4
|
+
module User
|
5
|
+
|
6
|
+
##
|
7
|
+
# Get User id base on `access_token`
|
8
|
+
#
|
9
|
+
# @return id
|
10
|
+
def me(options={})
|
11
|
+
options = {
|
12
|
+
access_token: options[:access_token]
|
13
|
+
}
|
14
|
+
response = get("/#{Validic.api_version}/me.json", options)
|
15
|
+
response if response
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# POST User info for provisioning base on `access_token`
|
20
|
+
#
|
21
|
+
# @params[:organization_id] -- organization_id -- String
|
22
|
+
# @params[:access_token] -- organization's access_token -- String
|
23
|
+
# @params[:uid] -- uid for the new user -- String
|
24
|
+
# @params[:height] -- info for user -- Integer
|
25
|
+
# @params[:weight] -- info for user -- String
|
26
|
+
# @params[:location] -- info for user -- String
|
27
|
+
# @params[:gender] -- info for user -- String
|
28
|
+
# @params[:birth_year] -- info for user -- String
|
29
|
+
#
|
30
|
+
# @return user object
|
31
|
+
def user_provision(options={})
|
32
|
+
organization_id = options[:organization_id]
|
33
|
+
options = {
|
34
|
+
access_token: options[:access_token],
|
35
|
+
user: {
|
36
|
+
uid: options[:uid],
|
37
|
+
profile: {
|
38
|
+
height: options[:height],
|
39
|
+
gender: options[:gender],
|
40
|
+
location: options[:location],
|
41
|
+
weight: options[:weight]
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
response = post("/#{Validic.api_version}/organizations/#{organization_id}/users.json", options)
|
46
|
+
response if response
|
47
|
+
end
|
48
|
+
|
49
|
+
##
|
50
|
+
#
|
51
|
+
# PUT request for suspending a user
|
52
|
+
#
|
53
|
+
# @params[:organization_id] -- String
|
54
|
+
# @params[:access_token] -- String -- organization's access_token
|
55
|
+
# @params[:user_id] -- String -- user's ID to suspend
|
56
|
+
# @params[:suspend] -- Boolean -- (1/0)
|
57
|
+
#
|
58
|
+
# @return user object
|
59
|
+
def user_suspend(options={})
|
60
|
+
organization_id = options[:organization_id]
|
61
|
+
user_id = options[:user_id]
|
62
|
+
options = {
|
63
|
+
suspend: options[:suspend],
|
64
|
+
access_token: options[:access_token]
|
65
|
+
}
|
66
|
+
|
67
|
+
response = put("/#{Validic.api_version}/organizations/#{organization_id}/users/#{user_id}.json", options)
|
68
|
+
response
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Validic
|
4
|
+
module Weight
|
5
|
+
|
6
|
+
##
|
7
|
+
# Get Weight 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 for date range beyond yesterday
|
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 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
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Create Weight base on `access_token` and `authentication_token`
|
42
|
+
#
|
43
|
+
# @params :access_token - *required if not specified on your initializer / organization access_token
|
44
|
+
# @params :authentication_token - *required / authentication_token of a specific user
|
45
|
+
#
|
46
|
+
# @params :timestamp
|
47
|
+
# @params :weight
|
48
|
+
# @params :bmi
|
49
|
+
# @params :fat_percent
|
50
|
+
# @params :mass_weight
|
51
|
+
# @params :free_mass
|
52
|
+
# @params :source
|
53
|
+
#
|
54
|
+
# @return success
|
55
|
+
def create_weight(options={})
|
56
|
+
options = {
|
57
|
+
access_token: options[:access_token],
|
58
|
+
weight: {
|
59
|
+
timestamp: options[:timestamp],
|
60
|
+
weight: options[:weight],
|
61
|
+
bmi: options[:bmi],
|
62
|
+
fat_percent: options[:fat_percent],
|
63
|
+
mass_weight: options[:mass_weight],
|
64
|
+
free_mass: options[:free_mass],
|
65
|
+
source: options[:source]
|
66
|
+
}
|
67
|
+
}
|
68
|
+
|
69
|
+
response = post("/#{Validic.api_version}/weight.json", options)
|
70
|
+
response if response
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/spec/.DS_Store
ADDED
Binary file
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'validic'
|
2
|
+
require 'vcr'
|
3
|
+
require 'simplecov'
|
4
|
+
require 'simplecov-rcov'
|
5
|
+
require 'api_matchers'
|
6
|
+
|
7
|
+
class SimpleCov::Formatter::MergedFormatter
|
8
|
+
def format(result)
|
9
|
+
SimpleCov::Formatter::HTMLFormatter.new.format(result)
|
10
|
+
SimpleCov::Formatter::RcovFormatter.new.format(result)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
SimpleCov.formatter = SimpleCov::Formatter::MergedFormatter
|
15
|
+
SimpleCov.start do
|
16
|
+
add_filter '/vendor'
|
17
|
+
end
|
18
|
+
|
19
|
+
VCR.configure do |c|
|
20
|
+
c.allow_http_connections_when_no_cassette = true
|
21
|
+
c.cassette_library_dir = 'spec/cassette'
|
22
|
+
c.hook_into :webmock
|
23
|
+
c.configure_rspec_metadata!
|
24
|
+
c.default_cassette_options = { record: :new_episodes }
|
25
|
+
end
|
26
|
+
|
27
|
+
RSpec.configure do |c|
|
28
|
+
c.include APIMatchers::RSpecMatchers
|
29
|
+
|
30
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
31
|
+
|
32
|
+
##
|
33
|
+
# Add gem specific configuration for easy access
|
34
|
+
#
|
35
|
+
c.before(:each) do
|
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'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Validic::Activity do
|
5
|
+
|
6
|
+
let(:client) { Validic::Client.new }
|
7
|
+
|
8
|
+
context "#get_activities" do
|
9
|
+
before do
|
10
|
+
@activities_response = client.get_activities({})
|
11
|
+
end
|
12
|
+
|
13
|
+
it "returns JSON response of Validic::Activity", vcr: true do
|
14
|
+
@activities_response.should_not be_nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "status 200" do
|
18
|
+
@activities_response.summary.status.should == 200
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has summary node" do
|
22
|
+
@activities_response.summary.should_not be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context "#get_activities via organization" do
|
27
|
+
before do
|
28
|
+
@activities_response = client.get_activities({organization_id: "519e24e16a7e0cc7ef00002b", access_token: "ENTERPRISE_KEY"})
|
29
|
+
end
|
30
|
+
|
31
|
+
it "returns JSON response of Validic::Activity", vcr: true do
|
32
|
+
@activities_response.should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it "status 200" do
|
36
|
+
@activities_response.summary.status.should == 200
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has summary node" do
|
40
|
+
@activities_response.summary.should_not be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "#get_activities of a user" do
|
45
|
+
before do
|
46
|
+
@activities_response = client.get_activities({user_id: "519e24e16a7e0cc7ef00002c"})
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns JSON response of Validic::Activity", vcr: true do
|
50
|
+
@activities_response.should_not be_nil
|
51
|
+
end
|
52
|
+
|
53
|
+
it "status 200" do
|
54
|
+
@activities_response.summary.status.should == 200
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has summary node" do
|
58
|
+
@activities_response.summary.should_not be_nil
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "#get_latest_activities of a user base on activity_type" do
|
63
|
+
before do
|
64
|
+
@latest_activities_response = client.get_latest_activities(user_id: "519e24e16a7e0cc7ef00002c", access_token: "9c03ad2bcb022425944e4686d398ef8398f537c2f7c113495ffa7bc9cfa49286", activity_type: "routine")
|
65
|
+
end
|
66
|
+
|
67
|
+
it "returns JSON response of Validic::Activity", vcr: true do
|
68
|
+
@latest_activities_response.should_not be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
it "status 200" do
|
72
|
+
@latest_activities_response.summary.status.should == 200
|
73
|
+
end
|
74
|
+
|
75
|
+
it "has summary node" do
|
76
|
+
@latest_activities_response.summary.should_not be_nil
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
context "#get_latest_activities of an organization base on activity_type" do
|
81
|
+
before do
|
82
|
+
@latest_activities_response = client.get_latest_activities(organization_id: "519e24e16a7e0cc7ef00002b", activity_type: "routine", access_token: "296a9c1d73c1b40af4c8e643336cb25524caf2a7679ba92c192855160572fdb1")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "returns JSON response of Validic::Activity", vcr: true do
|
86
|
+
@latest_activities_response.should_not be_nil
|
87
|
+
end
|
88
|
+
|
89
|
+
it "status 200" do
|
90
|
+
@latest_activities_response.summary.status.should == 200
|
91
|
+
end
|
92
|
+
|
93
|
+
it "has summary node" do
|
94
|
+
@latest_activities_response.summary.should_not be_nil
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|