validic 0.4.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8852001360881e470bc390ff9e44d0c83f8c42c
4
- data.tar.gz: e3494be76d5d6794db140f08a7228b8ed9788430
3
+ metadata.gz: 126d89621c9028f5e07f6988e1d460d273f864b2
4
+ data.tar.gz: cfd36bbb933bb2e10d239a049bb6dbd375c3ca16
5
5
  SHA512:
6
- metadata.gz: 3ca048da5b89cbada497942557373b0b9d25bc25d296c238349edf72211caf5054a38832b3e26cc8477ea5c8ad36050476eb861e65791941ec0e867c1ab77394
7
- data.tar.gz: 06ef87e636504d0db352769653d77bbb690e8e94d156a8c1dda454f99886f3a30897df85443aefd4e98dad4f47afb4de719b7555f81d598150668666f0157ded
6
+ metadata.gz: 6c77c1e8227a18bbff2bc64d9fa4d3a160fa8803707bf7db7635d2dfd648cdfe00d4bcfc36231a68a661f8038648cc1d19c7363f1dfb26d5d418e6ef4682dcce
7
+ data.tar.gz: a94a08ba6093f64a15f8e60b52e0fdbf05de887c86cb52b2b98b4bf06c0a354c8f8341eff5e82c9081749ccbc45add1a82cfba258c68a797abb7f994cfb83a6e
@@ -0,0 +1,5 @@
1
+ # Change Log
2
+
3
+ 0.5.0
4
+ -----------
5
+ - Ability to call the next or previous page from a Validic::Response
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validic (0.4.1)
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.1)
16
+ faraday (0.9.2)
17
17
  multipart-post (>= 1.2, < 3)
18
- faraday_middleware (0.9.1)
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.0)
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 options
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 user id from authentication token
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 including create, update and delete. The gem supports all 3 of these:
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",
@@ -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 = options[:api_url].nil? ? 'https://api.validic.com' : options[:api_url]
48
- @api_version = options[:api_version].nil? ? 'v1' : options[:api_version]
49
- @access_token = options[:access_token].nil? ? Validic.access_token : options[:access_token]
50
- @organization_id = options[:organization_id].nil? ? Validic.organization_id : options[: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
 
@@ -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
@@ -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
- case response
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 = response
13
+ @records = resp
10
14
  when Hash
11
- @attributes = response
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
@@ -4,16 +4,14 @@ module Validic
4
4
  module REST
5
5
  module Apps
6
6
 
7
- def get_org_apps
8
- resp = get_request(:apps)
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
- resp = get_request(:sync_apps,
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
- resp = get_request(:biometrics, options)
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
- resp = latest(:biometrics, options)
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
- resp = get_request(:diabetes, options)
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
- resp = latest(:diabetes, options)
35
- build_response_attr(resp)
33
+ build_response(latest(:diabetes, options))
36
34
  end
37
35
  end
38
36
  end
@@ -5,8 +5,7 @@ module Validic
5
5
  module Fitness
6
6
 
7
7
  def get_fitness(options = {})
8
- resp = get_request(:fitness, options)
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
- resp = latest(:fitness, options)
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
- resp = get_request(:nutrition, options)
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
- resp = latest(:nutrition, options)
36
- build_response_attr(resp)
34
+ build_response(latest(:nutrition, options))
37
35
  end
38
36
  end
39
37
  end
@@ -4,8 +4,7 @@ module Validic
4
4
  module REST
5
5
  module Organizations
6
6
  def get_organization(params = {})
7
- resp = get_request(:organizations, params)
8
- build_response_attr(resp)
7
+ build_response(get_request(:organizations, params))
9
8
  end
10
9
  end
11
10
  end
@@ -0,0 +1,13 @@
1
+ require 'validic/response'
2
+
3
+ module Validic
4
+ module REST
5
+ module Response
6
+ private
7
+
8
+ def build_response(response)
9
+ Validic::Response.new(response, connection)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -5,8 +5,7 @@ module Validic
5
5
  module Routine
6
6
 
7
7
  def get_routine(params = {})
8
- resp = get_request(:routine, params)
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
- resp = latest(:routine, options)
36
- build_response_attr(resp)
34
+ build_response(latest(:routine, options))
37
35
  end
38
36
  end
39
37
  end
@@ -5,8 +5,7 @@ module Validic
5
5
  module Sleep
6
6
 
7
7
  def get_sleep(options = {})
8
- resp = get_request(:sleep, options)
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
- resp = latest(:sleep, options)
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
- resp = get_request(:tobacco_cessation, options)
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
- resp = latest(:tobacco_cessation, options)
36
- build_response_attr(resp)
34
+ build_response(latest(:tobacco_cessation, options))
37
35
  end
38
36
  end
39
37
  end
@@ -5,8 +5,7 @@ module Validic
5
5
  module Users
6
6
 
7
7
  def get_users(options = {})
8
- resp = get_request(:users, options)
9
- build_response_attr(resp)
8
+ build_response(get_request(:users, options))
10
9
  end
11
10
  alias :get_user :get_users
12
11
 
@@ -5,10 +5,8 @@ module Validic
5
5
  module Weight
6
6
 
7
7
  def get_weight(params={})
8
- resp = get_request(:weight, params)
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
- resp = latest(:weight, options)
38
- build_response_attr(resp)
35
+ build_response(latest(:weight, options))
39
36
  end
40
-
41
37
  end
42
38
  end
43
39
  end
@@ -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"]
@@ -1,3 +1,3 @@
1
1
  module Validic
2
- VERSION = '0.4.1'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -0,0 +1 @@
1
+ {"code": 406, "message": "Not Acceptable", "errors": ["Invalid date"]}
@@ -8,7 +8,7 @@
8
8
  "offset": 0,
9
9
  "limit": 100,
10
10
  "previous": null,
11
- "next": null,
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
+ }
@@ -2,9 +2,44 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  describe Validic::Client do
5
- let(:client) { Validic::Client.new }
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
@@ -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
- before do
8
- stub_get("/organizations/1/apps.json")
9
- .with(query: { access_token: '1' })
10
- .to_return(body: fixture('apps.json'),
11
- headers: { content_type: 'application/json; charset=utf-8' })
12
- @apps = client.get_org_apps
13
- end
14
- it 'returns a response object' do
15
- expect(@apps).to be_a Validic::Response
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
- it 'makes an apps request to the correct url' do
18
- expect(a_get('/organizations/1/apps.json')
19
- .with(query: { access_token: '1' })).to have_been_made
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
- @synced_apps = client.get_user_synced_apps(authentication_token: '2')
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.1
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: 2015-04-07 00:00:00.000000000 Z
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.0.14
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
@@ -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