lhs 1.2.0 → 1.2.1

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: 43644dd5ced6e07d1930e1b8377070475780b45d
4
- data.tar.gz: 0a1ae22b03cec9fa31f2d311419972ecf8f919c3
3
+ metadata.gz: 371888c99881b65fa1571b7ab9d0639b784a66de
4
+ data.tar.gz: 41bcc0e2446cf6ea11b8469d0bb8c78494bf3708
5
5
  SHA512:
6
- metadata.gz: b2196aa94fc0e7653a055b81faa2ce04a1152713e77ed61b8f899cd36c172b133e2a1ccc0b595aca498bac5d107f970171a053b60a48ede60f946f1360e48ec0
7
- data.tar.gz: 96abeddb6c2b0c2b6bbd25890ca5b4f16b7cdcf907d12e470a1bb1e4b2122fe15b4e1de7f0bbf477d11b17b4d4a05bf2f8a75bdeab75c4be443186bc68c407d1
6
+ metadata.gz: 8bed4523267443a431e667ab516589d69c49da957cdcccf798e302cbc4775638b039f29eada8e1e8643435be196513005176e36119d4b468fac2b81ce22ee342
7
+ data.tar.gz: 22f46fdcab0190ec3f890b2f2191120d55eb9c7bf822bfcdf5be180d43561cdb33098a20cd354518364829399ffbb28c91173a77fd26cbd62f3060dc6e9374c9
@@ -21,8 +21,8 @@ class LHS::Item < LHS::Proxy
21
21
  else
22
22
  service.instance.find_endpoint(data).compile(data)
23
23
  end
24
- response = service.instance.request(method: :post, url: url, body: data.to_json, headers: {'Content-Type' => 'application/json'})
25
- self._data.merge!(response)
24
+ data = service.instance.request(method: :post, url: url, body: data.to_json, headers: {'Content-Type' => 'application/json'})
25
+ self._data.merge_raw!(data)
26
26
  true
27
27
  end
28
28
  end
@@ -16,8 +16,8 @@ class LHS::Item < LHS::Proxy
16
16
  def update!(params)
17
17
  service = _data._root._service
18
18
  data = _data._raw.dup
19
- response = service.instance.request(method: :post, url: href, body: data.merge(params).to_json, headers: {'Content-Type' => 'application/json'})
20
- self._data.merge!(response)
19
+ data = service.instance.request(method: :post, url: href, body: data.merge(params).to_json, headers: {'Content-Type' => 'application/json'})
20
+ self._data.merge_raw!(data)
21
21
  true
22
22
  end
23
23
  end
@@ -7,9 +7,15 @@ class LHS::Service
7
7
 
8
8
  module ClassMethods
9
9
 
10
+ # Should be an edge case but sometimes all objects from a certain resource
11
+ # are required. In this case we load the first page with the default max limit,
12
+ # compute the amount of left over requests, do all the the left over requests
13
+ # for the following pages and concatenate all the results in order to return
14
+ # all the objects for a given resource.
10
15
  def all(params = {})
11
16
  all = []
12
- data = instance.request(params: params.merge(limit: 100))
17
+ default_max_limit = 100
18
+ data = instance.request(params: params.merge(limit: default_max_limit))
13
19
  all.concat(data._raw['items'])
14
20
  total_left = data._raw['total'] - data.count
15
21
  limit = data._raw['limit'] || data.count
@@ -18,7 +18,7 @@ class LHS::Data
18
18
 
19
19
  # merging data
20
20
  # e.g. when loading remote data via link
21
- def merge!(data)
21
+ def merge_raw!(data)
22
22
  return false unless data._raw.is_a?(Hash)
23
23
  _raw.merge! data._raw
24
24
  end
@@ -19,7 +19,7 @@ class LHS::Proxy
19
19
  fail 'No href found' unless _data.href
20
20
  service = _data._root._service
21
21
  data = service.instance.request(url: _data.href, method: :get)
22
- merge!(data)
22
+ _data.merge_raw!(data)
23
23
  self._loaded = true
24
24
  self
25
25
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
3
3
  end
@@ -25,7 +25,7 @@ describe LHS::Data do
25
25
  context 'merging' do
26
26
 
27
27
  it 'merges data' do
28
- data.merge!(loaded_data)
28
+ data.merge_raw!(loaded_data)
29
29
  expect(data.id).to eq loaded_data.id
30
30
  end
31
31
  end
@@ -32,14 +32,14 @@ describe LHS::Proxy do
32
32
  context 'load' do
33
33
 
34
34
  it 'is loading data remotely when not present yet' do
35
- link.load!.id
35
+ expect(link.load!.id).to be
36
+ expect(link.id).to be
36
37
  end
37
38
 
38
39
  it 'can be reloaded' do
39
- link.load!.id
40
+ expect(link.load!.id).to be
40
41
  stub_request(:get, 'http://datastore-stg.lb-service.sunrise.intra.local.ch/v2/content-ads/51dfc5690cf271c375c5a12d')
41
42
  .to_return(status: 404)
42
- link.load!.id
43
43
  expect(-> { link.reload!.id })
44
44
  .to raise_error LHC::NotFound
45
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - local.ch