lhs 15.0.1 → 15.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5612b7fd76224814a3250ca7cef5cb41e708d6da
4
- data.tar.gz: 3496afc8f424012ee023dfe213b5f70bcd6c2299
3
+ metadata.gz: 0e401b46b1033f255793a10a976ba7a0b14ec364
4
+ data.tar.gz: b3e461f0882936419e352349caa0dcca4c5ec48c
5
5
  SHA512:
6
- metadata.gz: 7785e4ccbb104ed5f166f8d8179cccea503eb80ce91c01e13571378525f71504fb71a7a04a3add83d1af7c24a5c01650394b50895105e516f4c3aed8dbf4df89
7
- data.tar.gz: 8a6e4469c4bd980e6873b03c858fa4a5ed157223d2c01a911979ee9ee5d6cabcf5e9794bc85516744888bbdb3a0cb544fe446a56c15d5da2823b005d94b70230
6
+ metadata.gz: bbd204a60d46660fdcfb7ec01b71ef9e1e11a7ddf94827a4312e3b3235ecfaa96fdd87046d732a61a43f49b64b6601787e6f857b6dd8e0e39bbc5d4c006ab653
7
+ data.tar.gz: 631a0a7a45c359da9e8c0f47f583a03f0950dc8263629d217c443feb77e92e37711fa526f52594f5189caa596c3031e0528411983b3afcbd1eedb960595caadc
@@ -24,8 +24,8 @@ class LHS::Record
24
24
  params = options[:params] || {}
25
25
  loop do # as suggested by Matz
26
26
  data = request(params: params.merge(limit_key(:parameter) => batch_size, pagination_key(:parameter) => start))
27
- batch_size = data._raw[limit_key(:parameter)]
28
- left = data._raw.dig(*total_key).to_i - data._raw[pagination_key(:parameter)].to_i - data._raw[limit_key(:paramter)].to_i
27
+ batch_size = data._raw.dig(*limit_key(:body))
28
+ left = data._raw.dig(*total_key).to_i - data._raw.dig(*pagination_key(:body)).to_i - data._raw.dig(*limit_key(:body)).to_i
29
29
  yield new(data)
30
30
  break if left <= 0
31
31
  start += batch_size
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '15.0.1'
2
+ VERSION = '15.0.2'
3
3
  end
@@ -90,4 +90,31 @@ describe LHS::Collection do
90
90
  expect(length).to eq total
91
91
  end
92
92
  end
93
+
94
+ context 'pagination with nested response' do
95
+ before do
96
+ class Record < LHS::Record
97
+ endpoint '{+datastore}/{campaign_id}/feedbacks'
98
+ endpoint '{+datastore}/feedbacks'
99
+ configuration items_key: [:response, :docs], limit_key: { body: [:response, :size], parameter: :size }, pagination_key: { body: [:response, :start], parameter: :start }, pagination_strategy: :start, total_key: [:response, :totalResults]
100
+ end
101
+ end
102
+
103
+ let(:options) { { items_key: 'docs', limit_key: 'size', pagination_key: 'start', total_key: 'totalResults' } }
104
+
105
+ it 'capable to do batch processing with configured pagination' do
106
+ stub_request(:get, "#{datastore}/feedbacks?size=230&start=1").to_return(status: 200, body: "{\"response\":#{api_response((1..100).to_a, 1, options)}}")
107
+ stub_request(:get, "#{datastore}/feedbacks?size=100&start=101").to_return(status: 200, body: "{\"response\":#{api_response((101..200).to_a, 101, options)}}")
108
+ stub_request(:get, "#{datastore}/feedbacks?size=100&start=201").to_return(status: 200, body: "{\"response\":#{api_response((201..300).to_a, 201, options)}}")
109
+ stub_request(:get, "#{datastore}/feedbacks?size=100&start=301").to_return(status: 200, body: "{\"response\":#{api_response((301..400).to_a, 301, options)}}")
110
+ stub_request(:get, "#{datastore}/feedbacks?size=100&start=401").to_return(status: 200, body: "{\"response\":#{api_response((401..total).to_a, 401, options)}}")
111
+ length = 0
112
+ Record.find_in_batches(batch_size: 230) do |records|
113
+ length += records.length
114
+ expect(records).to be_kind_of Record
115
+ expect(records._proxy).to be_kind_of LHS::Collection
116
+ end
117
+ expect(length).to eq total
118
+ end
119
+ end
93
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhs
3
3
  version: !ruby/object:Gem::Version
4
- version: 15.0.1
4
+ version: 15.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - https://github.com/local-ch/lhs/graphs/contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-17 00:00:00.000000000 Z
11
+ date: 2018-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc