dhs 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dhs/concerns/record/request.rb +1 -0
- data/lib/dhs/version.rb +1 -1
- data/spec/pagination/next_offset_spec.rb +53 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ef9be83e5148eedcda73523574e4d53684aecbf906e9034b12f52c9b8881a7b
|
4
|
+
data.tar.gz: c8195c1668a305f9e9fcc723ba2464de9b87f17d2eaaa57ec3d4787ec36d8e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be55a13a577be249b76b1eaeb7baec3a307b94f4a7c2c4643ea1fcf66edb3f8df3927386886babe211b687821229180d33f0cf5e5af04f1af9534ccd67c20ffd
|
7
|
+
data.tar.gz: 5ab39a51ac32085b8cb71e183c34edd64a7c5e78c86e6e08faabdd03d196a5aadbbfeba8e7b2ac8dc571d59b2ad7281cda2a20c5d8c131e3fbafdf061c6a0adc
|
@@ -387,6 +387,7 @@ class DHS::Record
|
|
387
387
|
end
|
388
388
|
|
389
389
|
def merge_batch_data_with_parent!(batch_data, parent_data, pagination = nil)
|
390
|
+
return if batch_data.raw_items.blank?
|
390
391
|
parent_data.concat(input: parent_data._raw, items: batch_data.raw_items, record: self)
|
391
392
|
return if pagination.present? && pagination.is_a?(DHS::Pagination::Link)
|
392
393
|
[limit_key(:body), total_key, pagination_key(:body)].each do |pagination_attribute|
|
data/lib/dhs/version.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
require 'rails_helper'
|
4
4
|
|
5
5
|
describe DHS::Record do
|
6
|
-
context 'pagination' do
|
6
|
+
context 'next offset pagination' do
|
7
7
|
def stub_api_request(next_offset:, items: [], offset: nil)
|
8
8
|
stub_request(:get, ['http://depay.fi/v2/transactions?limit=100', offset ? "offset=#{offset}" : nil].compact.join('&'))
|
9
9
|
.to_return(body: { items: items, next_offset: next_offset }.to_json)
|
@@ -28,4 +28,56 @@ describe DHS::Record do
|
|
28
28
|
expect(transactions.to_a).to eq (0...300).to_a
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
context 'next offset pagination with items configuration' do
|
33
|
+
def stub_api_request(next_offset:, items: [], offset: nil)
|
34
|
+
stub_request(:get, ['http://depay.fi/v2/transactions?limit=100', offset ? "offset=#{offset}" : nil].compact.join('&'))
|
35
|
+
.to_return(body: { assets: items, next_offset: next_offset }.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
let!(:requests) do
|
39
|
+
stub_api_request(items: (0...100).to_a, next_offset: 99)
|
40
|
+
stub_api_request(items: (100...200).to_a, offset: 99, next_offset: 199)
|
41
|
+
stub_api_request(items: (200...300).to_a, offset: 199, next_offset: 0)
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
class Transaction < DHS::Record
|
46
|
+
configuration items_key: :assets, pagination_strategy: :next_offset, pagination_key: { body: :next_offset, parameter: :offset }
|
47
|
+
|
48
|
+
endpoint 'http://depay.fi/v2/transactions'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'fetches and merges all the assets/items' do
|
53
|
+
transactions = Transaction.all.fetch
|
54
|
+
expect(transactions.to_a).to eq (0...300).to_a
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'next offset pagination with items configuration and nil response' do
|
59
|
+
def stub_api_request(next_offset:, items: [], offset: nil)
|
60
|
+
stub_request(:get, ['http://depay.fi/v2/transactions?limit=100', offset ? "offset=#{offset}" : nil].compact.join('&'))
|
61
|
+
.to_return(body: { assets: items, next_offset: next_offset }.to_json)
|
62
|
+
end
|
63
|
+
|
64
|
+
let!(:requests) do
|
65
|
+
stub_api_request(items: (0...100).to_a, next_offset: 99)
|
66
|
+
stub_api_request(items: (100...200).to_a, offset: 99, next_offset: 199)
|
67
|
+
stub_api_request(items: nil, offset: 199, next_offset: 0)
|
68
|
+
end
|
69
|
+
|
70
|
+
before do
|
71
|
+
class Transaction < DHS::Record
|
72
|
+
configuration items_key: :assets, pagination_strategy: :next_offset, pagination_key: { body: :next_offset, parameter: :offset }
|
73
|
+
|
74
|
+
endpoint 'http://depay.fi/v2/transactions'
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'fetches and merges all the assets/items' do
|
79
|
+
transactions = Transaction.all.fetch
|
80
|
+
expect(transactions.to_a).to eq (0...200).to_a
|
81
|
+
end
|
82
|
+
end
|
31
83
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/DePayFi/dhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|