dhs 1.0.3 → 1.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 +4 -4
- data/README.md +34 -1
- data/lib/dhs.rb +1 -0
- data/lib/dhs/concerns/record/pagination.rb +2 -0
- data/lib/dhs/pagination/offset_page.rb +7 -0
- data/lib/dhs/version.rb +1 -1
- data/spec/pagination/offset_page_spec.rb +61 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1880fd170b224c3968acc2c3d77f2aa2b31bf6205f0427a30d8041081feafda9
|
4
|
+
data.tar.gz: 85e87c2fd8b9f0931286d7b4343839c9951f6a22f201d2dcd1135fad0dccf4f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15623d271f53db3a97af63412ee8a325ffa3ed8039bfbe3716a5fb337341f978cfde0893f811111eaee487d4f01d8c6e32cd70d5f6de5389d0a6d7a66a65d4bc
|
7
|
+
data.tar.gz: 507dd7ccbcd98f21060dfb1c90fa1e849aa63319e842bc1f70d8aa06398aeb4edbc9f7763890090b9252df93606851f598e901451e750ad4fd4ae0c772a04ead
|
data/README.md
CHANGED
@@ -1131,6 +1131,40 @@ In parallel:
|
|
1131
1131
|
GET https://service.example.com/records?limit=100&page=3
|
1132
1132
|
```
|
1133
1133
|
|
1134
|
+
##### Pagination strategy: offset_page
|
1135
|
+
|
1136
|
+
The `offest_page` strategy is based on the `page` strategy with the only difference
|
1137
|
+
that the pages are counted from 0 onwards (not from 1).
|
1138
|
+
|
1139
|
+
```ruby
|
1140
|
+
# app/models/transaction.rb
|
1141
|
+
|
1142
|
+
class Transaction < DHS::Record
|
1143
|
+
configuration pagination_strategy: 'offset_page', pagination_key: 'page'
|
1144
|
+
|
1145
|
+
endpoint '{+service}/transactions'
|
1146
|
+
end
|
1147
|
+
```
|
1148
|
+
|
1149
|
+
```ruby
|
1150
|
+
# app/controllers/some_controller.rb
|
1151
|
+
|
1152
|
+
Record.all
|
1153
|
+
|
1154
|
+
```
|
1155
|
+
```
|
1156
|
+
GET https://service.example.com/records?limit=100
|
1157
|
+
{
|
1158
|
+
items: [{...}, ...],
|
1159
|
+
total: 300,
|
1160
|
+
limit: 100,
|
1161
|
+
page: 0
|
1162
|
+
}
|
1163
|
+
In parallel:
|
1164
|
+
GET https://service.example.com/records?limit=100&page=1
|
1165
|
+
GET https://service.example.com/records?limit=100&page=2
|
1166
|
+
```
|
1167
|
+
|
1134
1168
|
##### Pagination strategy: total_pages
|
1135
1169
|
|
1136
1170
|
The `total_pages` strategy is based on the `page` strategy with the only difference
|
@@ -1165,7 +1199,6 @@ In parallel:
|
|
1165
1199
|
GET https://service.example.com/records?limit=100&page=3
|
1166
1200
|
```
|
1167
1201
|
|
1168
|
-
|
1169
1202
|
##### Pagination strategy: start
|
1170
1203
|
|
1171
1204
|
In comparison to the `offset` strategy, the `start` strategy indicates with which item the current page starts.
|
data/lib/dhs.rb
CHANGED
@@ -38,6 +38,7 @@ module DHS
|
|
38
38
|
autoload :Offset, 'dhs/pagination/offset'
|
39
39
|
autoload :Page, 'dhs/pagination/page'
|
40
40
|
autoload :TotalPages, 'dhs/pagination/total_pages'
|
41
|
+
autoload :OffsetPage, 'dhs/pagination/offset_page'
|
41
42
|
autoload :Start, 'dhs/pagination/start'
|
42
43
|
autoload :Link, 'dhs/pagination/link'
|
43
44
|
end
|
data/lib/dhs/version.rb
CHANGED
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rails_helper'
|
4
|
+
|
5
|
+
describe DHS::Record do
|
6
|
+
context 'pagination' do
|
7
|
+
def stub_api_request(items: [], page: nil)
|
8
|
+
stub_request(:get, ['http://depay.fi/v2/transactions?limit=100', page].compact.join('&page='))
|
9
|
+
.to_return(body: { items: items }.to_json)
|
10
|
+
end
|
11
|
+
|
12
|
+
let!(:requests) do
|
13
|
+
stub_api_request(items: (0...100).to_a)
|
14
|
+
stub_api_request(items: (100...200).to_a, page: 1)
|
15
|
+
stub_api_request(items: (200...300).to_a, page: 2)
|
16
|
+
stub_api_request(items: [], page: 3)
|
17
|
+
end
|
18
|
+
|
19
|
+
before do
|
20
|
+
class Transaction < DHS::Record
|
21
|
+
configuration pagination_strategy: :offset_page, pagination_key: :page
|
22
|
+
|
23
|
+
endpoint 'http://depay.fi/v2/transactions'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'fetches all the pages' do
|
28
|
+
transactions = Transaction.all.fetch
|
29
|
+
expect(transactions.to_a).to eq (0...300).to_a
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'incomplete pages' do
|
33
|
+
let!(:requests) do
|
34
|
+
stub_api_request(items: (0...100).to_a)
|
35
|
+
stub_api_request(items: (100...200).to_a, page: 1)
|
36
|
+
stub_api_request(items: (200...300).to_a, page: 2)
|
37
|
+
stub_api_request(items: [300], page: 3)
|
38
|
+
stub_api_request(items: [], page: 4)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'fetches all the pages' do
|
42
|
+
transactions = Transaction.all.fetch
|
43
|
+
expect(transactions.to_a).to eq (0..300).to_a
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'incomplete pages' do
|
48
|
+
let!(:requests) do
|
49
|
+
stub_api_request(items: (0...100).to_a)
|
50
|
+
stub_api_request(items: (100...200).to_a, page: 1)
|
51
|
+
stub_api_request(items: (200...299).to_a, page: 2)
|
52
|
+
stub_api_request(items: [], page: 3)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'fetches all the pages' do
|
56
|
+
transactions = Transaction.all.fetch
|
57
|
+
expect(transactions.to_a).to eq (0...299).to_a
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
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.0
|
4
|
+
version: 1.1.0
|
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: 2021-04-
|
11
|
+
date: 2021-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -322,6 +322,7 @@ files:
|
|
322
322
|
- lib/dhs/pagination/base.rb
|
323
323
|
- lib/dhs/pagination/link.rb
|
324
324
|
- lib/dhs/pagination/offset.rb
|
325
|
+
- lib/dhs/pagination/offset_page.rb
|
325
326
|
- lib/dhs/pagination/page.rb
|
326
327
|
- lib/dhs/pagination/start.rb
|
327
328
|
- lib/dhs/pagination/total_pages.rb
|
@@ -459,6 +460,7 @@ files:
|
|
459
460
|
- spec/pagination/link/parallel_spec.rb
|
460
461
|
- spec/pagination/link/total_spec.rb
|
461
462
|
- spec/pagination/offset/pages_left_spec.rb
|
463
|
+
- spec/pagination/offset_page_spec.rb
|
462
464
|
- spec/pagination/parameters_spec.rb
|
463
465
|
- spec/pagination/total_pages_spec.rb
|
464
466
|
- spec/proxy/create_sub_resource_spec.rb
|
@@ -693,6 +695,7 @@ test_files:
|
|
693
695
|
- spec/pagination/link/parallel_spec.rb
|
694
696
|
- spec/pagination/link/total_spec.rb
|
695
697
|
- spec/pagination/offset/pages_left_spec.rb
|
698
|
+
- spec/pagination/offset_page_spec.rb
|
696
699
|
- spec/pagination/parameters_spec.rb
|
697
700
|
- spec/pagination/total_pages_spec.rb
|
698
701
|
- spec/proxy/create_sub_resource_spec.rb
|