You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fe77414
Browse filesBrowse the repository at this point in the historyBrowse files
feat(client)!: extract auto pagination to shared classes
refactor(client)!: refactor async auto-pagination
refactor(client)!: rename `getNextPage{,Params}` to `nextPage{,Params}`
refactor(client)!: swap `nextPage{,Params}` to return non-optional
# Migration
- If you were referencing the `AutoPager` class on a specific `*Page` or `*PageAsync` type, then you should instead reference the shared `AutoPager` and `AutoPagerAsync` types, under the `core` package
- `AutoPagerAsync` now has different usage. You can call `.subscribe(...)` on the returned object instead to get called back each page item. You can also call `onCompleteFuture()` to get a future that completes when all items have been processed. Finally, you can call `.close()` on the returned object to stop auto-paginating early
- If you were referencing `getNextPage` or `getNextPageParams`:
- Swap to `nextPage()` and `nextPageParams()`
- Note that these both now return non-optional types (use `hasNextPage()` before calling these, since they will throw if it's impossible to get another page)
There are examples and further information about pagination in the readme.
For methods that return a paginated list of results, this library provides convenient ways access the results either one page at a time, or item-by-item across all pages.
219
+
The SDK defines methods that return a paginated lists of results. It provides convenient ways to access the results either one page at a time or item-by-item across all pages.
220
220
221
221
### Auto-pagination
222
222
223
-
To iterate through all results across all pages, you can use `autoPager`, which automatically handles fetching more pages for you:
223
+
To iterate through all results across all pages, use the `autoPager()` method, which automatically fetches more pages as needed.
224
224
225
-
### Synchronous
225
+
When using the synchronous client, the method returns an [`Iterable`](https://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html)
226
226
227
227
```java
228
228
importcom.lithic.api.models.CardListPage;
229
229
importcom.lithic.api.models.NonPciCard;
230
230
231
-
// As an Iterable:
232
-
CardListPage page = client.cards().list(params);
231
+
CardListPage page = client.cards().list();
232
+
233
+
// Process as an Iterable
233
234
for (NonPciCard card : page.autoPager()) {
234
235
System.out.println(card);
235
-
};
236
+
}
236
237
237
-
// As a Stream:
238
-
client.cards().list(params).autoPager().stream()
238
+
// Process as a Stream
239
+
page.autoPager()
240
+
.stream()
239
241
.limit(50)
240
242
.forEach(card ->System.out.println(card));
241
243
```
242
244
243
-
### Asynchronous
245
+
When using the asynchronous client, the method returns an [`AsyncStreamResponse`](lithic-java-core/src/main/kotlin/com/lithic/api/core/http/AsyncStreamResponse.kt):
244
246
245
247
```java
246
-
// Using forEach, which returns CompletableFuture<Void>:
If none of the above helpers meet your needs, you can also manually request pages one-by-one. A page of results has a `data()` method to fetch the list of objects, as well as top-level `response` and other methods to fetch top-level data about the page. It also has methods `hasNextPage`, `getNextPage`, and `getNextPageParams` methods to help with pagination.
296
+
To access individual page items and manually request the next page, use the `items()`,
297
+
`hasNextPage()`, and `nextPage()` methods:
254
298
255
299
```java
256
300
importcom.lithic.api.models.CardListPage;
257
301
importcom.lithic.api.models.NonPciCard;
258
302
259
-
CardListPage page = client.cards().list(params);
260
-
while (page !=null) {
261
-
for (NonPciCard card : page.data()) {
303
+
CardListPage page = client.cards().list();
304
+
while (true) {
305
+
for (NonPciCard card : page.items()) {
262
306
System.out.println(card);
263
307
}
264
308
265
-
page = page.getNextPage().orElse(null);
309
+
if (!page.hasNextPage()) {
310
+
break;
311
+
}
312
+
313
+
page = page.nextPage();
266
314
}
267
315
```
268
316
@@ -339,7 +387,6 @@ To set a custom timeout, configure the method call using the `timeout` method:
0 commit comments