lhs 16.0.1 → 16.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 519bda1b6733055661e7c322952675d1a8e05dc4b946314ccf84ec1fbcff7fe5
4
- data.tar.gz: 9a8fca55ca2145b107872375e09244b0fa7bb9d54e18f193a627689cdeac1dc8
3
+ metadata.gz: 40c9a3c78d7e3f84b0652f9903eaba8b6f7312a7bd1b0e1a2f59100a6f296acb
4
+ data.tar.gz: a70e74d0de431175fe821751884d6b4eb60cc7e9bdd8c1237e906e41723c6b97
5
5
  SHA512:
6
- metadata.gz: 8b34a119d3d592fc15ce1c0bf1bee4f4f6943ab043b34dc783e1c564f939bc5c6e0e13a092a61357a6cd31a9cba895103182cfadbf5bd61300c241c3ace77d23
7
- data.tar.gz: 5318780360ec447fae0820747c6bc0b86a8f9c2a0b37d827a5086c391e1b160a68cd186380171630b2b915944a319577e7385ba535e06bcb2bb468c968f74ab8
6
+ metadata.gz: 8b5952d6ef6362ac7f9689a6c845469af65d8047228b267af4c28828adafdc776458af6a6562f395ae4dcc622b8462ef30f6b6e9c62a105a35ba9eb02f3d2b27
7
+ data.tar.gz: c554b8122c917cab6866bed3c081cebfc66d35971c10a085617fc0eec546d9e1e2542c7cfeae93400c1a07e4402398750317fcbd270f9b3d09a9bfe16f3eb9fe
data/README.md CHANGED
@@ -2077,7 +2077,7 @@ In case an API does not provide pagination information in the repsponse data (li
2077
2077
  `find_each` is a more fine grained way to process single records that are fetched in batches.
2078
2078
 
2079
2079
  ```ruby
2080
- Record.find_each(start: 50, batch_size: 20, params: { has_reviews: true }) do |record|
2080
+ Record.find_each(start: 50, batch_size: 20, params: { has_reviews: true }, headers: { 'Authorization': 'Bearer 123' }) do |record|
2081
2081
  # Iterates over each record. Starts with record no. 50 and fetches 20 records each batch.
2082
2082
  record
2083
2083
  break if record.some_attribute == some_value
@@ -2089,7 +2089,7 @@ end
2089
2089
  `find_in_batches` is used by `find_each` and processes batches.
2090
2090
 
2091
2091
  ```ruby
2092
- Record.find_in_batches(start: 50, batch_size: 20, params: { has_reviews: true }) do |records|
2092
+ Record.find_in_batches(start: 50, batch_size: 20, params: { has_reviews: true }, headers: { 'Authorization': 'Bearer 123' }) do |records|
2093
2093
  # Iterates over multiple records (batch size is 20). Starts with record no. 50 and fetches 20 records each batch.
2094
2094
  records
2095
2095
  break if records.first.name == some_value
@@ -19,11 +19,13 @@ class LHS::Record
19
19
  # Process batches of entries
20
20
  def find_in_batches(options = {})
21
21
  raise 'No block given' unless block_given?
22
- start = options[:start] || 1
23
- batch_size = options[:batch_size] || LHS::Pagination::Base::DEFAULT_LIMIT
24
- params = options[:params] || {}
22
+ options = options.dup
23
+ start = options.delete(:start) || 1
24
+ batch_size = options.delete(:batch_size) || LHS::Pagination::Base::DEFAULT_LIMIT
25
25
  loop do # as suggested by Matz
26
- data = request(params: params.merge(limit_key(:parameter) => batch_size, pagination_key(:parameter) => start))
26
+ options = options.dup
27
+ options[:params] = (options[:params] || {}).merge(limit_key(:parameter) => batch_size, pagination_key(:parameter) => start)
28
+ data = request(options)
27
29
  batch_size = data._raw.dig(*limit_key(:body))
28
30
  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
31
  yield new(data)
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = '16.0.1'
2
+ VERSION = '16.1.0'
3
3
  end
@@ -41,5 +41,15 @@ describe LHS::Collection do
41
41
  end
42
42
  expect(count).to eq total
43
43
  end
44
+
45
+ it 'passes options to the requests made' do
46
+ request = stub_request(:get, "http://local.ch/v2/feedbacks?limit=100&offset=1")
47
+ .with(headers: { 'Authorization' => 'Bearer 123' })
48
+ .to_return(body: {
49
+ items: []
50
+ }.to_json)
51
+ Record.find_each(headers: { 'Authorization' => 'Bearer 123' }) { |record| }
52
+ expect(request).to have_been_made
53
+ end
44
54
  end
45
55
  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: 16.0.1
4
+ version: 16.1.0
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-10-29 00:00:00.000000000 Z
11
+ date: 2018-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel