validic 0.4.1 → 0.5.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Gemfile.lock +7 -4
- data/README.md +17 -8
- data/lib/validic/client.rb +6 -6
- data/lib/validic/error.rb +2 -0
- data/lib/validic/response.rb +44 -5
- data/lib/validic/rest/apps.rb +4 -6
- data/lib/validic/rest/biometrics.rb +2 -4
- data/lib/validic/rest/diabetes.rb +2 -4
- data/lib/validic/rest/fitness.rb +2 -4
- data/lib/validic/rest/nutrition.rb +2 -4
- data/lib/validic/rest/organizations.rb +1 -2
- data/lib/validic/rest/response.rb +13 -0
- data/lib/validic/rest/routine.rb +2 -4
- data/lib/validic/rest/sleep.rb +2 -4
- data/lib/validic/rest/tobacco_cessation.rb +2 -4
- data/lib/validic/rest/users.rb +1 -2
- data/lib/validic/rest/weight.rb +2 -6
- data/lib/validic/summary.rb +1 -0
- data/lib/validic/version.rb +1 -1
- data/spec/fixtures/invalid_date.json +1 -0
- data/spec/fixtures/routines.json +1 -2
- data/spec/fixtures/routines2.json +46 -0
- data/spec/validic/client_spec.rb +36 -1
- data/spec/validic/error_spec.rb +16 -0
- data/spec/validic/response_spec.rb +39 -0
- data/spec/validic/rest/apps_spec.rb +32 -13
- data/spec/validic/summary_spec.rb +13 -0
- metadata +21 -14
- data/lib/validic/rest/utils.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 126d89621c9028f5e07f6988e1d460d273f864b2
|
4
|
+
data.tar.gz: cfd36bbb933bb2e10d239a049bb6dbd375c3ca16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6c77c1e8227a18bbff2bc64d9fa4d3a160fa8803707bf7db7635d2dfd648cdfe00d4bcfc36231a68a661f8038648cc1d19c7363f1dfb26d5d418e6ef4682dcce
|
7
|
+
data.tar.gz: a94a08ba6093f64a15f8e60b52e0fdbf05de887c86cb52b2b98b4bf06c0a354c8f8341eff5e82c9081749ccbc45add1a82cfba258c68a797abb7f994cfb83a6e
|
data/CHANGELOG.md
ADDED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
validic (0.
|
4
|
+
validic (0.5.0)
|
5
5
|
faraday_middleware (~> 0.9.0)
|
6
6
|
multi_json
|
7
7
|
|
@@ -13,12 +13,12 @@ GEM
|
|
13
13
|
crack (0.4.2)
|
14
14
|
safe_yaml (~> 1.0.0)
|
15
15
|
diff-lcs (1.2.5)
|
16
|
-
faraday (0.9.
|
16
|
+
faraday (0.9.2)
|
17
17
|
multipart-post (>= 1.2, < 3)
|
18
|
-
faraday_middleware (0.9.
|
18
|
+
faraday_middleware (0.9.2)
|
19
19
|
faraday (>= 0.7.4, < 0.10)
|
20
20
|
method_source (0.8.2)
|
21
|
-
multi_json (1.11.
|
21
|
+
multi_json (1.11.2)
|
22
22
|
multipart-post (2.0.0)
|
23
23
|
pry (0.10.1)
|
24
24
|
coderay (~> 1.1.0)
|
@@ -55,3 +55,6 @@ DEPENDENCIES
|
|
55
55
|
validic!
|
56
56
|
webmock (~> 1.20.4)
|
57
57
|
yard
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
1.10.6
|
data/README.md
CHANGED
@@ -71,7 +71,7 @@ require 'validic'
|
|
71
71
|
Validic.configure do |config|
|
72
72
|
config.api_url = 'https://api.validic.com'
|
73
73
|
config.api_version = 'v1'
|
74
|
-
config.access_token = 'ORGANIZATION_ACCESS_TOKEN'
|
74
|
+
config.access_token = 'ORGANIZATION_ACCESS_TOKEN'
|
75
75
|
config.organization_id = 'ORGANIZATION_ID'
|
76
76
|
end
|
77
77
|
|
@@ -88,7 +88,7 @@ options = {
|
|
88
88
|
access_token: 'ORGANIZATION_ACCESS_TOKEN',
|
89
89
|
organization_id: 'ORGANIZATION_ID'
|
90
90
|
}
|
91
|
-
client = Validic::Client.new
|
91
|
+
client = Validic::Client.new(options)
|
92
92
|
```
|
93
93
|
|
94
94
|
Now you can use the wrapper's helper methods to interface with the Validic API.
|
@@ -112,9 +112,6 @@ client.get_routine(start_date: '2015-01-01T00:00:00+00:00')
|
|
112
112
|
|
113
113
|
### More Examples ###
|
114
114
|
|
115
|
-
You can override initialized organization id and access tokens for all helper
|
116
|
-
methods by passing parameters in an options hash as a final parameter.
|
117
|
-
|
118
115
|
Below are examples of all helper methods.
|
119
116
|
|
120
117
|
```ruby
|
@@ -230,7 +227,7 @@ client.get_users(user_id: '5499a29b84626b0339000094')
|
|
230
227
|
client.refresh_token(user_id: '5499a29b84626b0339000094')
|
231
228
|
```
|
232
229
|
|
233
|
-
##### Get
|
230
|
+
##### Get user_id from authentication token
|
234
231
|
```ruby
|
235
232
|
client.me(authentication_token: 'L9RFSRnJvkwfiZm8vEc4')
|
236
233
|
```
|
@@ -338,15 +335,27 @@ client.get_sleep
|
|
338
335
|
client.get_tobacco_cessations
|
339
336
|
```
|
340
337
|
|
338
|
+
##### Get the next page of a Validic::Response
|
339
|
+
```ruby
|
340
|
+
data = client.get_routine(start_date: '2013-01-01', paginated: "true")
|
341
|
+
data.next
|
342
|
+
```
|
343
|
+
|
344
|
+
##### Get the previous page of a Validic::Response
|
345
|
+
```ruby
|
346
|
+
data = client.get_routine(start_date: '2013-01-01', paginated: "true", page: 3)
|
347
|
+
data.previous
|
348
|
+
```
|
349
|
+
|
341
350
|
## [Validic Connect](https://validic.com/api/partners)
|
342
351
|
|
343
352
|
|
344
353
|
##### CRUD Operations
|
345
|
-
As a Validic Connect partner you have access to all CRUD operations
|
354
|
+
As a Validic Connect partner you have access to all CRUD operations.
|
346
355
|
|
347
356
|
**Create**
|
348
357
|
```ruby
|
349
|
-
client.create_sleep(user_id: 'VALIDIC_USER_ID, activity_id: 'UNIQUE_ACTIVITY_ID', awake: 2, rem: 1, deep: 7)
|
358
|
+
client.create_sleep(user_id: 'VALIDIC_USER_ID', activity_id: 'UNIQUE_ACTIVITY_ID', awake: 2, rem: 1, deep: 7)
|
350
359
|
=> #<Validic::Sleep:0x007fafcc2cdd40
|
351
360
|
@_id="54b93e1b84626b0581000012",
|
352
361
|
@activity_id="22323",
|
data/lib/validic/client.rb
CHANGED
@@ -9,11 +9,11 @@ require 'validic/rest/nutrition'
|
|
9
9
|
require 'validic/rest/organizations'
|
10
10
|
require 'validic/rest/profile'
|
11
11
|
require 'validic/rest/request'
|
12
|
+
require 'validic/rest/response'
|
12
13
|
require 'validic/rest/routine'
|
13
14
|
require 'validic/rest/sleep'
|
14
15
|
require 'validic/rest/tobacco_cessation'
|
15
16
|
require 'validic/rest/users'
|
16
|
-
require 'validic/rest/utils'
|
17
17
|
require 'validic/rest/weight'
|
18
18
|
require 'validic/version'
|
19
19
|
|
@@ -27,11 +27,11 @@ module Validic
|
|
27
27
|
include REST::Organizations
|
28
28
|
include REST::Profile
|
29
29
|
include REST::Request
|
30
|
+
include REST::Response
|
30
31
|
include REST::Routine
|
31
32
|
include REST::Sleep
|
32
33
|
include REST::TobaccoCessation
|
33
34
|
include REST::Users
|
34
|
-
include REST::Utils
|
35
35
|
include REST::Weight
|
36
36
|
|
37
37
|
attr_accessor :api_url,
|
@@ -44,10 +44,10 @@ module Validic
|
|
44
44
|
#
|
45
45
|
# @params options[Hash]
|
46
46
|
def initialize(options={})
|
47
|
-
@api_url
|
48
|
-
@api_version
|
49
|
-
@access_token
|
50
|
-
@organization_id
|
47
|
+
@api_url = options.fetch(:api_url, 'https://api.validic.com')
|
48
|
+
@api_version = options.fetch(:api_version, 'v1')
|
49
|
+
@access_token = options.fetch(:access_token, Validic.access_token)
|
50
|
+
@organization_id = options.fetch(:organization_id, Validic.organization_id)
|
51
51
|
reload_config
|
52
52
|
end
|
53
53
|
|
data/lib/validic/error.rb
CHANGED
@@ -9,11 +9,13 @@ module Validic
|
|
9
9
|
UnprocessableEntity = Class.new(ClientError)
|
10
10
|
Conflict = Class.new(ClientError)
|
11
11
|
InternalServerError = Class.new(ServerError)
|
12
|
+
InvalidDate = Class.new(ClientError)
|
12
13
|
|
13
14
|
ERRORS = {
|
14
15
|
401 => Validic::Error::Unauthorized,
|
15
16
|
403 => Validic::Error::Forbidden,
|
16
17
|
404 => Validic::Error::NotFound,
|
18
|
+
406 => Validic::Error::InvalidDate,
|
17
19
|
409 => Validic::Error::Conflict,
|
18
20
|
422 => Validic::Error::UnprocessableEntity,
|
19
21
|
500 => Validic::Error::InternalServerError
|
data/lib/validic/response.rb
CHANGED
@@ -1,15 +1,54 @@
|
|
1
|
+
require 'validic/summary'
|
2
|
+
|
1
3
|
module Validic
|
2
4
|
class Response
|
5
|
+
include REST::Request
|
3
6
|
attr_reader :summary, :records, :attributes
|
4
|
-
def initialize(summary, response)
|
5
|
-
@summary = summary
|
6
7
|
|
7
|
-
|
8
|
+
def initialize(response, connection = nil)
|
9
|
+
@connection = connection
|
10
|
+
@summary = summary_object(response)
|
11
|
+
case resp = response_object(response)
|
8
12
|
when Array
|
9
|
-
@records =
|
13
|
+
@records = resp
|
10
14
|
when Hash
|
11
|
-
@attributes =
|
15
|
+
@attributes = resp
|
12
16
|
end
|
13
17
|
end
|
18
|
+
|
19
|
+
def next
|
20
|
+
return nil unless next_url = summary.next
|
21
|
+
resp = get(next_url, {})
|
22
|
+
self.class.new(resp, connection)
|
23
|
+
end
|
24
|
+
|
25
|
+
def previous
|
26
|
+
return nil unless previous_url = summary.previous
|
27
|
+
resp = get(previous_url, {})
|
28
|
+
self.class.new(resp, connection)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def connection
|
34
|
+
@connection
|
35
|
+
end
|
36
|
+
|
37
|
+
def summary_object(resp)
|
38
|
+
Validic::Summary.new(resp.delete("summary"))
|
39
|
+
end
|
40
|
+
|
41
|
+
def response_object(resp)
|
42
|
+
return resp.values.first if resp.values.first.is_a? Hash
|
43
|
+
klass = Validic.const_get(camelize_response_key(resp))
|
44
|
+
resp.values.flatten.collect { |obj| klass.new(obj) }
|
45
|
+
end
|
46
|
+
|
47
|
+
def camelize_response_key(resp)
|
48
|
+
key = resp.keys.first
|
49
|
+
key = key.include?('_') ? key.split('_').map(&:capitalize).join : key.capitalize
|
50
|
+
key.chop! if %w(Users Apps).include?(key) #strip last letter off to match ::User or ::App
|
51
|
+
key
|
52
|
+
end
|
14
53
|
end
|
15
54
|
end
|
data/lib/validic/rest/apps.rb
CHANGED
@@ -4,16 +4,14 @@ module Validic
|
|
4
4
|
module REST
|
5
5
|
module Apps
|
6
6
|
|
7
|
-
def get_org_apps
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
7
|
+
def get_org_apps(params = {})
|
8
|
+
build_response(get_request(:apps, params))
|
10
9
|
end
|
11
10
|
alias :get_apps :get_org_apps
|
12
11
|
|
13
12
|
def get_user_synced_apps(options = {})
|
14
|
-
|
15
|
-
authentication_token: options[:authentication_token])
|
16
|
-
build_response_attr(resp)
|
13
|
+
build_response(get_request(:sync_apps,
|
14
|
+
authentication_token: options[:authentication_token]))
|
17
15
|
end
|
18
16
|
alias :get_synced_apps :get_user_synced_apps
|
19
17
|
end
|
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module Biometrics
|
6
6
|
|
7
7
|
def get_biometrics(options = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:biometrics, options))
|
10
9
|
end
|
11
10
|
|
12
11
|
def create_biometrics(options = {})
|
@@ -31,8 +30,7 @@ module Validic
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def latest_biometrics(options = {})
|
34
|
-
|
35
|
-
build_response_attr(resp)
|
33
|
+
build_response(latest(:biometrics, options))
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module Diabetes
|
6
6
|
|
7
7
|
def get_diabetes(options = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:diabetes, options))
|
10
9
|
end
|
11
10
|
|
12
11
|
def create_diabetes(options = {})
|
@@ -31,8 +30,7 @@ module Validic
|
|
31
30
|
end
|
32
31
|
|
33
32
|
def latest_diabetes(options = {})
|
34
|
-
|
35
|
-
build_response_attr(resp)
|
33
|
+
build_response(latest(:diabetes, options))
|
36
34
|
end
|
37
35
|
end
|
38
36
|
end
|
data/lib/validic/rest/fitness.rb
CHANGED
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module Fitness
|
6
6
|
|
7
7
|
def get_fitness(options = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:fitness, options))
|
10
9
|
end
|
11
10
|
alias :get_fitnesses :get_fitness
|
12
11
|
|
@@ -32,8 +31,7 @@ module Validic
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def latest_fitness(options = {})
|
35
|
-
|
36
|
-
build_response_attr(resp)
|
34
|
+
build_response(latest(:fitness, options))
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module Nutrition
|
6
6
|
|
7
7
|
def get_nutrition(options = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:nutrition, options))
|
10
9
|
end
|
11
10
|
alias :get_nutritions :get_nutrition
|
12
11
|
|
@@ -32,8 +31,7 @@ module Validic
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def latest_nutrition(options = {})
|
35
|
-
|
36
|
-
build_response_attr(resp)
|
34
|
+
build_response(latest(:nutrition, options))
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/validic/rest/routine.rb
CHANGED
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module Routine
|
6
6
|
|
7
7
|
def get_routine(params = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:routine, params))
|
10
9
|
end
|
11
10
|
alias :get_routines :get_routine
|
12
11
|
|
@@ -32,8 +31,7 @@ module Validic
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def latest_routine(options = {})
|
35
|
-
|
36
|
-
build_response_attr(resp)
|
34
|
+
build_response(latest(:routine, options))
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/validic/rest/sleep.rb
CHANGED
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module Sleep
|
6
6
|
|
7
7
|
def get_sleep(options = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:sleep, options))
|
10
9
|
end
|
11
10
|
alias :get_sleeps :get_sleep
|
12
11
|
|
@@ -25,8 +24,7 @@ module Validic
|
|
25
24
|
end
|
26
25
|
|
27
26
|
def latest_sleep(options = {})
|
28
|
-
|
29
|
-
build_response_attr(resp)
|
27
|
+
build_response(latest(:sleep, options))
|
30
28
|
end
|
31
29
|
|
32
30
|
def delete_sleep(options = {})
|
@@ -5,8 +5,7 @@ module Validic
|
|
5
5
|
module TobaccoCessation
|
6
6
|
|
7
7
|
def get_tobacco_cessation(options = {})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:tobacco_cessation, options))
|
10
9
|
end
|
11
10
|
alias :get_tobacco_cessations :get_tobacco_cessation
|
12
11
|
|
@@ -32,8 +31,7 @@ module Validic
|
|
32
31
|
end
|
33
32
|
|
34
33
|
def latest_tobacco_cessation(options = {})
|
35
|
-
|
36
|
-
build_response_attr(resp)
|
34
|
+
build_response(latest(:tobacco_cessation, options))
|
37
35
|
end
|
38
36
|
end
|
39
37
|
end
|
data/lib/validic/rest/users.rb
CHANGED
data/lib/validic/rest/weight.rb
CHANGED
@@ -5,10 +5,8 @@ module Validic
|
|
5
5
|
module Weight
|
6
6
|
|
7
7
|
def get_weight(params={})
|
8
|
-
|
9
|
-
build_response_attr(resp)
|
8
|
+
build_response(get_request(:weight, params))
|
10
9
|
end
|
11
|
-
|
12
10
|
alias :get_weights :get_weight
|
13
11
|
|
14
12
|
def create_weight(options={})
|
@@ -34,10 +32,8 @@ module Validic
|
|
34
32
|
end
|
35
33
|
|
36
34
|
def latest_weight(options={})
|
37
|
-
|
38
|
-
build_response_attr(resp)
|
35
|
+
build_response(latest(:weight, options))
|
39
36
|
end
|
40
|
-
|
41
37
|
end
|
42
38
|
end
|
43
39
|
end
|
data/lib/validic/summary.rb
CHANGED
@@ -3,6 +3,7 @@ module Validic
|
|
3
3
|
attr_reader :timestamp, :start_date, :end_date, :offset, :message,
|
4
4
|
:results, :limit, :previous, :next, :status
|
5
5
|
def initialize(sum_hash)
|
6
|
+
sum_hash = Hash(sum_hash)
|
6
7
|
@timestamp = sum_hash["timestamp"]
|
7
8
|
@status = sum_hash["status"]
|
8
9
|
@offset = sum_hash["offset"]
|
data/lib/validic/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"code": 406, "message": "Not Acceptable", "errors": ["Invalid date"]}
|
data/spec/fixtures/routines.json
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
"offset": 0,
|
9
9
|
"limit": 100,
|
10
10
|
"previous": null,
|
11
|
-
"next":
|
11
|
+
"next": "https://api.validic.com/v1/organizations/1/routine.json?access_token=1&paginated=true&start_date=2013-01-01&page=2",
|
12
12
|
"params": {
|
13
13
|
"start_date": null,
|
14
14
|
"end_date": null,
|
@@ -44,4 +44,3 @@
|
|
44
44
|
}
|
45
45
|
]
|
46
46
|
}
|
47
|
-
|
@@ -0,0 +1,46 @@
|
|
1
|
+
{
|
2
|
+
"summary": {
|
3
|
+
"status": 200,
|
4
|
+
"message": "OK",
|
5
|
+
"results": 3,
|
6
|
+
"start_date": "2013-03-27T00:00:00+00:00",
|
7
|
+
"end_date": "2013-03-27T23:59:59+00:00",
|
8
|
+
"offset": 0,
|
9
|
+
"limit": 100,
|
10
|
+
"previous": "https://api.validic.com/v1/organizations/1/routine.json?access_token=1&paginated=true&start_date=2013-01-01&page=1",
|
11
|
+
"next": null,
|
12
|
+
"params": {
|
13
|
+
"start_date": null,
|
14
|
+
"end_date": null,
|
15
|
+
"offset": null,
|
16
|
+
"limit": null
|
17
|
+
}
|
18
|
+
},"routine": [
|
19
|
+
{
|
20
|
+
"_id": "51552cdbfded0807c4000062",
|
21
|
+
"timestamp": "2013-03-10T07:12:16+00:00",
|
22
|
+
"utc_offset": "+00:00",
|
23
|
+
"steps": 9355,
|
24
|
+
"distance": 7290.33,
|
25
|
+
"floors": 23,
|
26
|
+
"elevation": 3.4,
|
27
|
+
"calories_burned": 2874,
|
28
|
+
"source": "sample_app",
|
29
|
+
"source_name": "Sample App",
|
30
|
+
"last_updated": "2013-03-10T07:12:16+00:00"
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"_id": "51552cdbfded0807c4000062",
|
34
|
+
"timestamp": "2013-03-10T07:12:16+00:00",
|
35
|
+
"utc_offset": "+00:00",
|
36
|
+
"steps": 9355,
|
37
|
+
"distance": 7290.33,
|
38
|
+
"floors": 23,
|
39
|
+
"elevation": 3.4,
|
40
|
+
"calories_burned": 2874,
|
41
|
+
"source": "sample_app",
|
42
|
+
"source_name": "Sample App",
|
43
|
+
"last_updated": "2013-03-10T07:12:16+00:00"
|
44
|
+
}
|
45
|
+
]
|
46
|
+
}
|
data/spec/validic/client_spec.rb
CHANGED
@@ -2,9 +2,44 @@
|
|
2
2
|
require 'spec_helper'
|
3
3
|
|
4
4
|
describe Validic::Client do
|
5
|
-
|
5
|
+
|
6
|
+
describe '#initialize' do
|
7
|
+
before(:each) do
|
8
|
+
Validic.configure do |config|
|
9
|
+
config.access_token = '1234'
|
10
|
+
config.organization_id = 1
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'uses defaults' do
|
15
|
+
client = Validic::Client.new
|
16
|
+
|
17
|
+
expect(client.api_url).to eq 'https://api.validic.com'
|
18
|
+
expect(client.api_version).to eq 'v1'
|
19
|
+
expect(client.access_token).to eq '1234'
|
20
|
+
expect(client.organization_id).to eq 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'uses options' do
|
24
|
+
opts = {
|
25
|
+
api_url: 'http://test.example.com',
|
26
|
+
api_version: 'v2',
|
27
|
+
access_token: 'abcd',
|
28
|
+
organization_id: 2
|
29
|
+
}
|
30
|
+
|
31
|
+
client = Validic::Client.new(opts)
|
32
|
+
|
33
|
+
expect(client.api_url).to eq 'http://test.example.com'
|
34
|
+
expect(client.api_version).to eq 'v2'
|
35
|
+
expect(client.access_token).to eq 'abcd'
|
36
|
+
expect(client.organization_id).to eq 2
|
37
|
+
end
|
38
|
+
end
|
6
39
|
|
7
40
|
describe '#connection' do
|
41
|
+
let(:client) { Validic::Client.new }
|
42
|
+
|
8
43
|
it 'returns a Faraday::Connection object' do
|
9
44
|
expect(client.connection).to be_kind_of Faraday::Connection
|
10
45
|
end
|
data/spec/validic/error_spec.rb
CHANGED
@@ -70,4 +70,20 @@ describe Validic::Error do
|
|
70
70
|
expect { client.get_profile }.to raise_error(Validic::Error::Unauthorized)
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
context 'Invalid date' do
|
75
|
+
before do
|
76
|
+
stub_request(:get, /fitness/)
|
77
|
+
.to_return(status: 406, body: fixture('invalid_date.json'),
|
78
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
79
|
+
end
|
80
|
+
it 'raises an InvalidDate error' do
|
81
|
+
start_date = DateTime.new(2015, 07, 15, 12)
|
82
|
+
end_date = DateTime.new(2015, 07, 15, 13)
|
83
|
+
|
84
|
+
expect {
|
85
|
+
client.get_fitness(start_date: start_date, end_date: end_date)
|
86
|
+
}.to raise_error Validic::Error::InvalidDate
|
87
|
+
end
|
88
|
+
end
|
73
89
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Validic::Response do
|
4
|
+
let(:client) { Validic::Client.new }
|
5
|
+
|
6
|
+
describe "Validic::Response next/previous" do
|
7
|
+
before do
|
8
|
+
stub_get('/organizations/1/routine.json')
|
9
|
+
.with(query: { access_token: '1' })
|
10
|
+
.to_return(body: fixture('routines.json'),
|
11
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
12
|
+
stub_get('/organizations/1/routine.json')
|
13
|
+
.with(query: { access_token: '1', page: '2', paginated: 'true', start_date: '2013-01-01' })
|
14
|
+
.to_return(body: fixture('routines2.json'),
|
15
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
16
|
+
stub_get('/organizations/1/routine.json')
|
17
|
+
.with(query: { access_token: '1', page: '1', paginated: 'true', start_date: '2013-01-01' })
|
18
|
+
.to_return(body: fixture('routines.json'),
|
19
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
20
|
+
end
|
21
|
+
it "makes a #next call" do
|
22
|
+
routine = client.get_routine
|
23
|
+
expect(routine).to be_a Validic::Response
|
24
|
+
|
25
|
+
next_call = routine.next
|
26
|
+
expect(next_call).to be_a Validic::Response
|
27
|
+
expect(next_call.records.size).to eq 2
|
28
|
+
end
|
29
|
+
it "makes a #previous call" do
|
30
|
+
routine = client.get_routine
|
31
|
+
expect(routine).to be_a Validic::Response
|
32
|
+
next_call = routine.next
|
33
|
+
previous_call = next_call.previous
|
34
|
+
|
35
|
+
expect(previous_call).to be_a Validic::Response
|
36
|
+
expect(previous_call.records.size).to eq 2
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -4,19 +4,38 @@ describe Validic::REST::Apps do
|
|
4
4
|
let(:client) { Validic::Client.new }
|
5
5
|
|
6
6
|
describe "#get_apps" do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
7
|
+
context 'non-expanded' do
|
8
|
+
before do
|
9
|
+
stub_get("/organizations/1/apps.json")
|
10
|
+
.with(query: { access_token: '1' })
|
11
|
+
.to_return(body: fixture('apps.json'),
|
12
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
13
|
+
@apps = client.get_org_apps
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'returns a response object' do
|
17
|
+
expect(@apps).to be_a Validic::Response
|
18
|
+
end
|
19
|
+
it 'makes an apps request to the correct url' do
|
20
|
+
expect(a_get('/organizations/1/apps.json')
|
21
|
+
.with(query: { access_token: '1' })).to have_been_made
|
22
|
+
end
|
16
23
|
end
|
17
|
-
|
18
|
-
|
19
|
-
|
24
|
+
context 'expanded' do
|
25
|
+
before do
|
26
|
+
stub_get("/organizations/1/apps.json")
|
27
|
+
.with(query: { access_token: '1', expanded: 1 })
|
28
|
+
.to_return(body: fixture('apps.json'),
|
29
|
+
headers: { content_type: 'application/json; charset=utf-8' })
|
30
|
+
@apps = client.get_org_apps(expanded: 1)
|
31
|
+
end
|
32
|
+
it 'returns a response object' do
|
33
|
+
expect(@apps).to be_a Validic::Response
|
34
|
+
end
|
35
|
+
it 'makes an apps request to the correct url' do
|
36
|
+
expect(a_get('/organizations/1/apps.json')
|
37
|
+
.with(query: { access_token: '1', expanded: '1' })).to have_been_made
|
38
|
+
end
|
20
39
|
end
|
21
40
|
end
|
22
41
|
|
@@ -26,7 +45,7 @@ describe Validic::REST::Apps do
|
|
26
45
|
.with(query: { authentication_token: '2', access_token: '1' })
|
27
46
|
.to_return(body: fixture('synced_apps.json'),
|
28
47
|
headers: { content_type: 'application/json; charset=utf-8' })
|
29
|
-
|
48
|
+
@synced_apps = client.get_user_synced_apps(authentication_token: '2')
|
30
49
|
end
|
31
50
|
it 'returns a response object' do
|
32
51
|
expect(@synced_apps).to be_a Validic::Response
|
@@ -1,3 +1,16 @@
|
|
1
1
|
describe Validic::Summary do
|
2
2
|
|
3
|
+
describe "#initialize" do
|
4
|
+
it "does not raise error with nil sum_hash" do
|
5
|
+
expect { Validic::Summary.new(nil) }.to_not raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
it "sets all attributes to nil if initialized with nil sum_hash" do
|
9
|
+
summary = Validic::Summary.new(nil)
|
10
|
+
|
11
|
+
%w(timestamp start_date end_date offset message results limit previous next status).each do |message|
|
12
|
+
expect(summary.send(message)).to be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
3
16
|
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julius Francisco & Jay Balanay
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday_middleware
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.9.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.9.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: multi_json
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
description: API Wrapper for Validic
|
@@ -60,8 +60,9 @@ executables: []
|
|
60
60
|
extensions: []
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
|
-
- .gitignore
|
64
|
-
- .rspec
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- Gemfile.lock
|
67
68
|
- LICENSE.txt
|
@@ -87,11 +88,11 @@ files:
|
|
87
88
|
- lib/validic/rest/organizations.rb
|
88
89
|
- lib/validic/rest/profile.rb
|
89
90
|
- lib/validic/rest/request.rb
|
91
|
+
- lib/validic/rest/response.rb
|
90
92
|
- lib/validic/rest/routine.rb
|
91
93
|
- lib/validic/rest/sleep.rb
|
92
94
|
- lib/validic/rest/tobacco_cessation.rb
|
93
95
|
- lib/validic/rest/users.rb
|
94
|
-
- lib/validic/rest/utils.rb
|
95
96
|
- lib/validic/rest/weight.rb
|
96
97
|
- lib/validic/routine.rb
|
97
98
|
- lib/validic/sleep.rb
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- spec/fixtures/fitnesses.json
|
124
125
|
- spec/fixtures/forbidden.json
|
125
126
|
- spec/fixtures/internal_server.json
|
127
|
+
- spec/fixtures/invalid_date.json
|
126
128
|
- spec/fixtures/me.json
|
127
129
|
- spec/fixtures/not_found.json
|
128
130
|
- spec/fixtures/nutrition-expanded.json
|
@@ -137,6 +139,7 @@ files:
|
|
137
139
|
- spec/fixtures/routine-extras.json
|
138
140
|
- spec/fixtures/routine.json
|
139
141
|
- spec/fixtures/routines.json
|
142
|
+
- spec/fixtures/routines2.json
|
140
143
|
- spec/fixtures/sleep-expanded.json
|
141
144
|
- spec/fixtures/sleep-extras.json
|
142
145
|
- spec/fixtures/sleep.json
|
@@ -160,6 +163,7 @@ files:
|
|
160
163
|
- spec/validic/client_spec.rb
|
161
164
|
- spec/validic/error_spec.rb
|
162
165
|
- spec/validic/expanded_spec.rb
|
166
|
+
- spec/validic/response_spec.rb
|
163
167
|
- spec/validic/rest/apps_spec.rb
|
164
168
|
- spec/validic/rest/biometrics_spec.rb
|
165
169
|
- spec/validic/rest/diabetes_spec.rb
|
@@ -185,17 +189,17 @@ require_paths:
|
|
185
189
|
- lib
|
186
190
|
required_ruby_version: !ruby/object:Gem::Requirement
|
187
191
|
requirements:
|
188
|
-
- -
|
192
|
+
- - ">="
|
189
193
|
- !ruby/object:Gem::Version
|
190
194
|
version: '0'
|
191
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
192
196
|
requirements:
|
193
|
-
- -
|
197
|
+
- - ">="
|
194
198
|
- !ruby/object:Gem::Version
|
195
199
|
version: '0'
|
196
200
|
requirements: []
|
197
201
|
rubyforge_project:
|
198
|
-
rubygems_version: 2.
|
202
|
+
rubygems_version: 2.4.8
|
199
203
|
signing_key:
|
200
204
|
specification_version: 4
|
201
205
|
summary: API Wrapper for Validic
|
@@ -222,6 +226,7 @@ test_files:
|
|
222
226
|
- spec/fixtures/fitnesses.json
|
223
227
|
- spec/fixtures/forbidden.json
|
224
228
|
- spec/fixtures/internal_server.json
|
229
|
+
- spec/fixtures/invalid_date.json
|
225
230
|
- spec/fixtures/me.json
|
226
231
|
- spec/fixtures/not_found.json
|
227
232
|
- spec/fixtures/nutrition-expanded.json
|
@@ -236,6 +241,7 @@ test_files:
|
|
236
241
|
- spec/fixtures/routine-extras.json
|
237
242
|
- spec/fixtures/routine.json
|
238
243
|
- spec/fixtures/routines.json
|
244
|
+
- spec/fixtures/routines2.json
|
239
245
|
- spec/fixtures/sleep-expanded.json
|
240
246
|
- spec/fixtures/sleep-extras.json
|
241
247
|
- spec/fixtures/sleep.json
|
@@ -259,6 +265,7 @@ test_files:
|
|
259
265
|
- spec/validic/client_spec.rb
|
260
266
|
- spec/validic/error_spec.rb
|
261
267
|
- spec/validic/expanded_spec.rb
|
268
|
+
- spec/validic/response_spec.rb
|
262
269
|
- spec/validic/rest/apps_spec.rb
|
263
270
|
- spec/validic/rest/biometrics_spec.rb
|
264
271
|
- spec/validic/rest/diabetes_spec.rb
|
data/lib/validic/rest/utils.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
require 'validic/response'
|
2
|
-
require 'validic/summary'
|
3
|
-
|
4
|
-
module Validic
|
5
|
-
module REST
|
6
|
-
module Utils
|
7
|
-
private
|
8
|
-
|
9
|
-
def build_response_attr(resp)
|
10
|
-
summary = Validic::Summary.new(resp.delete("summary"))
|
11
|
-
Validic::Response.new(summary, response_object(resp))
|
12
|
-
end
|
13
|
-
|
14
|
-
def response_object(resp)
|
15
|
-
return resp.values.first if resp.values.first.is_a? Hash
|
16
|
-
klass = Validic.const_get(camelize_response_key(resp))
|
17
|
-
resp.values.flatten.collect { |obj| klass.new(obj) }
|
18
|
-
end
|
19
|
-
|
20
|
-
def camelize_response_key(resp)
|
21
|
-
key = resp.keys.first
|
22
|
-
key = key.include?('_') ? key.split('_').map(&:capitalize).join : key.capitalize
|
23
|
-
key.chop! if %w(Users Apps).include?(key) #strip last letter off to match ::User or ::App
|
24
|
-
key
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|