From fe60c17a0e6f05539ea00c97309f209f0fe1139e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 15:22:19 +0000 Subject: [PATCH] feat(api)!: update SDKs to meteroid 0.1.0 --- api.md | 36 ++-- src/main/java/com/meteroid/AsyncPage.java | 71 ++++++-- .../java/com/meteroid/AsyncPaginator.java | 63 ------- src/main/java/com/meteroid/Meteroid.java | 17 +- src/main/java/com/meteroid/Page.java | 96 ++++++++-- src/main/java/com/meteroid/Paginator.java | 98 ----------- src/main/java/com/meteroid/api/AddOns.java | 76 ++++++-- .../java/com/meteroid/api/AddOnsAsync.java | 60 +++++-- .../com/meteroid/api/AddOnsListAsyncPage.java | 66 +++++++ .../java/com/meteroid/api/AddOnsListPage.java | 66 +++++++ src/main/java/com/meteroid/api/BatchJobs.java | 166 ++++++++++++++---- .../java/com/meteroid/api/BatchJobsAsync.java | 132 ++++++++++---- .../meteroid/api/BatchJobsListAsyncPage.java | 67 +++++++ .../api/BatchJobsListFailuresAsyncPage.java | 70 ++++++++ .../api/BatchJobsListFailuresPage.java | 68 +++++++ .../com/meteroid/api/BatchJobsListPage.java | 68 +++++++ src/main/java/com/meteroid/api/Coupons.java | 76 ++++++-- .../java/com/meteroid/api/CouponsAsync.java | 60 +++++-- .../meteroid/api/CouponsListAsyncPage.java | 66 +++++++ .../com/meteroid/api/CouponsListPage.java | 66 +++++++ .../java/com/meteroid/api/CreditNotes.java | 77 ++++++-- .../com/meteroid/api/CreditNotesAsync.java | 60 +++++-- .../api/CreditNotesListAsyncPage.java | 67 +++++++ .../com/meteroid/api/CreditNotesListPage.java | 68 +++++++ .../com/meteroid/api/CustomProperties.java | 99 ++++++++--- .../meteroid/api/CustomPropertiesAsync.java | 84 ++++++--- ...istCustomPropertyDefinitionsAsyncPage.java | 74 ++++++++ ...tiesListCustomPropertyDefinitionsPage.java | 74 ++++++++ src/main/java/com/meteroid/api/Customers.java | 77 ++++++-- .../java/com/meteroid/api/CustomersAsync.java | 60 +++++-- .../meteroid/api/CustomersListAsyncPage.java | 66 +++++++ .../com/meteroid/api/CustomersListPage.java | 66 +++++++ src/main/java/com/meteroid/api/Features.java | 75 ++++++-- .../java/com/meteroid/api/FeaturesAsync.java | 60 +++++-- .../meteroid/api/FeaturesListAsyncPage.java | 66 +++++++ .../com/meteroid/api/FeaturesListPage.java | 66 +++++++ src/main/java/com/meteroid/api/Invoices.java | 75 ++++++-- .../java/com/meteroid/api/InvoicesAsync.java | 60 +++++-- .../meteroid/api/InvoicesListAsyncPage.java | 66 +++++++ .../com/meteroid/api/InvoicesListPage.java | 66 +++++++ src/main/java/com/meteroid/api/Metrics.java | 78 ++++++-- .../java/com/meteroid/api/MetricsAsync.java | 61 +++++-- .../meteroid/api/MetricsListAsyncPage.java | 66 +++++++ .../com/meteroid/api/MetricsListPage.java | 66 +++++++ src/main/java/com/meteroid/api/Plans.java | 162 +++++++++++++---- .../java/com/meteroid/api/PlansAsync.java | 130 ++++++++++---- .../com/meteroid/api/PlansListAsyncPage.java | 66 +++++++ .../java/com/meteroid/api/PlansListPage.java | 65 +++++++ .../api/PlansListVersionsAsyncPage.java | 67 +++++++ .../meteroid/api/PlansListVersionsPage.java | 68 +++++++ .../com/meteroid/api/ProductFamilies.java | 78 ++++++-- .../meteroid/api/ProductFamiliesAsync.java | 61 +++++-- .../api/ProductFamiliesListAsyncPage.java | 67 +++++++ .../meteroid/api/ProductFamiliesListPage.java | 68 +++++++ src/main/java/com/meteroid/api/Products.java | 76 ++++++-- .../java/com/meteroid/api/ProductsAsync.java | 60 +++++-- .../meteroid/api/ProductsListAsyncPage.java | 66 +++++++ .../com/meteroid/api/ProductsListPage.java | 66 +++++++ .../java/com/meteroid/api/Subscriptions.java | 76 ++++++-- .../com/meteroid/api/SubscriptionsAsync.java | 60 +++++-- .../api/SubscriptionsListAsyncPage.java | 67 +++++++ .../meteroid/api/SubscriptionsListPage.java | 68 +++++++ .../meteroid/internal/MeteroidHttpClient.java | 33 +++- 63 files changed, 3792 insertions(+), 777 deletions(-) delete mode 100644 src/main/java/com/meteroid/AsyncPaginator.java delete mode 100644 src/main/java/com/meteroid/Paginator.java create mode 100644 src/main/java/com/meteroid/api/AddOnsListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/AddOnsListPage.java create mode 100644 src/main/java/com/meteroid/api/BatchJobsListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/BatchJobsListFailuresAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/BatchJobsListFailuresPage.java create mode 100644 src/main/java/com/meteroid/api/BatchJobsListPage.java create mode 100644 src/main/java/com/meteroid/api/CouponsListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/CouponsListPage.java create mode 100644 src/main/java/com/meteroid/api/CreditNotesListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/CreditNotesListPage.java create mode 100644 src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsPage.java create mode 100644 src/main/java/com/meteroid/api/CustomersListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/CustomersListPage.java create mode 100644 src/main/java/com/meteroid/api/FeaturesListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/FeaturesListPage.java create mode 100644 src/main/java/com/meteroid/api/InvoicesListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/InvoicesListPage.java create mode 100644 src/main/java/com/meteroid/api/MetricsListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/MetricsListPage.java create mode 100644 src/main/java/com/meteroid/api/PlansListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/PlansListPage.java create mode 100644 src/main/java/com/meteroid/api/PlansListVersionsAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/PlansListVersionsPage.java create mode 100644 src/main/java/com/meteroid/api/ProductFamiliesListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/ProductFamiliesListPage.java create mode 100644 src/main/java/com/meteroid/api/ProductsListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/ProductsListPage.java create mode 100644 src/main/java/com/meteroid/api/SubscriptionsListAsyncPage.java create mode 100644 src/main/java/com/meteroid/api/SubscriptionsListPage.java diff --git a/api.md b/api.md index eaf01d0..b25af4a 100644 --- a/api.md +++ b/api.md @@ -8,6 +8,12 @@ idempotency key of that call. `client.async()` has the same methods returning `CompletableFuture`s, and `client.withRawResponse()` returning `ApiResponse`s. Models are in [`com.meteroid.models`](src/main/java/com/meteroid/models). +A paginated list returns a page: the getters of its response body (`page.data()`), its items +(`page.items()`), `hasNextPage()` and `nextPage()`. Iterating it, or its `stream()`, yields every +item from that page on, and `pages()` every page, fetching the next ones on demand. `body()` is +the response body as received. The async client's pages have `nextPage()`, `forEach(...)`, +`forEachPage(...)` and `toList()`, returning `CompletableFuture`s. + [Add ons](#add-ons) · [Batch jobs](#batch-jobs) · [Checkout sessions](#checkout-sessions) · [Connect](#connect) · [Coupons](#coupons) · [Credit notes](#credit-notes) · [Custom properties](#custom-properties) · [Customers](#customers) · [Entitlements](#entitlements) · [Events](#events) · [Features](#features) · [Invoices](#invoices) · [Metrics](#metrics) · [Oauth](#oauth) · [Oauth apps](#oauth-apps) · [Plans](#plans) · [Product families](#product-families) · [Products](#products) · [Subscriptions](#subscriptions) · [Usage](#usage) ## Add ons @@ -16,7 +22,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `AddOnListResponse client.addOns().list([AddOnsListOptions options])` | `GET /api/v1/addons` | [`AddOnListResponse`](src/main/java/com/meteroid/models/AddOnListResponse.java) | +| `AddOnsListPage client.addOns().list([AddOnsListOptions options])` | `GET /api/v1/addons` | [page](src/main/java/com/meteroid/api/AddOnsListPage.java) of [`AddOn`](src/main/java/com/meteroid/models/AddOn.java), with the properties of [`AddOnListResponse`](src/main/java/com/meteroid/models/AddOnListResponse.java) | | `AddOn client.addOns().create(CreateAddOnRequest createAddOnRequest)` | `POST /api/v1/addons` | [`AddOn`](src/main/java/com/meteroid/models/AddOn.java) | | `AddOn client.addOns().retrieve(String addonId)` | `GET /api/v1/addons/{addon_id}` | [`AddOn`](src/main/java/com/meteroid/models/AddOn.java) | | `AddOn client.addOns().update(String addonId, UpdateAddOnRequest updateAddOnRequest)` | `PATCH /api/v1/addons/{addon_id}` | [`AddOn`](src/main/java/com/meteroid/models/AddOn.java) | @@ -31,9 +37,9 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `BatchJobListResponse client.batchJobs().list([BatchJobsListOptions options])` | `GET /api/v1/batch-jobs` | [`BatchJobListResponse`](src/main/java/com/meteroid/models/BatchJobListResponse.java) | +| `BatchJobsListPage client.batchJobs().list([BatchJobsListOptions options])` | `GET /api/v1/batch-jobs` | [page](src/main/java/com/meteroid/api/BatchJobsListPage.java) of [`BatchJobResponse`](src/main/java/com/meteroid/models/BatchJobResponse.java), with the properties of [`BatchJobListResponse`](src/main/java/com/meteroid/models/BatchJobListResponse.java) | | `BatchJobDetailResponse client.batchJobs().retrieve(String batchJobId)` | `GET /api/v1/batch-jobs/{batch_job_id}` | [`BatchJobDetailResponse`](src/main/java/com/meteroid/models/BatchJobDetailResponse.java) | -| `BatchJobFailuresResponse client.batchJobs().listFailures(String batchJobId, [BatchJobsListFailuresOptions options])` | `GET /api/v1/batch-jobs/{batch_job_id}/failures` | [`BatchJobFailuresResponse`](src/main/java/com/meteroid/models/BatchJobFailuresResponse.java) | +| `BatchJobsListFailuresPage client.batchJobs().listFailures(String batchJobId, [BatchJobsListFailuresOptions options])` | `GET /api/v1/batch-jobs/{batch_job_id}/failures` | [page](src/main/java/com/meteroid/api/BatchJobsListFailuresPage.java) of [`BatchJobItemFailureResponse`](src/main/java/com/meteroid/models/BatchJobItemFailureResponse.java), with the properties of [`BatchJobFailuresResponse`](src/main/java/com/meteroid/models/BatchJobFailuresResponse.java) | ## Checkout sessions @@ -64,7 +70,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `CouponListResponse client.coupons().list([CouponsListOptions options])` | `GET /api/v1/coupons` | [`CouponListResponse`](src/main/java/com/meteroid/models/CouponListResponse.java) | +| `CouponsListPage client.coupons().list([CouponsListOptions options])` | `GET /api/v1/coupons` | [page](src/main/java/com/meteroid/api/CouponsListPage.java) of [`Coupon`](src/main/java/com/meteroid/models/Coupon.java), with the properties of [`CouponListResponse`](src/main/java/com/meteroid/models/CouponListResponse.java) | | `Coupon client.coupons().create(CreateCouponRequest createCouponRequest)` | `POST /api/v1/coupons` | [`Coupon`](src/main/java/com/meteroid/models/Coupon.java) | | `Coupon client.coupons().retrieve(String couponId)` | `GET /api/v1/coupons/{coupon_id}` | [`Coupon`](src/main/java/com/meteroid/models/Coupon.java) | | `Coupon client.coupons().update(String couponId, UpdateCouponRequest updateCouponRequest)` | `PATCH /api/v1/coupons/{coupon_id}` | [`Coupon`](src/main/java/com/meteroid/models/Coupon.java) | @@ -79,7 +85,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `CreditNoteListResponse client.creditNotes().list([CreditNotesListOptions options])` | `GET /api/v1/credit-notes` | [`CreditNoteListResponse`](src/main/java/com/meteroid/models/CreditNoteListResponse.java) | +| `CreditNotesListPage client.creditNotes().list([CreditNotesListOptions options])` | `GET /api/v1/credit-notes` | [page](src/main/java/com/meteroid/api/CreditNotesListPage.java) of [`CreditNote`](src/main/java/com/meteroid/models/CreditNote.java), with the properties of [`CreditNoteListResponse`](src/main/java/com/meteroid/models/CreditNoteListResponse.java) | | `CreditNote client.creditNotes().retrieve(String creditNoteId)` | `GET /api/v1/credit-notes/{credit_note_id}` | [`CreditNote`](src/main/java/com/meteroid/models/CreditNote.java) | | `CreditNote client.creditNotes().updateCustomProperties(String creditNoteId, CreditNoteCustomPropertiesRequest creditNoteCustomPropertiesRequest)` | `PATCH /api/v1/credit-notes/{credit_note_id}/custom-properties` | [`CreditNote`](src/main/java/com/meteroid/models/CreditNote.java) | | `byte[] client.creditNotes().download(String creditNoteId)` | `GET /api/v1/credit-notes/{credit_note_id}/download` | bytes | @@ -91,7 +97,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `CustomPropertyDefinitionListResponse client.customProperties().listCustomPropertyDefinitions([CustomPropertiesListCustomPropertyDefinitionsOptions options])` | `GET /api/v1/custom-property-definitions` | [`CustomPropertyDefinitionListResponse`](src/main/java/com/meteroid/models/CustomPropertyDefinitionListResponse.java) | +| `CustomPropertiesListCustomPropertyDefinitionsPage client.customProperties().listCustomPropertyDefinitions([CustomPropertiesListCustomPropertyDefinitionsOptions options])` | `GET /api/v1/custom-property-definitions` | [page](src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsPage.java) of [`CustomPropertyDefinition`](src/main/java/com/meteroid/models/CustomPropertyDefinition.java), with the properties of [`CustomPropertyDefinitionListResponse`](src/main/java/com/meteroid/models/CustomPropertyDefinitionListResponse.java) | | `CustomPropertyDefinition client.customProperties().createCustomPropertyDefinition(CustomPropertyDefinitionCreateRequest customPropertyDefinitionCreateRequest)` | `POST /api/v1/custom-property-definitions` | [`CustomPropertyDefinition`](src/main/java/com/meteroid/models/CustomPropertyDefinition.java) | | `CustomPropertyDefinition client.customProperties().retrieveCustomPropertyDefinition(String id)` | `GET /api/v1/custom-property-definitions/{id}` | [`CustomPropertyDefinition`](src/main/java/com/meteroid/models/CustomPropertyDefinition.java) | | `CustomPropertyDefinition client.customProperties().updateCustomPropertyDefinition(String id, CustomPropertyDefinitionUpdateRequest customPropertyDefinitionUpdateRequest)` | `PUT /api/v1/custom-property-definitions/{id}` | [`CustomPropertyDefinition`](src/main/java/com/meteroid/models/CustomPropertyDefinition.java) | @@ -103,7 +109,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `CustomerListResponse client.customers().list([CustomersListOptions options])` | `GET /api/v1/customers` | [`CustomerListResponse`](src/main/java/com/meteroid/models/CustomerListResponse.java) | +| `CustomersListPage client.customers().list([CustomersListOptions options])` | `GET /api/v1/customers` | [page](src/main/java/com/meteroid/api/CustomersListPage.java) of [`Customer`](src/main/java/com/meteroid/models/Customer.java), with the properties of [`CustomerListResponse`](src/main/java/com/meteroid/models/CustomerListResponse.java) | | `Customer client.customers().create(CustomerCreateRequest customerCreateRequest)` | `POST /api/v1/customers` | [`Customer`](src/main/java/com/meteroid/models/Customer.java) | | `Customer client.customers().retrieve(String idOrAlias)` | `GET /api/v1/customers/{id_or_alias}` | [`Customer`](src/main/java/com/meteroid/models/Customer.java) | | `Customer client.customers().replace(String idOrAlias, CustomerUpdateRequest customerUpdateRequest)` | `PUT /api/v1/customers/{id_or_alias}` | [`Customer`](src/main/java/com/meteroid/models/Customer.java) | @@ -137,7 +143,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `FeatureListResponse client.features().list([FeaturesListOptions options])` | `GET /api/v1/features` | [`FeatureListResponse`](src/main/java/com/meteroid/models/FeatureListResponse.java) | +| `FeaturesListPage client.features().list([FeaturesListOptions options])` | `GET /api/v1/features` | [page](src/main/java/com/meteroid/api/FeaturesListPage.java) of [`Feature`](src/main/java/com/meteroid/models/Feature.java), with the properties of [`FeatureListResponse`](src/main/java/com/meteroid/models/FeatureListResponse.java) | | `Feature client.features().create(CreateFeatureRequest createFeatureRequest)` | `POST /api/v1/features` | [`Feature`](src/main/java/com/meteroid/models/Feature.java) | | `Feature client.features().retrieve(String idOrCode)` | `GET /api/v1/features/{id_or_code}` | [`Feature`](src/main/java/com/meteroid/models/Feature.java) | | `Feature client.features().update(String idOrCode, UpdateFeatureRequest updateFeatureRequest)` | `PATCH /api/v1/features/{id_or_code}` | [`Feature`](src/main/java/com/meteroid/models/Feature.java) | @@ -150,7 +156,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `InvoiceListResponse client.invoices().list([InvoicesListOptions options])` | `GET /api/v1/invoices` | [`InvoiceListResponse`](src/main/java/com/meteroid/models/InvoiceListResponse.java) | +| `InvoicesListPage client.invoices().list([InvoicesListOptions options])` | `GET /api/v1/invoices` | [page](src/main/java/com/meteroid/api/InvoicesListPage.java) of [`Invoice`](src/main/java/com/meteroid/models/Invoice.java), with the properties of [`InvoiceListResponse`](src/main/java/com/meteroid/models/InvoiceListResponse.java) | | `Invoice client.invoices().retrieve(String invoiceId)` | `GET /api/v1/invoices/{invoice_id}` | [`Invoice`](src/main/java/com/meteroid/models/Invoice.java) | | `Invoice client.invoices().updateCustomProperties(String invoiceId, InvoiceCustomPropertiesRequest invoiceCustomPropertiesRequest)` | `PATCH /api/v1/invoices/{invoice_id}/custom-properties` | [`Invoice`](src/main/java/com/meteroid/models/Invoice.java) | | `byte[] client.invoices().download(String invoiceId)` | `GET /api/v1/invoices/{invoice_id}/download` | bytes | @@ -163,7 +169,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `MetricListResponse client.metrics().list([MetricsListOptions options])` | `GET /api/v1/metrics` | [`MetricListResponse`](src/main/java/com/meteroid/models/MetricListResponse.java) | +| `MetricsListPage client.metrics().list([MetricsListOptions options])` | `GET /api/v1/metrics` | [page](src/main/java/com/meteroid/api/MetricsListPage.java) of [`MetricSummary`](src/main/java/com/meteroid/models/MetricSummary.java), with the properties of [`MetricListResponse`](src/main/java/com/meteroid/models/MetricListResponse.java) | | `Metric client.metrics().create(CreateMetricRequest createMetricRequest)` | `POST /api/v1/metrics` | [`Metric`](src/main/java/com/meteroid/models/Metric.java) | | `Metric client.metrics().retrieve(String metricId)` | `GET /api/v1/metrics/{metric_id}` | [`Metric`](src/main/java/com/meteroid/models/Metric.java) | | `Metric client.metrics().update(String metricId, UpdateMetricRequest updateMetricRequest)` | `PATCH /api/v1/metrics/{metric_id}` | [`Metric`](src/main/java/com/meteroid/models/Metric.java) | @@ -200,7 +206,7 @@ idempotency key of that call. `client.async()` has the same methods returning | --- | --- | --- | | `ResolvedEntitlementListResponse client.plans().listPlanVersionEntitlements(String planVersionId)` | `GET /api/v1/plan-versions/{plan_version_id}/entitlements` | [`ResolvedEntitlementListResponse`](src/main/java/com/meteroid/models/ResolvedEntitlementListResponse.java) | | `EntitlementListResponse client.plans().createPlanVersionEntitlement(String planVersionId, CreateEntitlementsRequest createEntitlementsRequest)` | `POST /api/v1/plan-versions/{plan_version_id}/entitlements` | [`EntitlementListResponse`](src/main/java/com/meteroid/models/EntitlementListResponse.java) | -| `PlanListResponse client.plans().list([PlansListOptions options])` | `GET /api/v1/plans` | [`PlanListResponse`](src/main/java/com/meteroid/models/PlanListResponse.java) | +| `PlansListPage client.plans().list([PlansListOptions options])` | `GET /api/v1/plans` | [page](src/main/java/com/meteroid/api/PlansListPage.java) of [`Plan`](src/main/java/com/meteroid/models/Plan.java), with the properties of [`PlanListResponse`](src/main/java/com/meteroid/models/PlanListResponse.java) | | `Plan client.plans().create(CreatePlanRequest createPlanRequest)` | `POST /api/v1/plans` | [`Plan`](src/main/java/com/meteroid/models/Plan.java) | | `MinimumCommitment client.plans().updateVersionMinimum(String planVersionId, MinimumCommitment minimumCommitment)` | `PUT /api/v1/plans/versions/{plan_version_id}/minimum` | [`MinimumCommitment`](src/main/java/com/meteroid/models/MinimumCommitment.java) | | `void client.plans().deleteVersionMinimum(String planVersionId)` | `DELETE /api/v1/plans/versions/{plan_version_id}/minimum` | nothing | @@ -210,7 +216,7 @@ idempotency key of that call. `client.async()` has the same methods returning | `void client.plans().archive(String planId)` | `POST /api/v1/plans/{plan_id}/archive` | nothing | | `Plan client.plans().publish(String planId)` | `POST /api/v1/plans/{plan_id}/publish` | [`Plan`](src/main/java/com/meteroid/models/Plan.java) | | `void client.plans().unarchive(String planId)` | `POST /api/v1/plans/{plan_id}/unarchive` | nothing | -| `PlanVersionListResponse client.plans().listVersions(String planId, [PlansListVersionsOptions options])` | `GET /api/v1/plans/{plan_id}/versions` | [`PlanVersionListResponse`](src/main/java/com/meteroid/models/PlanVersionListResponse.java) | +| `PlansListVersionsPage client.plans().listVersions(String planId, [PlansListVersionsOptions options])` | `GET /api/v1/plans/{plan_id}/versions` | [page](src/main/java/com/meteroid/api/PlansListVersionsPage.java) of [`PlanVersionSummary`](src/main/java/com/meteroid/models/PlanVersionSummary.java), with the properties of [`PlanVersionListResponse`](src/main/java/com/meteroid/models/PlanVersionListResponse.java) | ## Product families @@ -218,7 +224,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `ProductFamilyListResponse client.productFamilies().list([ProductFamiliesListOptions options])` | `GET /api/v1/product_families` | [`ProductFamilyListResponse`](src/main/java/com/meteroid/models/ProductFamilyListResponse.java) | +| `ProductFamiliesListPage client.productFamilies().list([ProductFamiliesListOptions options])` | `GET /api/v1/product_families` | [page](src/main/java/com/meteroid/api/ProductFamiliesListPage.java) of [`ProductFamily`](src/main/java/com/meteroid/models/ProductFamily.java), with the properties of [`ProductFamilyListResponse`](src/main/java/com/meteroid/models/ProductFamilyListResponse.java) | | `ProductFamily client.productFamilies().create(ProductFamilyCreateRequest productFamilyCreateRequest)` | `POST /api/v1/product_families` | [`ProductFamily`](src/main/java/com/meteroid/models/ProductFamily.java) | | `ProductFamily client.productFamilies().retrieve(String idOrAlias)` | `GET /api/v1/product_families/{id_or_alias}` | [`ProductFamily`](src/main/java/com/meteroid/models/ProductFamily.java) | @@ -228,7 +234,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `ProductListResponse client.products().list([ProductsListOptions options])` | `GET /api/v1/products` | [`ProductListResponse`](src/main/java/com/meteroid/models/ProductListResponse.java) | +| `ProductsListPage client.products().list([ProductsListOptions options])` | `GET /api/v1/products` | [page](src/main/java/com/meteroid/api/ProductsListPage.java) of [`Product`](src/main/java/com/meteroid/models/Product.java), with the properties of [`ProductListResponse`](src/main/java/com/meteroid/models/ProductListResponse.java) | | `Product client.products().create(CreateProductRequest createProductRequest)` | `POST /api/v1/products` | [`Product`](src/main/java/com/meteroid/models/Product.java) | | `Product client.products().retrieve(String productId)` | `GET /api/v1/products/{product_id}` | [`Product`](src/main/java/com/meteroid/models/Product.java) | | `Product client.products().update(String productId, UpdateProductRequest updateProductRequest)` | `PATCH /api/v1/products/{product_id}` | [`Product`](src/main/java/com/meteroid/models/Product.java) | @@ -243,7 +249,7 @@ idempotency key of that call. `client.async()` has the same methods returning | Method | Request | Returns | | --- | --- | --- | -| `SubscriptionListResponse client.subscriptions().list([SubscriptionsListOptions options])` | `GET /api/v1/subscriptions` | [`SubscriptionListResponse`](src/main/java/com/meteroid/models/SubscriptionListResponse.java) | +| `SubscriptionsListPage client.subscriptions().list([SubscriptionsListOptions options])` | `GET /api/v1/subscriptions` | [page](src/main/java/com/meteroid/api/SubscriptionsListPage.java) of [`Subscription`](src/main/java/com/meteroid/models/Subscription.java), with the properties of [`SubscriptionListResponse`](src/main/java/com/meteroid/models/SubscriptionListResponse.java) | | `SubscriptionDetails client.subscriptions().create(SubscriptionCreateRequest subscriptionCreateRequest)` | `POST /api/v1/subscriptions` | [`SubscriptionDetails`](src/main/java/com/meteroid/models/SubscriptionDetails.java) | | `SubscriptionDetails client.subscriptions().retrieve(String subscriptionId)` | `GET /api/v1/subscriptions/{subscription_id}` | [`SubscriptionDetails`](src/main/java/com/meteroid/models/SubscriptionDetails.java) | | `SubscriptionUpdateResponse client.subscriptions().update(String subscriptionId, SubscriptionUpdateRequest subscriptionUpdateRequest)` | `PATCH /api/v1/subscriptions/{subscription_id}` | [`SubscriptionUpdateResponse`](src/main/java/com/meteroid/models/SubscriptionUpdateResponse.java) | diff --git a/src/main/java/com/meteroid/AsyncPage.java b/src/main/java/com/meteroid/AsyncPage.java index 3ee4dfe..9707e06 100644 --- a/src/main/java/com/meteroid/AsyncPage.java +++ b/src/main/java/com/meteroid/AsyncPage.java @@ -6,34 +6,30 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.CompletableFuture; +import java.util.function.Consumer; import java.util.function.Supplier; /** * One page of a paginated list operation of the async client: its items, and the way to the next - * page. + * page. Each list operation returns its own subclass, which also has the getters of the response + * body. * + * @param

the type of the pages * @param the type of the items */ -public final class AsyncPage { +public abstract class AsyncPage

, T> { private final List items; - private final Supplier>> next; - - private AsyncPage(List items, Supplier>> next) { - this.items = Collections.unmodifiableList(new ArrayList<>(items)); - this.next = next; - } + private final Supplier> next; /** * A page, built by the SDK. * - * @param the type of the items * @param items the items of the page * @param next fetches the next page, or null on the last page - * @return the page */ - public static AsyncPage of( - List items, Supplier>> next) { - return new AsyncPage<>(items, next); + protected AsyncPage(List items, Supplier> next) { + this.items = Collections.unmodifiableList(new ArrayList<>(items)); + this.next = next; } /** @@ -41,7 +37,7 @@ public static AsyncPage of( * * @return the items, unmodifiable */ - public List items() { + public final List items() { return items; } @@ -50,7 +46,7 @@ public List items() { * * @return false on the last page */ - public boolean hasNextPage() { + public final boolean hasNextPage() { return next != null; } @@ -59,7 +55,7 @@ public boolean hasNextPage() { * * @return the next page, failed with {@link NoSuchElementException} on the last page */ - public CompletableFuture> nextPage() { + public final CompletableFuture

nextPage() { if (next == null) { return CompletableFuture.failedFuture( new NoSuchElementException("this is the last page")); @@ -67,8 +63,45 @@ public CompletableFuture> nextPage() { return next.get(); } - @Override - public String toString() { - return "AsyncPage{items=" + items + ", hasNextPage=" + hasNextPage() + "}"; + /** + * Calls {@code action} with this page and each one after it, fetching the next page once the + * action returns. + * + * @param action called with each page, in order + * @return completes after the last page, or with the first error + */ + public final CompletableFuture forEachPage(Consumer action) { + P page = self(); + action.accept(page); + if (!page.hasNextPage()) { + return CompletableFuture.completedFuture(null); + } + return page.nextPage().thenCompose(next -> next.forEachPage(action)); + } + + /** + * Calls {@code action} with every item from this page on, fetching the next page once the items + * of one are done. + * + * @param action called with each item, in order + * @return completes after the last item, or with the first error + */ + public final CompletableFuture forEach(Consumer action) { + return forEachPage(page -> page.items().forEach(action)); + } + + /** + * Collects every item from this page on. + * + * @return the items of this page and the ones after it + */ + public final CompletableFuture> toList() { + List all = new ArrayList<>(); + return forEach(all::add).thenApply(done -> all); + } + + @SuppressWarnings("unchecked") + private P self() { + return (P) this; } } diff --git a/src/main/java/com/meteroid/AsyncPaginator.java b/src/main/java/com/meteroid/AsyncPaginator.java deleted file mode 100644 index 3f21e71..0000000 --- a/src/main/java/com/meteroid/AsyncPaginator.java +++ /dev/null @@ -1,63 +0,0 @@ -// this file is @generated by Perseid; edit the shared runtime template. -package com.meteroid; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CompletableFuture; -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * Every item of a paginated list operation of the async client, fetched page by page. - * - * @param the type of the items - */ -public final class AsyncPaginator { - private final Supplier>> first; - - /** - * A paginator, built by the SDK. - * - * @param first fetches the first page - */ - public AsyncPaginator(Supplier>> first) { - this.first = first; - } - - /** - * Fetches the first page. - * - * @return the first page - */ - public CompletableFuture> firstPage() { - return first.get(); - } - - /** - * Calls {@code action} with every item, fetching the next page once the items of one are done. - * - * @param action called with each item, in order - * @return completes after the last item, or with the first error - */ - public CompletableFuture forEach(Consumer action) { - return firstPage().thenCompose(page -> forEach(page, action)); - } - - /** - * Collects every item. - * - * @return the items of every page - */ - public CompletableFuture> toList() { - List items = new ArrayList<>(); - return forEach(items::add).thenApply(done -> items); - } - - private CompletableFuture forEach(AsyncPage page, Consumer action) { - page.items().forEach(action); - if (!page.hasNextPage()) { - return CompletableFuture.completedFuture(null); - } - return page.nextPage().thenCompose(next -> forEach(next, action)); - } -} diff --git a/src/main/java/com/meteroid/Meteroid.java b/src/main/java/com/meteroid/Meteroid.java index 8fa8d3c..2f06564 100644 --- a/src/main/java/com/meteroid/Meteroid.java +++ b/src/main/java/com/meteroid/Meteroid.java @@ -42,13 +42,15 @@ * } * *

Without an API key, the client reads {@value MeteroidOptions#API_KEY_ENV}, and {@value - * MeteroidOptions#BASE_URL_ENV} overrides the base URL, which the API has no default for: one of - * them is required. + * MeteroidOptions#BASE_URL_ENV} overrides the base URL, {@link #DEFAULT_BASE_URL} otherwise. */ public final class Meteroid implements AutoCloseable { private static final Map SECURITY_SCHEMES = Map.ofEntries(Map.entry("bearer_auth", new MeteroidAuth.Scheme("bearer", null, null))); + /** The base URL of the API when neither the options nor the environment set one. */ + public static final String DEFAULT_BASE_URL = "https://api.meteroid.com"; + private final MeteroidOptions options; private final MeteroidHttpClient httpClient; private final WithRawResponse withRawResponse; @@ -107,17 +109,12 @@ public Meteroid(String apiKey, MeteroidOptions options) { * A client with custom options. * * @param options the options; the environment supplies the API key and base URL they leave out - * @throws IllegalStateException when neither the options nor the environment set a base URL */ public Meteroid(MeteroidOptions options) { this.options = options; - String baseUrl = options.baseUrl().orElseGet(() -> env(MeteroidOptions.BASE_URL_ENV, null)); - if (baseUrl == null) { - throw new IllegalStateException( - "no base URL: set MeteroidOptions.builder().baseUrl(...) or the " - + MeteroidOptions.BASE_URL_ENV - + " environment variable"); - } + String baseUrl = + options.baseUrl() + .orElseGet(() -> env(MeteroidOptions.BASE_URL_ENV, DEFAULT_BASE_URL)); HttpUrl parsedUrl = HttpUrl.parse(baseUrl); if (parsedUrl == null) { throw new IllegalArgumentException("Invalid base URL: " + baseUrl); diff --git a/src/main/java/com/meteroid/Page.java b/src/main/java/com/meteroid/Page.java index dab46c9..9c4a505 100644 --- a/src/main/java/com/meteroid/Page.java +++ b/src/main/java/com/meteroid/Page.java @@ -3,34 +3,36 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.function.Supplier; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; /** - * One page of a paginated list operation: its items, and the way to the next page. + * One page of a paginated list operation: its items, and the way to the next page. Each list + * operation returns its own subclass, which also has the getters of the response body. * + *

Iterating a page yields every item from this page on, fetching the next pages as the iteration + * goes; each iteration fetches them again. + * + * @param

the type of the pages * @param the type of the items */ -public final class Page { +public abstract class Page

, T> implements Iterable { private final List items; - private final Supplier> next; - - private Page(List items, Supplier> next) { - this.items = Collections.unmodifiableList(new ArrayList<>(items)); - this.next = next; - } + private final Supplier

next; /** * A page, built by the SDK. * - * @param the type of the items * @param items the items of the page * @param next fetches the next page, or null on the last page - * @return the page */ - public static Page of(List items, Supplier> next) { - return new Page<>(items, next); + protected Page(List items, Supplier

next) { + this.items = Collections.unmodifiableList(new ArrayList<>(items)); + this.next = next; } /** @@ -38,7 +40,7 @@ public static Page of(List items, Supplier> next) { * * @return the items, unmodifiable */ - public List items() { + public final List items() { return items; } @@ -47,7 +49,7 @@ public List items() { * * @return false on the last page */ - public boolean hasNextPage() { + public final boolean hasNextPage() { return next != null; } @@ -57,15 +59,75 @@ public boolean hasNextPage() { * @return the next page * @throws NoSuchElementException on the last page */ - public Page nextPage() { + public final P nextPage() { if (next == null) { throw new NoSuchElementException("this is the last page"); } return next.get(); } + /** + * This page and the ones after it, fetched as the iteration goes. + * + * @return the pages, from this one + */ + public final Iterable

pages() { + return () -> + new Iterator<>() { + private P current; + + @Override + public boolean hasNext() { + return current == null || current.hasNextPage(); + } + + @Override + public P next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + current = current == null ? self() : current.nextPage(); + return current; + } + }; + } + + /** + * The items of this page and the ones after it, as a sequential stream fetching pages on + * demand. + * + * @return every item from this page on + */ + public final Stream stream() { + return StreamSupport.stream(spliterator(), false); + } + @Override - public String toString() { - return "Page{items=" + items + ", hasNextPage=" + hasNextPage() + "}"; + public final Iterator iterator() { + Iterator

pages = pages().iterator(); + return new Iterator<>() { + private Iterator items = Collections.emptyIterator(); + + @Override + public boolean hasNext() { + while (!items.hasNext() && pages.hasNext()) { + items = pages.next().items().iterator(); + } + return items.hasNext(); + } + + @Override + public T next() { + if (!hasNext()) { + throw new NoSuchElementException(); + } + return items.next(); + } + }; + } + + @SuppressWarnings("unchecked") + private P self() { + return (P) this; } } diff --git a/src/main/java/com/meteroid/Paginator.java b/src/main/java/com/meteroid/Paginator.java deleted file mode 100644 index 7a88500..0000000 --- a/src/main/java/com/meteroid/Paginator.java +++ /dev/null @@ -1,98 +0,0 @@ -// this file is @generated by Perseid; edit the shared runtime template. -package com.meteroid; - -import java.util.Collections; -import java.util.Iterator; -import java.util.NoSuchElementException; -import java.util.function.Supplier; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -/** - * Every item of a paginated list operation, fetched page by page as the iteration goes. Each - * iteration starts over from the first page; {@link #pages()} goes page by page instead. - * - * @param the type of the items - */ -public final class Paginator implements Iterable { - private final Supplier> first; - - /** - * A paginator, built by the SDK. - * - * @param first fetches the first page - */ - public Paginator(Supplier> first) { - this.first = first; - } - - /** - * Fetches the first page. - * - * @return the first page - */ - public Page firstPage() { - return first.get(); - } - - /** - * The pages, fetched as the iteration goes. - * - * @return the pages, from the first one - */ - public Iterable> pages() { - return () -> - new Iterator<>() { - private Page current; - private boolean started; - - @Override - public boolean hasNext() { - return !started || current.hasNextPage(); - } - - @Override - public Page next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - current = started ? current.nextPage() : firstPage(); - started = true; - return current; - } - }; - } - - /** - * The items, as a sequential stream fetching pages on demand. - * - * @return the items of every page - */ - public Stream stream() { - return StreamSupport.stream(spliterator(), false); - } - - @Override - public Iterator iterator() { - Iterator> pages = pages().iterator(); - return new Iterator<>() { - private Iterator items = Collections.emptyIterator(); - - @Override - public boolean hasNext() { - while (!items.hasNext() && pages.hasNext()) { - items = pages.next().items().iterator(); - } - return items.hasNext(); - } - - @Override - public T next() { - if (!hasNext()) { - throw new NoSuchElementException(); - } - return items.next(); - } - }; - } -} diff --git a/src/main/java/com/meteroid/api/AddOns.java b/src/main/java/com/meteroid/api/AddOns.java index fba154e..b2712e1 100644 --- a/src/main/java/com/meteroid/api/AddOns.java +++ b/src/main/java/com/meteroid/api/AddOns.java @@ -15,6 +15,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -47,9 +48,9 @@ public WithRawResponse withRawResponse() { /** * List add-ons * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public AddOnListResponse list() { + public AddOnsListPage list() { return list(AddOnsListOptions.none(), RequestOptions.none()); } @@ -57,9 +58,9 @@ public AddOnListResponse list() { * List add-ons * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public AddOnListResponse list(final AddOnsListOptions options) { + public AddOnsListPage list(final AddOnsListOptions options) { return list(options, RequestOptions.none()); } @@ -67,9 +68,9 @@ public AddOnListResponse list(final AddOnsListOptions options) { * List add-ons * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public AddOnListResponse list(final RequestOptions requestOptions) { + public AddOnsListPage list(final RequestOptions requestOptions) { return list(AddOnsListOptions.none(), requestOptions); } @@ -78,11 +79,11 @@ public AddOnListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public AddOnListResponse list( + public AddOnsListPage list( final AddOnsListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -119,6 +120,40 @@ MeteroidHttpClient.Exchange exchangeList( .returning(AddOnListResponse.class); } + private AddOnsListPage pageOfList( + AddOnListResponse response, + final AddOnsListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new AddOnsListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(AddOnListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList(AddOnListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create an add-on * @@ -393,9 +428,9 @@ private WithRawResponse() {} /** * List add-ons * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(AddOnsListOptions.none(), RequestOptions.none()); } @@ -403,9 +438,9 @@ public ApiResponse list() { * List add-ons * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final AddOnsListOptions options) { + public ApiResponse list(final AddOnsListOptions options) { return list(options, RequestOptions.none()); } @@ -413,9 +448,9 @@ public ApiResponse list(final AddOnsListOptions options) { * List add-ons * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(AddOnsListOptions.none(), requestOptions); } @@ -424,11 +459,16 @@ public ApiResponse list(final RequestOptions requestOptions) * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final AddOnsListOptions options, final RequestOptions requestOptions) { - return AddOns.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/AddOnsAsync.java b/src/main/java/com/meteroid/api/AddOnsAsync.java index a01df16..a963298 100644 --- a/src/main/java/com/meteroid/api/AddOnsAsync.java +++ b/src/main/java/com/meteroid/api/AddOnsAsync.java @@ -11,6 +11,7 @@ import com.meteroid.models.ResolvedEntitlementListResponse; import com.meteroid.models.UpdateAddOnRequest; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -43,9 +44,9 @@ public WithRawResponse withRawResponse() { /** * List add-ons * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(AddOnsListOptions.none(), RequestOptions.none()); } @@ -53,9 +54,9 @@ public CompletableFuture list() { * List add-ons * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final AddOnsListOptions options) { + public CompletableFuture list(final AddOnsListOptions options) { return list(options, RequestOptions.none()); } @@ -63,9 +64,9 @@ public CompletableFuture list(final AddOnsListOptions options * List add-ons * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(AddOnsListOptions.none(), requestOptions); } @@ -74,11 +75,27 @@ public CompletableFuture list(final RequestOptions requestOpt * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final AddOnsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private AddOnsListAsyncPage pageOfList( + AddOnListResponse response, + final AddOnsListOptions options, + final RequestOptions requestOptions) { + List items = AddOns.itemsOfList(response); + Integer next = AddOns.nextOfList(response, items, options.page().orElse(0)); + return new AddOnsListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -258,9 +275,9 @@ private WithRawResponse() {} /** * List add-ons * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(AddOnsListOptions.none(), RequestOptions.none()); } @@ -268,9 +285,9 @@ public CompletableFuture> list() { * List add-ons * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final AddOnsListOptions options) { return list(options, RequestOptions.none()); } @@ -279,9 +296,9 @@ public CompletableFuture> list( * List add-ons * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(AddOnsListOptions.none(), requestOptions); } @@ -291,11 +308,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final AddOnsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/AddOnsListAsyncPage.java b/src/main/java/com/meteroid/api/AddOnsListAsyncPage.java new file mode 100644 index 0000000..9b32fd5 --- /dev/null +++ b/src/main/java/com/meteroid/api/AddOnsListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.AddOn; +import com.meteroid.models.AddOnListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link AddOnsAsync#list}: the {@link AddOn} items of one response, and the properties + * of its body, {@link AddOnListResponse}. + */ +public final class AddOnsListAsyncPage extends AsyncPage { + private final AddOnListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public AddOnsListAsyncPage( + AddOnListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public AddOnListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "AddOnsListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/AddOnsListPage.java b/src/main/java/com/meteroid/api/AddOnsListPage.java new file mode 100644 index 0000000..5e9d873 --- /dev/null +++ b/src/main/java/com/meteroid/api/AddOnsListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.AddOn; +import com.meteroid.models.AddOnListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link AddOns#list}: the {@link AddOn} items of one response, and the properties of its + * body, {@link AddOnListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class AddOnsListPage extends Page { + private final AddOnListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public AddOnsListPage( + AddOnListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public AddOnListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "AddOnsListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/BatchJobs.java b/src/main/java/com/meteroid/api/BatchJobs.java index 83cac64..b9c8853 100644 --- a/src/main/java/com/meteroid/api/BatchJobs.java +++ b/src/main/java/com/meteroid/api/BatchJobs.java @@ -7,7 +7,9 @@ import com.meteroid.internal.Utils; import com.meteroid.models.BatchJobDetailResponse; import com.meteroid.models.BatchJobFailuresResponse; +import com.meteroid.models.BatchJobItemFailureResponse; import com.meteroid.models.BatchJobListResponse; +import com.meteroid.models.BatchJobResponse; import com.meteroid.models.BatchJobStatus; import com.meteroid.models.BatchJobType; @@ -46,9 +48,9 @@ public WithRawResponse withRawResponse() { /** * List batch jobs with optional filtering by type and status. * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobListResponse list() { + public BatchJobsListPage list() { return list(BatchJobsListOptions.none(), RequestOptions.none()); } @@ -56,9 +58,9 @@ public BatchJobListResponse list() { * List batch jobs with optional filtering by type and status. * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobListResponse list(final BatchJobsListOptions options) { + public BatchJobsListPage list(final BatchJobsListOptions options) { return list(options, RequestOptions.none()); } @@ -66,9 +68,9 @@ public BatchJobListResponse list(final BatchJobsListOptions options) { * List batch jobs with optional filtering by type and status. * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobListResponse list(final RequestOptions requestOptions) { + public BatchJobsListPage list(final RequestOptions requestOptions) { return list(BatchJobsListOptions.none(), requestOptions); } @@ -77,11 +79,11 @@ public BatchJobListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobListResponse list( + public BatchJobsListPage list( final BatchJobsListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -110,6 +112,41 @@ MeteroidHttpClient.Exchange exchangeList( .returning(BatchJobListResponse.class); } + private BatchJobsListPage pageOfList( + BatchJobListResponse response, + final BatchJobsListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new BatchJobsListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(BatchJobListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList( + BatchJobListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Get batch job detail * @@ -156,9 +193,9 @@ MeteroidHttpClient.Exchange exchangeRetrieve( *

Retrieve paginated failures for a batch job. * * @param batchJobId the {@code batch_job_id} path parameter - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobFailuresResponse listFailures(final String batchJobId) { + public BatchJobsListFailuresPage listFailures(final String batchJobId) { return listFailures(batchJobId, BatchJobsListFailuresOptions.none(), RequestOptions.none()); } @@ -169,9 +206,9 @@ public BatchJobFailuresResponse listFailures(final String batchJobId) { * * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobFailuresResponse listFailures( + public BatchJobsListFailuresPage listFailures( final String batchJobId, final BatchJobsListFailuresOptions options) { return listFailures(batchJobId, options, RequestOptions.none()); } @@ -183,9 +220,9 @@ public BatchJobFailuresResponse listFailures( * * @param batchJobId the {@code batch_job_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobFailuresResponse listFailures( + public BatchJobsListFailuresPage listFailures( final String batchJobId, final RequestOptions requestOptions) { return listFailures(batchJobId, BatchJobsListFailuresOptions.none(), requestOptions); } @@ -198,13 +235,17 @@ public BatchJobFailuresResponse listFailures( * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public BatchJobFailuresResponse listFailures( + public BatchJobsListFailuresPage listFailures( final String batchJobId, final BatchJobsListFailuresOptions options, final RequestOptions requestOptions) { - return exchangeListFailures(batchJobId, options, requestOptions).send(); + return pageOfListFailures( + exchangeListFailures(batchJobId, options, requestOptions).send(), + batchJobId, + options, + requestOptions); } MeteroidHttpClient.Exchange exchangeListFailures( @@ -236,6 +277,47 @@ MeteroidHttpClient.Exchange exchangeListFailures( .returning(BatchJobFailuresResponse.class); } + private BatchJobsListFailuresPage pageOfListFailures( + BatchJobFailuresResponse response, + final String batchJobId, + final BatchJobsListFailuresOptions options, + final RequestOptions requestOptions) { + List items = itemsOfListFailures(response); + Integer next = nextOfListFailures(response, items, options.offset().orElse(0)); + return new BatchJobsListFailuresPage( + response, + items, + next == null + ? null + : () -> + listFailures( + batchJobId, + options.toBuilder().offset(next).build(), + requestOptions)); + } + + static List itemsOfListFailures( + BatchJobFailuresResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfListFailures( + BatchJobFailuresResponse response, + List items, + Integer current) { + if (items.isEmpty()) { + return null; + } + Integer next = current + items.size(); + long total = + Utils.optional(response.totalCount()).map(Number::longValue).orElse(Long.MAX_VALUE); + if (next >= total) { + return null; + } + return next; + } + /** The operations, returning the status and headers along with the body. */ public final class WithRawResponse { private WithRawResponse() {} @@ -243,9 +325,9 @@ private WithRawResponse() {} /** * List batch jobs with optional filtering by type and status. * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(BatchJobsListOptions.none(), RequestOptions.none()); } @@ -253,9 +335,9 @@ public ApiResponse list() { * List batch jobs with optional filtering by type and status. * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final BatchJobsListOptions options) { + public ApiResponse list(final BatchJobsListOptions options) { return list(options, RequestOptions.none()); } @@ -263,9 +345,9 @@ public ApiResponse list(final BatchJobsListOptions options * List batch jobs with optional filtering by type and status. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(BatchJobsListOptions.none(), requestOptions); } @@ -274,11 +356,16 @@ public ApiResponse list(final RequestOptions requestOption * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final BatchJobsListOptions options, final RequestOptions requestOptions) { - return BatchJobs.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** @@ -313,9 +400,9 @@ public ApiResponse retrieve( *

Retrieve paginated failures for a batch job. * * @param batchJobId the {@code batch_job_id} path parameter - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listFailures(final String batchJobId) { + public ApiResponse listFailures(final String batchJobId) { return listFailures( batchJobId, BatchJobsListFailuresOptions.none(), RequestOptions.none()); } @@ -327,9 +414,9 @@ public ApiResponse listFailures(final String batchJobI * * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listFailures( + public ApiResponse listFailures( final String batchJobId, final BatchJobsListFailuresOptions options) { return listFailures(batchJobId, options, RequestOptions.none()); } @@ -341,9 +428,9 @@ public ApiResponse listFailures( * * @param batchJobId the {@code batch_job_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listFailures( + public ApiResponse listFailures( final String batchJobId, final RequestOptions requestOptions) { return listFailures(batchJobId, BatchJobsListFailuresOptions.none(), requestOptions); } @@ -356,15 +443,18 @@ public ApiResponse listFailures( * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listFailures( + public ApiResponse listFailures( final String batchJobId, final BatchJobsListFailuresOptions options, final RequestOptions requestOptions) { - return BatchJobs.this - .exchangeListFailures(batchJobId, options, requestOptions) - .sendRaw(); + ApiResponse response = + exchangeListFailures(batchJobId, options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfListFailures(response.body(), batchJobId, options, requestOptions)); } } } diff --git a/src/main/java/com/meteroid/api/BatchJobsAsync.java b/src/main/java/com/meteroid/api/BatchJobsAsync.java index 831708b..bdda26b 100644 --- a/src/main/java/com/meteroid/api/BatchJobsAsync.java +++ b/src/main/java/com/meteroid/api/BatchJobsAsync.java @@ -5,8 +5,11 @@ import com.meteroid.RequestOptions; import com.meteroid.models.BatchJobDetailResponse; import com.meteroid.models.BatchJobFailuresResponse; +import com.meteroid.models.BatchJobItemFailureResponse; import com.meteroid.models.BatchJobListResponse; +import com.meteroid.models.BatchJobResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -39,9 +42,9 @@ public WithRawResponse withRawResponse() { /** * List batch jobs with optional filtering by type and status. * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(BatchJobsListOptions.none(), RequestOptions.none()); } @@ -49,9 +52,9 @@ public CompletableFuture list() { * List batch jobs with optional filtering by type and status. * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final BatchJobsListOptions options) { + public CompletableFuture list(final BatchJobsListOptions options) { return list(options, RequestOptions.none()); } @@ -59,9 +62,9 @@ public CompletableFuture list(final BatchJobsListOptions o * List batch jobs with optional filtering by type and status. * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(BatchJobsListOptions.none(), requestOptions); } @@ -70,11 +73,27 @@ public CompletableFuture list(final RequestOptions request * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final BatchJobsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private BatchJobsListAsyncPage pageOfList( + BatchJobListResponse response, + final BatchJobsListOptions options, + final RequestOptions requestOptions) { + List items = BatchJobs.itemsOfList(response); + Integer next = BatchJobs.nextOfList(response, items, options.page().orElse(0)); + return new BatchJobsListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -109,9 +128,9 @@ public CompletableFuture retrieve( *

Retrieve paginated failures for a batch job. * * @param batchJobId the {@code batch_job_id} path parameter - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listFailures(final String batchJobId) { + public CompletableFuture listFailures(final String batchJobId) { return listFailures(batchJobId, BatchJobsListFailuresOptions.none(), RequestOptions.none()); } @@ -122,9 +141,9 @@ public CompletableFuture listFailures(final String bat * * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listFailures( + public CompletableFuture listFailures( final String batchJobId, final BatchJobsListFailuresOptions options) { return listFailures(batchJobId, options, RequestOptions.none()); } @@ -136,9 +155,9 @@ public CompletableFuture listFailures( * * @param batchJobId the {@code batch_job_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listFailures( + public CompletableFuture listFailures( final String batchJobId, final RequestOptions requestOptions) { return listFailures(batchJobId, BatchJobsListFailuresOptions.none(), requestOptions); } @@ -151,13 +170,36 @@ public CompletableFuture listFailures( * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listFailures( + public CompletableFuture listFailures( + final String batchJobId, + final BatchJobsListFailuresOptions options, + final RequestOptions requestOptions) { + return sync.exchangeListFailures(batchJobId, options, requestOptions) + .sendAsync() + .thenApply( + response -> + pageOfListFailures(response, batchJobId, options, requestOptions)); + } + + private BatchJobsListFailuresAsyncPage pageOfListFailures( + BatchJobFailuresResponse response, final String batchJobId, final BatchJobsListFailuresOptions options, final RequestOptions requestOptions) { - return sync.exchangeListFailures(batchJobId, options, requestOptions).sendAsync(); + List items = BatchJobs.itemsOfListFailures(response); + Integer next = BatchJobs.nextOfListFailures(response, items, options.offset().orElse(0)); + return new BatchJobsListFailuresAsyncPage( + response, + items, + next == null + ? null + : () -> + listFailures( + batchJobId, + options.toBuilder().offset(next).build(), + requestOptions)); } /** The operations, returning the status and headers along with the body. */ @@ -167,9 +209,9 @@ private WithRawResponse() {} /** * List batch jobs with optional filtering by type and status. * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(BatchJobsListOptions.none(), RequestOptions.none()); } @@ -177,9 +219,9 @@ public CompletableFuture> list() { * List batch jobs with optional filtering by type and status. * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final BatchJobsListOptions options) { return list(options, RequestOptions.none()); } @@ -188,9 +230,9 @@ public CompletableFuture> list( * List batch jobs with optional filtering by type and status. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(BatchJobsListOptions.none(), requestOptions); } @@ -200,11 +242,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final BatchJobsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** @@ -240,9 +289,9 @@ public CompletableFuture> retrieve( *

Retrieve paginated failures for a batch job. * * @param batchJobId the {@code batch_job_id} path parameter - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listFailures( + public CompletableFuture> listFailures( final String batchJobId) { return listFailures( batchJobId, BatchJobsListFailuresOptions.none(), RequestOptions.none()); @@ -255,9 +304,9 @@ public CompletableFuture> listFailures( * * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listFailures( + public CompletableFuture> listFailures( final String batchJobId, final BatchJobsListFailuresOptions options) { return listFailures(batchJobId, options, RequestOptions.none()); } @@ -269,9 +318,9 @@ public CompletableFuture> listFailures( * * @param batchJobId the {@code batch_job_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listFailures( + public CompletableFuture> listFailures( final String batchJobId, final RequestOptions requestOptions) { return listFailures(batchJobId, BatchJobsListFailuresOptions.none(), requestOptions); } @@ -284,13 +333,24 @@ public CompletableFuture> listFailures( * @param batchJobId the {@code batch_job_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listFailures( + public CompletableFuture> listFailures( final String batchJobId, final BatchJobsListFailuresOptions options, final RequestOptions requestOptions) { - return sync.exchangeListFailures(batchJobId, options, requestOptions).sendRawAsync(); + return sync.exchangeListFailures(batchJobId, options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfListFailures( + response.body(), + batchJobId, + options, + requestOptions))); } } } diff --git a/src/main/java/com/meteroid/api/BatchJobsListAsyncPage.java b/src/main/java/com/meteroid/api/BatchJobsListAsyncPage.java new file mode 100644 index 0000000..0f6cab9 --- /dev/null +++ b/src/main/java/com/meteroid/api/BatchJobsListAsyncPage.java @@ -0,0 +1,67 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.BatchJobListResponse; +import com.meteroid.models.BatchJobResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link BatchJobsAsync#list}: the {@link BatchJobResponse} items of one response, and + * the properties of its body, {@link BatchJobListResponse}. + */ +public final class BatchJobsListAsyncPage + extends AsyncPage { + private final BatchJobListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public BatchJobsListAsyncPage( + BatchJobListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public BatchJobListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "BatchJobsListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/BatchJobsListFailuresAsyncPage.java b/src/main/java/com/meteroid/api/BatchJobsListFailuresAsyncPage.java new file mode 100644 index 0000000..35d5fae --- /dev/null +++ b/src/main/java/com/meteroid/api/BatchJobsListFailuresAsyncPage.java @@ -0,0 +1,70 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.BatchJobFailuresResponse; +import com.meteroid.models.BatchJobItemFailureResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link BatchJobsAsync#listFailures}: the {@link BatchJobItemFailureResponse} items of + * one response, and the properties of its body, {@link BatchJobFailuresResponse}. + */ +public final class BatchJobsListFailuresAsyncPage + extends AsyncPage { + private final BatchJobFailuresResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public BatchJobsListFailuresAsyncPage( + BatchJobFailuresResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public BatchJobFailuresResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code total_count} property. + * + * @return the value, never null + */ + public Long totalCount() { + return body.totalCount(); + } + + @Override + public String toString() { + return "BatchJobsListFailuresAsyncPage{body=" + + body + + ", hasNextPage=" + + hasNextPage() + + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/BatchJobsListFailuresPage.java b/src/main/java/com/meteroid/api/BatchJobsListFailuresPage.java new file mode 100644 index 0000000..d553d84 --- /dev/null +++ b/src/main/java/com/meteroid/api/BatchJobsListFailuresPage.java @@ -0,0 +1,68 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.BatchJobFailuresResponse; +import com.meteroid.models.BatchJobItemFailureResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link BatchJobs#listFailures}: the {@link BatchJobItemFailureResponse} items of one + * response, and the properties of its body, {@link BatchJobFailuresResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class BatchJobsListFailuresPage + extends Page { + private final BatchJobFailuresResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public BatchJobsListFailuresPage( + BatchJobFailuresResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public BatchJobFailuresResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code total_count} property. + * + * @return the value, never null + */ + public Long totalCount() { + return body.totalCount(); + } + + @Override + public String toString() { + return "BatchJobsListFailuresPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/BatchJobsListPage.java b/src/main/java/com/meteroid/api/BatchJobsListPage.java new file mode 100644 index 0000000..edad055 --- /dev/null +++ b/src/main/java/com/meteroid/api/BatchJobsListPage.java @@ -0,0 +1,68 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.BatchJobListResponse; +import com.meteroid.models.BatchJobResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link BatchJobs#list}: the {@link BatchJobResponse} items of one response, and the + * properties of its body, {@link BatchJobListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class BatchJobsListPage extends Page { + private final BatchJobListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public BatchJobsListPage( + BatchJobListResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public BatchJobListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "BatchJobsListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Coupons.java b/src/main/java/com/meteroid/api/Coupons.java index 23e9741..73440ec 100644 --- a/src/main/java/com/meteroid/api/Coupons.java +++ b/src/main/java/com/meteroid/api/Coupons.java @@ -13,6 +13,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -45,9 +46,9 @@ public WithRawResponse withRawResponse() { /** * List coupons * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CouponListResponse list() { + public CouponsListPage list() { return list(CouponsListOptions.none(), RequestOptions.none()); } @@ -55,9 +56,9 @@ public CouponListResponse list() { * List coupons * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CouponListResponse list(final CouponsListOptions options) { + public CouponsListPage list(final CouponsListOptions options) { return list(options, RequestOptions.none()); } @@ -65,9 +66,9 @@ public CouponListResponse list(final CouponsListOptions options) { * List coupons * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CouponListResponse list(final RequestOptions requestOptions) { + public CouponsListPage list(final RequestOptions requestOptions) { return list(CouponsListOptions.none(), requestOptions); } @@ -76,11 +77,11 @@ public CouponListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CouponListResponse list( + public CouponsListPage list( final CouponsListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -113,6 +114,40 @@ MeteroidHttpClient.Exchange exchangeList( .returning(CouponListResponse.class); } + private CouponsListPage pageOfList( + CouponListResponse response, + final CouponsListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new CouponsListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(CouponListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList(CouponListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create a coupon * @@ -368,9 +403,9 @@ private WithRawResponse() {} /** * List coupons * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(CouponsListOptions.none(), RequestOptions.none()); } @@ -378,9 +413,9 @@ public ApiResponse list() { * List coupons * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final CouponsListOptions options) { + public ApiResponse list(final CouponsListOptions options) { return list(options, RequestOptions.none()); } @@ -388,9 +423,9 @@ public ApiResponse list(final CouponsListOptions options) { * List coupons * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(CouponsListOptions.none(), requestOptions); } @@ -399,11 +434,16 @@ public ApiResponse list(final RequestOptions requestOptions) * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final CouponsListOptions options, final RequestOptions requestOptions) { - return Coupons.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/CouponsAsync.java b/src/main/java/com/meteroid/api/CouponsAsync.java index 56e5fc5..fac2f8a 100644 --- a/src/main/java/com/meteroid/api/CouponsAsync.java +++ b/src/main/java/com/meteroid/api/CouponsAsync.java @@ -8,6 +8,7 @@ import com.meteroid.models.CreateCouponRequest; import com.meteroid.models.UpdateCouponRequest; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -40,9 +41,9 @@ public WithRawResponse withRawResponse() { /** * List coupons * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(CouponsListOptions.none(), RequestOptions.none()); } @@ -50,9 +51,9 @@ public CompletableFuture list() { * List coupons * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final CouponsListOptions options) { + public CompletableFuture list(final CouponsListOptions options) { return list(options, RequestOptions.none()); } @@ -60,9 +61,9 @@ public CompletableFuture list(final CouponsListOptions optio * List coupons * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(CouponsListOptions.none(), requestOptions); } @@ -71,11 +72,27 @@ public CompletableFuture list(final RequestOptions requestOp * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final CouponsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private CouponsListAsyncPage pageOfList( + CouponListResponse response, + final CouponsListOptions options, + final RequestOptions requestOptions) { + List items = Coupons.itemsOfList(response); + Integer next = Coupons.nextOfList(response, items, options.page().orElse(0)); + return new CouponsListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -244,9 +261,9 @@ private WithRawResponse() {} /** * List coupons * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(CouponsListOptions.none(), RequestOptions.none()); } @@ -254,9 +271,9 @@ public CompletableFuture> list() { * List coupons * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final CouponsListOptions options) { return list(options, RequestOptions.none()); } @@ -265,9 +282,9 @@ public CompletableFuture> list( * List coupons * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(CouponsListOptions.none(), requestOptions); } @@ -277,11 +294,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final CouponsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/CouponsListAsyncPage.java b/src/main/java/com/meteroid/api/CouponsListAsyncPage.java new file mode 100644 index 0000000..ba38f68 --- /dev/null +++ b/src/main/java/com/meteroid/api/CouponsListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.Coupon; +import com.meteroid.models.CouponListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link CouponsAsync#list}: the {@link Coupon} items of one response, and the properties + * of its body, {@link CouponListResponse}. + */ +public final class CouponsListAsyncPage extends AsyncPage { + private final CouponListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CouponsListAsyncPage( + CouponListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CouponListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CouponsListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/CouponsListPage.java b/src/main/java/com/meteroid/api/CouponsListPage.java new file mode 100644 index 0000000..7c25c49 --- /dev/null +++ b/src/main/java/com/meteroid/api/CouponsListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.Coupon; +import com.meteroid.models.CouponListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Coupons#list}: the {@link Coupon} items of one response, and the properties of + * its body, {@link CouponListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class CouponsListPage extends Page { + private final CouponListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CouponsListPage( + CouponListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CouponListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CouponsListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/CreditNotes.java b/src/main/java/com/meteroid/api/CreditNotes.java index cd02767..7abfce3 100644 --- a/src/main/java/com/meteroid/api/CreditNotes.java +++ b/src/main/java/com/meteroid/api/CreditNotes.java @@ -12,6 +12,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -46,9 +47,9 @@ public WithRawResponse withRawResponse() { * *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CreditNoteListResponse list() { + public CreditNotesListPage list() { return list(CreditNotesListOptions.none(), RequestOptions.none()); } @@ -58,9 +59,9 @@ public CreditNoteListResponse list() { *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CreditNoteListResponse list(final CreditNotesListOptions options) { + public CreditNotesListPage list(final CreditNotesListOptions options) { return list(options, RequestOptions.none()); } @@ -70,9 +71,9 @@ public CreditNoteListResponse list(final CreditNotesListOptions options) { *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CreditNoteListResponse list(final RequestOptions requestOptions) { + public CreditNotesListPage list(final RequestOptions requestOptions) { return list(CreditNotesListOptions.none(), requestOptions); } @@ -83,11 +84,11 @@ public CreditNoteListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CreditNoteListResponse list( + public CreditNotesListPage list( final CreditNotesListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -128,6 +129,41 @@ MeteroidHttpClient.Exchange exchangeList( .returning(CreditNoteListResponse.class); } + private CreditNotesListPage pageOfList( + CreditNoteListResponse response, + final CreditNotesListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new CreditNotesListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(CreditNoteListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList( + CreditNoteListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Get credit note * @@ -320,9 +356,9 @@ private WithRawResponse() {} * *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(CreditNotesListOptions.none(), RequestOptions.none()); } @@ -332,9 +368,9 @@ public ApiResponse list() { *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final CreditNotesListOptions options) { + public ApiResponse list(final CreditNotesListOptions options) { return list(options, RequestOptions.none()); } @@ -344,9 +380,9 @@ public ApiResponse list(final CreditNotesListOptions opt *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(CreditNotesListOptions.none(), requestOptions); } @@ -357,11 +393,16 @@ public ApiResponse list(final RequestOptions requestOpti * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final CreditNotesListOptions options, final RequestOptions requestOptions) { - return CreditNotes.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/CreditNotesAsync.java b/src/main/java/com/meteroid/api/CreditNotesAsync.java index 933bd8c..4746afb 100644 --- a/src/main/java/com/meteroid/api/CreditNotesAsync.java +++ b/src/main/java/com/meteroid/api/CreditNotesAsync.java @@ -7,6 +7,7 @@ import com.meteroid.models.CreditNoteCustomPropertiesRequest; import com.meteroid.models.CreditNoteListResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -41,9 +42,9 @@ public WithRawResponse withRawResponse() { * *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(CreditNotesListOptions.none(), RequestOptions.none()); } @@ -53,9 +54,9 @@ public CompletableFuture list() { *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final CreditNotesListOptions options) { + public CompletableFuture list(final CreditNotesListOptions options) { return list(options, RequestOptions.none()); } @@ -65,9 +66,9 @@ public CompletableFuture list(final CreditNotesListOptio *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(CreditNotesListOptions.none(), requestOptions); } @@ -78,11 +79,27 @@ public CompletableFuture list(final RequestOptions reque * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final CreditNotesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private CreditNotesListAsyncPage pageOfList( + CreditNoteListResponse response, + final CreditNotesListOptions options, + final RequestOptions requestOptions) { + List items = CreditNotes.itemsOfList(response); + Integer next = CreditNotes.nextOfList(response, items, options.page().orElse(0)); + return new CreditNotesListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -211,9 +228,9 @@ private WithRawResponse() {} * *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(CreditNotesListOptions.none(), RequestOptions.none()); } @@ -223,9 +240,9 @@ public CompletableFuture> list() { *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final CreditNotesListOptions options) { return list(options, RequestOptions.none()); } @@ -236,9 +253,9 @@ public CompletableFuture> list( *

List a tenant's credit notes, optionally filtered by customer, invoice or status. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(CreditNotesListOptions.none(), requestOptions); } @@ -250,11 +267,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final CreditNotesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/CreditNotesListAsyncPage.java b/src/main/java/com/meteroid/api/CreditNotesListAsyncPage.java new file mode 100644 index 0000000..ad7f5b1 --- /dev/null +++ b/src/main/java/com/meteroid/api/CreditNotesListAsyncPage.java @@ -0,0 +1,67 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.CreditNote; +import com.meteroid.models.CreditNoteListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link CreditNotesAsync#list}: the {@link CreditNote} items of one response, and the + * properties of its body, {@link CreditNoteListResponse}. + */ +public final class CreditNotesListAsyncPage + extends AsyncPage { + private final CreditNoteListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CreditNotesListAsyncPage( + CreditNoteListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CreditNoteListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CreditNotesListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/CreditNotesListPage.java b/src/main/java/com/meteroid/api/CreditNotesListPage.java new file mode 100644 index 0000000..5afa9c5 --- /dev/null +++ b/src/main/java/com/meteroid/api/CreditNotesListPage.java @@ -0,0 +1,68 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.CreditNote; +import com.meteroid.models.CreditNoteListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link CreditNotes#list}: the {@link CreditNote} items of one response, and the + * properties of its body, {@link CreditNoteListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class CreditNotesListPage extends Page { + private final CreditNoteListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CreditNotesListPage( + CreditNoteListResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CreditNoteListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CreditNotesListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/CustomProperties.java b/src/main/java/com/meteroid/api/CustomProperties.java index 354fb16..78506f9 100644 --- a/src/main/java/com/meteroid/api/CustomProperties.java +++ b/src/main/java/com/meteroid/api/CustomProperties.java @@ -13,6 +13,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -45,9 +46,9 @@ public WithRawResponse withRawResponse() { /** * List custom property definitions * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions() { + public CustomPropertiesListCustomPropertyDefinitionsPage listCustomPropertyDefinitions() { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), RequestOptions.none()); } @@ -56,9 +57,9 @@ public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions() { * List custom property definitions * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions( + public CustomPropertiesListCustomPropertyDefinitionsPage listCustomPropertyDefinitions( final CustomPropertiesListCustomPropertyDefinitionsOptions options) { return listCustomPropertyDefinitions(options, RequestOptions.none()); } @@ -67,9 +68,9 @@ public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions( * List custom property definitions * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions( + public CustomPropertiesListCustomPropertyDefinitionsPage listCustomPropertyDefinitions( final RequestOptions requestOptions) { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), requestOptions); @@ -80,12 +81,15 @@ public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions( + public CustomPropertiesListCustomPropertyDefinitionsPage listCustomPropertyDefinitions( final CustomPropertiesListCustomPropertyDefinitionsOptions options, final RequestOptions requestOptions) { - return exchangeListCustomPropertyDefinitions(options, requestOptions).send(); + return pageOfListCustomPropertyDefinitions( + exchangeListCustomPropertyDefinitions(options, requestOptions).send(), + options, + requestOptions); } MeteroidHttpClient.Exchange @@ -117,6 +121,47 @@ public CustomPropertyDefinitionListResponse listCustomPropertyDefinitions( .returning(CustomPropertyDefinitionListResponse.class); } + private CustomPropertiesListCustomPropertyDefinitionsPage pageOfListCustomPropertyDefinitions( + CustomPropertyDefinitionListResponse response, + final CustomPropertiesListCustomPropertyDefinitionsOptions options, + final RequestOptions requestOptions) { + List items = itemsOfListCustomPropertyDefinitions(response); + Integer next = + nextOfListCustomPropertyDefinitions(response, items, options.page().orElse(0)); + return new CustomPropertiesListCustomPropertyDefinitionsPage( + response, + items, + next == null + ? null + : () -> + listCustomPropertyDefinitions( + options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfListCustomPropertyDefinitions( + CustomPropertyDefinitionListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfListCustomPropertyDefinitions( + CustomPropertyDefinitionListResponse response, + List items, + Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create a custom property definition * @@ -293,9 +338,10 @@ private WithRawResponse() {} /** * List custom property definitions * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listCustomPropertyDefinitions() { + public ApiResponse + listCustomPropertyDefinitions() { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), RequestOptions.none()); @@ -305,10 +351,11 @@ public ApiResponse listCustomPropertyDefin * List custom property definitions * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listCustomPropertyDefinitions( - final CustomPropertiesListCustomPropertyDefinitionsOptions options) { + public ApiResponse + listCustomPropertyDefinitions( + final CustomPropertiesListCustomPropertyDefinitionsOptions options) { return listCustomPropertyDefinitions(options, RequestOptions.none()); } @@ -316,10 +363,10 @@ public ApiResponse listCustomPropertyDefin * List custom property definitions * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listCustomPropertyDefinitions( - final RequestOptions requestOptions) { + public ApiResponse + listCustomPropertyDefinitions(final RequestOptions requestOptions) { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), requestOptions); } @@ -329,14 +376,18 @@ public ApiResponse listCustomPropertyDefin * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listCustomPropertyDefinitions( - final CustomPropertiesListCustomPropertyDefinitionsOptions options, - final RequestOptions requestOptions) { - return CustomProperties.this - .exchangeListCustomPropertyDefinitions(options, requestOptions) - .sendRaw(); + public ApiResponse + listCustomPropertyDefinitions( + final CustomPropertiesListCustomPropertyDefinitionsOptions options, + final RequestOptions requestOptions) { + ApiResponse response = + exchangeListCustomPropertyDefinitions(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfListCustomPropertyDefinitions(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/CustomPropertiesAsync.java b/src/main/java/com/meteroid/api/CustomPropertiesAsync.java index c2e3d73..f8fdac4 100644 --- a/src/main/java/com/meteroid/api/CustomPropertiesAsync.java +++ b/src/main/java/com/meteroid/api/CustomPropertiesAsync.java @@ -8,6 +8,7 @@ import com.meteroid.models.CustomPropertyDefinitionListResponse; import com.meteroid.models.CustomPropertyDefinitionUpdateRequest; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -40,9 +41,10 @@ public WithRawResponse withRawResponse() { /** * List custom property definitions * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listCustomPropertyDefinitions() { + public CompletableFuture + listCustomPropertyDefinitions() { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), RequestOptions.none()); } @@ -51,10 +53,11 @@ public CompletableFuture listCustomPropert * List custom property definitions * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listCustomPropertyDefinitions( - final CustomPropertiesListCustomPropertyDefinitionsOptions options) { + public CompletableFuture + listCustomPropertyDefinitions( + final CustomPropertiesListCustomPropertyDefinitionsOptions options) { return listCustomPropertyDefinitions(options, RequestOptions.none()); } @@ -62,10 +65,10 @@ public CompletableFuture listCustomPropert * List custom property definitions * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listCustomPropertyDefinitions( - final RequestOptions requestOptions) { + public CompletableFuture + listCustomPropertyDefinitions(final RequestOptions requestOptions) { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), requestOptions); } @@ -75,12 +78,38 @@ public CompletableFuture listCustomPropert * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listCustomPropertyDefinitions( - final CustomPropertiesListCustomPropertyDefinitionsOptions options, - final RequestOptions requestOptions) { - return sync.exchangeListCustomPropertyDefinitions(options, requestOptions).sendAsync(); + public CompletableFuture + listCustomPropertyDefinitions( + final CustomPropertiesListCustomPropertyDefinitionsOptions options, + final RequestOptions requestOptions) { + return sync.exchangeListCustomPropertyDefinitions(options, requestOptions) + .sendAsync() + .thenApply( + response -> + pageOfListCustomPropertyDefinitions( + response, options, requestOptions)); + } + + private CustomPropertiesListCustomPropertyDefinitionsAsyncPage + pageOfListCustomPropertyDefinitions( + CustomPropertyDefinitionListResponse response, + final CustomPropertiesListCustomPropertyDefinitionsOptions options, + final RequestOptions requestOptions) { + List items = + CustomProperties.itemsOfListCustomPropertyDefinitions(response); + Integer next = + CustomProperties.nextOfListCustomPropertyDefinitions( + response, items, options.page().orElse(0)); + return new CustomPropertiesListCustomPropertyDefinitionsAsyncPage( + response, + items, + next == null + ? null + : () -> + listCustomPropertyDefinitions( + options.toBuilder().page(next).build(), requestOptions)); } /** @@ -199,9 +228,10 @@ private WithRawResponse() {} /** * List custom property definitions * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> + public CompletableFuture< + ApiResponse> listCustomPropertyDefinitions() { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), @@ -212,9 +242,10 @@ private WithRawResponse() {} * List custom property definitions * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> + public CompletableFuture< + ApiResponse> listCustomPropertyDefinitions( final CustomPropertiesListCustomPropertyDefinitionsOptions options) { return listCustomPropertyDefinitions(options, RequestOptions.none()); @@ -224,9 +255,10 @@ private WithRawResponse() {} * List custom property definitions * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> + public CompletableFuture< + ApiResponse> listCustomPropertyDefinitions(final RequestOptions requestOptions) { return listCustomPropertyDefinitions( CustomPropertiesListCustomPropertyDefinitionsOptions.none(), requestOptions); @@ -237,14 +269,22 @@ private WithRawResponse() {} * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> + public CompletableFuture< + ApiResponse> listCustomPropertyDefinitions( final CustomPropertiesListCustomPropertyDefinitionsOptions options, final RequestOptions requestOptions) { return sync.exchangeListCustomPropertyDefinitions(options, requestOptions) - .sendRawAsync(); + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfListCustomPropertyDefinitions( + response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsAsyncPage.java b/src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsAsyncPage.java new file mode 100644 index 0000000..16b13e4 --- /dev/null +++ b/src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsAsyncPage.java @@ -0,0 +1,74 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.CustomPropertyDefinition; +import com.meteroid.models.CustomPropertyDefinitionListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link CustomPropertiesAsync#listCustomPropertyDefinitions}: the {@link + * CustomPropertyDefinition} items of one response, and the properties of its body, {@link + * CustomPropertyDefinitionListResponse}. + */ +public final class CustomPropertiesListCustomPropertyDefinitionsAsyncPage + extends AsyncPage< + CustomPropertiesListCustomPropertyDefinitionsAsyncPage, CustomPropertyDefinition> { + private final CustomPropertyDefinitionListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CustomPropertiesListCustomPropertyDefinitionsAsyncPage( + CustomPropertyDefinitionListResponse body, + List items, + Supplier> + next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CustomPropertyDefinitionListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CustomPropertiesListCustomPropertyDefinitionsAsyncPage{body=" + + body + + ", hasNextPage=" + + hasNextPage() + + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsPage.java b/src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsPage.java new file mode 100644 index 0000000..3291b28 --- /dev/null +++ b/src/main/java/com/meteroid/api/CustomPropertiesListCustomPropertyDefinitionsPage.java @@ -0,0 +1,74 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.CustomPropertyDefinition; +import com.meteroid.models.CustomPropertyDefinitionListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link CustomProperties#listCustomPropertyDefinitions}: the {@link + * CustomPropertyDefinition} items of one response, and the properties of its body, {@link + * CustomPropertyDefinitionListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class CustomPropertiesListCustomPropertyDefinitionsPage + extends Page { + private final CustomPropertyDefinitionListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CustomPropertiesListCustomPropertyDefinitionsPage( + CustomPropertyDefinitionListResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CustomPropertyDefinitionListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CustomPropertiesListCustomPropertyDefinitionsPage{body=" + + body + + ", hasNextPage=" + + hasNextPage() + + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Customers.java b/src/main/java/com/meteroid/api/Customers.java index 31d9c75..283696c 100644 --- a/src/main/java/com/meteroid/api/Customers.java +++ b/src/main/java/com/meteroid/api/Customers.java @@ -16,6 +16,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -48,9 +49,9 @@ public WithRawResponse withRawResponse() { /** * List customers with optional pagination and search filtering. * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomerListResponse list() { + public CustomersListPage list() { return list(CustomersListOptions.none(), RequestOptions.none()); } @@ -58,9 +59,9 @@ public CustomerListResponse list() { * List customers with optional pagination and search filtering. * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomerListResponse list(final CustomersListOptions options) { + public CustomersListPage list(final CustomersListOptions options) { return list(options, RequestOptions.none()); } @@ -68,9 +69,9 @@ public CustomerListResponse list(final CustomersListOptions options) { * List customers with optional pagination and search filtering. * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomerListResponse list(final RequestOptions requestOptions) { + public CustomersListPage list(final RequestOptions requestOptions) { return list(CustomersListOptions.none(), requestOptions); } @@ -79,11 +80,11 @@ public CustomerListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public CustomerListResponse list( + public CustomersListPage list( final CustomersListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -116,6 +117,41 @@ MeteroidHttpClient.Exchange exchangeList( .returning(CustomerListResponse.class); } + private CustomersListPage pageOfList( + CustomerListResponse response, + final CustomersListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new CustomersListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(CustomerListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList( + CustomerListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create customer * @@ -478,9 +514,9 @@ private WithRawResponse() {} /** * List customers with optional pagination and search filtering. * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(CustomersListOptions.none(), RequestOptions.none()); } @@ -488,9 +524,9 @@ public ApiResponse list() { * List customers with optional pagination and search filtering. * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final CustomersListOptions options) { + public ApiResponse list(final CustomersListOptions options) { return list(options, RequestOptions.none()); } @@ -498,9 +534,9 @@ public ApiResponse list(final CustomersListOptions options * List customers with optional pagination and search filtering. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(CustomersListOptions.none(), requestOptions); } @@ -509,11 +545,16 @@ public ApiResponse list(final RequestOptions requestOption * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final CustomersListOptions options, final RequestOptions requestOptions) { - return Customers.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/CustomersAsync.java b/src/main/java/com/meteroid/api/CustomersAsync.java index 14022ac..de12a92 100644 --- a/src/main/java/com/meteroid/api/CustomersAsync.java +++ b/src/main/java/com/meteroid/api/CustomersAsync.java @@ -12,6 +12,7 @@ import com.meteroid.models.CustomerUpdateRequest; import com.meteroid.models.EffectiveEntitlementListResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -44,9 +45,9 @@ public WithRawResponse withRawResponse() { /** * List customers with optional pagination and search filtering. * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(CustomersListOptions.none(), RequestOptions.none()); } @@ -54,9 +55,9 @@ public CompletableFuture list() { * List customers with optional pagination and search filtering. * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final CustomersListOptions options) { + public CompletableFuture list(final CustomersListOptions options) { return list(options, RequestOptions.none()); } @@ -64,9 +65,9 @@ public CompletableFuture list(final CustomersListOptions o * List customers with optional pagination and search filtering. * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(CustomersListOptions.none(), requestOptions); } @@ -75,11 +76,27 @@ public CompletableFuture list(final RequestOptions request * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final CustomersListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private CustomersListAsyncPage pageOfList( + CustomerListResponse response, + final CustomersListOptions options, + final RequestOptions requestOptions) { + List items = Customers.itemsOfList(response); + Integer next = Customers.nextOfList(response, items, options.page().orElse(0)); + return new CustomersListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -303,9 +320,9 @@ private WithRawResponse() {} /** * List customers with optional pagination and search filtering. * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(CustomersListOptions.none(), RequestOptions.none()); } @@ -313,9 +330,9 @@ public CompletableFuture> list() { * List customers with optional pagination and search filtering. * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final CustomersListOptions options) { return list(options, RequestOptions.none()); } @@ -324,9 +341,9 @@ public CompletableFuture> list( * List customers with optional pagination and search filtering. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(CustomersListOptions.none(), requestOptions); } @@ -336,11 +353,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final CustomersListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/CustomersListAsyncPage.java b/src/main/java/com/meteroid/api/CustomersListAsyncPage.java new file mode 100644 index 0000000..b0f4f13 --- /dev/null +++ b/src/main/java/com/meteroid/api/CustomersListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.Customer; +import com.meteroid.models.CustomerListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link CustomersAsync#list}: the {@link Customer} items of one response, and the + * properties of its body, {@link CustomerListResponse}. + */ +public final class CustomersListAsyncPage extends AsyncPage { + private final CustomerListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CustomersListAsyncPage( + CustomerListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CustomerListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CustomersListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/CustomersListPage.java b/src/main/java/com/meteroid/api/CustomersListPage.java new file mode 100644 index 0000000..4e9c3c0 --- /dev/null +++ b/src/main/java/com/meteroid/api/CustomersListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.Customer; +import com.meteroid.models.CustomerListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Customers#list}: the {@link Customer} items of one response, and the properties + * of its body, {@link CustomerListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class CustomersListPage extends Page { + private final CustomerListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public CustomersListPage( + CustomerListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public CustomerListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "CustomersListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Features.java b/src/main/java/com/meteroid/api/Features.java index e00d28b..8b0ed75 100644 --- a/src/main/java/com/meteroid/api/Features.java +++ b/src/main/java/com/meteroid/api/Features.java @@ -46,9 +46,9 @@ public WithRawResponse withRawResponse() { /** * List features * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public FeatureListResponse list() { + public FeaturesListPage list() { return list(FeaturesListOptions.none(), RequestOptions.none()); } @@ -56,9 +56,9 @@ public FeatureListResponse list() { * List features * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public FeatureListResponse list(final FeaturesListOptions options) { + public FeaturesListPage list(final FeaturesListOptions options) { return list(options, RequestOptions.none()); } @@ -66,9 +66,9 @@ public FeatureListResponse list(final FeaturesListOptions options) { * List features * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public FeatureListResponse list(final RequestOptions requestOptions) { + public FeaturesListPage list(final RequestOptions requestOptions) { return list(FeaturesListOptions.none(), requestOptions); } @@ -77,11 +77,11 @@ public FeatureListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public FeatureListResponse list( + public FeaturesListPage list( final FeaturesListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -114,6 +114,40 @@ MeteroidHttpClient.Exchange exchangeList( .returning(FeatureListResponse.class); } + private FeaturesListPage pageOfList( + FeatureListResponse response, + final FeaturesListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new FeaturesListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(FeatureListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList(FeatureListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create a feature * @@ -309,9 +343,9 @@ private WithRawResponse() {} /** * List features * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(FeaturesListOptions.none(), RequestOptions.none()); } @@ -319,9 +353,9 @@ public ApiResponse list() { * List features * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final FeaturesListOptions options) { + public ApiResponse list(final FeaturesListOptions options) { return list(options, RequestOptions.none()); } @@ -329,9 +363,9 @@ public ApiResponse list(final FeaturesListOptions options) * List features * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(FeaturesListOptions.none(), requestOptions); } @@ -340,11 +374,16 @@ public ApiResponse list(final RequestOptions requestOptions * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final FeaturesListOptions options, final RequestOptions requestOptions) { - return Features.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/FeaturesAsync.java b/src/main/java/com/meteroid/api/FeaturesAsync.java index 1ed5ab2..892a66d 100644 --- a/src/main/java/com/meteroid/api/FeaturesAsync.java +++ b/src/main/java/com/meteroid/api/FeaturesAsync.java @@ -8,6 +8,7 @@ import com.meteroid.models.FeatureListResponse; import com.meteroid.models.UpdateFeatureRequest; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -40,9 +41,9 @@ public WithRawResponse withRawResponse() { /** * List features * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(FeaturesListOptions.none(), RequestOptions.none()); } @@ -50,9 +51,9 @@ public CompletableFuture list() { * List features * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final FeaturesListOptions options) { + public CompletableFuture list(final FeaturesListOptions options) { return list(options, RequestOptions.none()); } @@ -60,9 +61,9 @@ public CompletableFuture list(final FeaturesListOptions opt * List features * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(FeaturesListOptions.none(), requestOptions); } @@ -71,11 +72,27 @@ public CompletableFuture list(final RequestOptions requestO * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final FeaturesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private FeaturesListAsyncPage pageOfList( + FeatureListResponse response, + final FeaturesListOptions options, + final RequestOptions requestOptions) { + List items = Features.itemsOfList(response); + Integer next = Features.nextOfList(response, items, options.page().orElse(0)); + return new FeaturesListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -208,9 +225,9 @@ private WithRawResponse() {} /** * List features * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(FeaturesListOptions.none(), RequestOptions.none()); } @@ -218,9 +235,9 @@ public CompletableFuture> list() { * List features * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final FeaturesListOptions options) { return list(options, RequestOptions.none()); } @@ -229,9 +246,9 @@ public CompletableFuture> list( * List features * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(FeaturesListOptions.none(), requestOptions); } @@ -241,11 +258,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final FeaturesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/FeaturesListAsyncPage.java b/src/main/java/com/meteroid/api/FeaturesListAsyncPage.java new file mode 100644 index 0000000..c6d3747 --- /dev/null +++ b/src/main/java/com/meteroid/api/FeaturesListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.Feature; +import com.meteroid.models.FeatureListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link FeaturesAsync#list}: the {@link Feature} items of one response, and the + * properties of its body, {@link FeatureListResponse}. + */ +public final class FeaturesListAsyncPage extends AsyncPage { + private final FeatureListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public FeaturesListAsyncPage( + FeatureListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public FeatureListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "FeaturesListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/FeaturesListPage.java b/src/main/java/com/meteroid/api/FeaturesListPage.java new file mode 100644 index 0000000..394c9cf --- /dev/null +++ b/src/main/java/com/meteroid/api/FeaturesListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.Feature; +import com.meteroid.models.FeatureListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Features#list}: the {@link Feature} items of one response, and the properties of + * its body, {@link FeatureListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class FeaturesListPage extends Page { + private final FeatureListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public FeaturesListPage( + FeatureListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public FeatureListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "FeaturesListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Invoices.java b/src/main/java/com/meteroid/api/Invoices.java index 10eb651..a5ab26a 100644 --- a/src/main/java/com/meteroid/api/Invoices.java +++ b/src/main/java/com/meteroid/api/Invoices.java @@ -46,9 +46,9 @@ public WithRawResponse withRawResponse() { /** * List invoices with optional filtering by customer, subscription, or status. * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public InvoiceListResponse list() { + public InvoicesListPage list() { return list(InvoicesListOptions.none(), RequestOptions.none()); } @@ -56,9 +56,9 @@ public InvoiceListResponse list() { * List invoices with optional filtering by customer, subscription, or status. * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public InvoiceListResponse list(final InvoicesListOptions options) { + public InvoicesListPage list(final InvoicesListOptions options) { return list(options, RequestOptions.none()); } @@ -66,9 +66,9 @@ public InvoiceListResponse list(final InvoicesListOptions options) { * List invoices with optional filtering by customer, subscription, or status. * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public InvoiceListResponse list(final RequestOptions requestOptions) { + public InvoicesListPage list(final RequestOptions requestOptions) { return list(InvoicesListOptions.none(), requestOptions); } @@ -77,11 +77,11 @@ public InvoiceListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public InvoiceListResponse list( + public InvoicesListPage list( final InvoicesListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -122,6 +122,40 @@ MeteroidHttpClient.Exchange exchangeList( .returning(InvoiceListResponse.class); } + private InvoicesListPage pageOfList( + InvoiceListResponse response, + final InvoicesListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new InvoicesListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(InvoiceListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList(InvoiceListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Get invoice * @@ -368,9 +402,9 @@ private WithRawResponse() {} /** * List invoices with optional filtering by customer, subscription, or status. * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(InvoicesListOptions.none(), RequestOptions.none()); } @@ -378,9 +412,9 @@ public ApiResponse list() { * List invoices with optional filtering by customer, subscription, or status. * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final InvoicesListOptions options) { + public ApiResponse list(final InvoicesListOptions options) { return list(options, RequestOptions.none()); } @@ -388,9 +422,9 @@ public ApiResponse list(final InvoicesListOptions options) * List invoices with optional filtering by customer, subscription, or status. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(InvoicesListOptions.none(), requestOptions); } @@ -399,11 +433,16 @@ public ApiResponse list(final RequestOptions requestOptions * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final InvoicesListOptions options, final RequestOptions requestOptions) { - return Invoices.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/InvoicesAsync.java b/src/main/java/com/meteroid/api/InvoicesAsync.java index 763300b..4dfcbaa 100644 --- a/src/main/java/com/meteroid/api/InvoicesAsync.java +++ b/src/main/java/com/meteroid/api/InvoicesAsync.java @@ -7,6 +7,7 @@ import com.meteroid.models.InvoiceCustomPropertiesRequest; import com.meteroid.models.InvoiceListResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -39,9 +40,9 @@ public WithRawResponse withRawResponse() { /** * List invoices with optional filtering by customer, subscription, or status. * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(InvoicesListOptions.none(), RequestOptions.none()); } @@ -49,9 +50,9 @@ public CompletableFuture list() { * List invoices with optional filtering by customer, subscription, or status. * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final InvoicesListOptions options) { + public CompletableFuture list(final InvoicesListOptions options) { return list(options, RequestOptions.none()); } @@ -59,9 +60,9 @@ public CompletableFuture list(final InvoicesListOptions opt * List invoices with optional filtering by customer, subscription, or status. * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(InvoicesListOptions.none(), requestOptions); } @@ -70,11 +71,27 @@ public CompletableFuture list(final RequestOptions requestO * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final InvoicesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private InvoicesListAsyncPage pageOfList( + InvoiceListResponse response, + final InvoicesListOptions options, + final RequestOptions requestOptions) { + List items = Invoices.itemsOfList(response); + Integer next = Invoices.nextOfList(response, items, options.page().orElse(0)); + return new InvoicesListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -237,9 +254,9 @@ private WithRawResponse() {} /** * List invoices with optional filtering by customer, subscription, or status. * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(InvoicesListOptions.none(), RequestOptions.none()); } @@ -247,9 +264,9 @@ public CompletableFuture> list() { * List invoices with optional filtering by customer, subscription, or status. * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final InvoicesListOptions options) { return list(options, RequestOptions.none()); } @@ -258,9 +275,9 @@ public CompletableFuture> list( * List invoices with optional filtering by customer, subscription, or status. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(InvoicesListOptions.none(), requestOptions); } @@ -270,11 +287,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final InvoicesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/InvoicesListAsyncPage.java b/src/main/java/com/meteroid/api/InvoicesListAsyncPage.java new file mode 100644 index 0000000..6126b14 --- /dev/null +++ b/src/main/java/com/meteroid/api/InvoicesListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.Invoice; +import com.meteroid.models.InvoiceListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link InvoicesAsync#list}: the {@link Invoice} items of one response, and the + * properties of its body, {@link InvoiceListResponse}. + */ +public final class InvoicesListAsyncPage extends AsyncPage { + private final InvoiceListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public InvoicesListAsyncPage( + InvoiceListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public InvoiceListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "InvoicesListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/InvoicesListPage.java b/src/main/java/com/meteroid/api/InvoicesListPage.java new file mode 100644 index 0000000..b9e90b0 --- /dev/null +++ b/src/main/java/com/meteroid/api/InvoicesListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.Invoice; +import com.meteroid.models.InvoiceListResponse; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Invoices#list}: the {@link Invoice} items of one response, and the properties of + * its body, {@link InvoiceListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class InvoicesListPage extends Page { + private final InvoiceListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public InvoicesListPage( + InvoiceListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public InvoiceListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "InvoicesListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Metrics.java b/src/main/java/com/meteroid/api/Metrics.java index e45d5d1..42b0f32 100644 --- a/src/main/java/com/meteroid/api/Metrics.java +++ b/src/main/java/com/meteroid/api/Metrics.java @@ -8,10 +8,12 @@ import com.meteroid.models.CreateMetricRequest; import com.meteroid.models.Metric; import com.meteroid.models.MetricListResponse; +import com.meteroid.models.MetricSummary; import com.meteroid.models.UpdateMetricRequest; import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -44,9 +46,9 @@ public WithRawResponse withRawResponse() { /** * List billable metrics * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public MetricListResponse list() { + public MetricsListPage list() { return list(MetricsListOptions.none(), RequestOptions.none()); } @@ -54,9 +56,9 @@ public MetricListResponse list() { * List billable metrics * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public MetricListResponse list(final MetricsListOptions options) { + public MetricsListPage list(final MetricsListOptions options) { return list(options, RequestOptions.none()); } @@ -64,9 +66,9 @@ public MetricListResponse list(final MetricsListOptions options) { * List billable metrics * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public MetricListResponse list(final RequestOptions requestOptions) { + public MetricsListPage list(final RequestOptions requestOptions) { return list(MetricsListOptions.none(), requestOptions); } @@ -75,11 +77,11 @@ public MetricListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public MetricListResponse list( + public MetricsListPage list( final MetricsListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -112,6 +114,41 @@ MeteroidHttpClient.Exchange exchangeList( .returning(MetricListResponse.class); } + private MetricsListPage pageOfList( + MetricListResponse response, + final MetricsListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new MetricsListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(MetricListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList( + MetricListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create a billable metric * @@ -303,9 +340,9 @@ private WithRawResponse() {} /** * List billable metrics * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(MetricsListOptions.none(), RequestOptions.none()); } @@ -313,9 +350,9 @@ public ApiResponse list() { * List billable metrics * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final MetricsListOptions options) { + public ApiResponse list(final MetricsListOptions options) { return list(options, RequestOptions.none()); } @@ -323,9 +360,9 @@ public ApiResponse list(final MetricsListOptions options) { * List billable metrics * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(MetricsListOptions.none(), requestOptions); } @@ -334,11 +371,16 @@ public ApiResponse list(final RequestOptions requestOptions) * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final MetricsListOptions options, final RequestOptions requestOptions) { - return Metrics.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/MetricsAsync.java b/src/main/java/com/meteroid/api/MetricsAsync.java index cdd86a7..7a4b943 100644 --- a/src/main/java/com/meteroid/api/MetricsAsync.java +++ b/src/main/java/com/meteroid/api/MetricsAsync.java @@ -6,8 +6,10 @@ import com.meteroid.models.CreateMetricRequest; import com.meteroid.models.Metric; import com.meteroid.models.MetricListResponse; +import com.meteroid.models.MetricSummary; import com.meteroid.models.UpdateMetricRequest; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -40,9 +42,9 @@ public WithRawResponse withRawResponse() { /** * List billable metrics * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(MetricsListOptions.none(), RequestOptions.none()); } @@ -50,9 +52,9 @@ public CompletableFuture list() { * List billable metrics * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final MetricsListOptions options) { + public CompletableFuture list(final MetricsListOptions options) { return list(options, RequestOptions.none()); } @@ -60,9 +62,9 @@ public CompletableFuture list(final MetricsListOptions optio * List billable metrics * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(MetricsListOptions.none(), requestOptions); } @@ -71,11 +73,27 @@ public CompletableFuture list(final RequestOptions requestOp * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final MetricsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private MetricsListAsyncPage pageOfList( + MetricListResponse response, + final MetricsListOptions options, + final RequestOptions requestOptions) { + List items = Metrics.itemsOfList(response); + Integer next = Metrics.nextOfList(response, items, options.page().orElse(0)); + return new MetricsListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -204,9 +222,9 @@ private WithRawResponse() {} /** * List billable metrics * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(MetricsListOptions.none(), RequestOptions.none()); } @@ -214,9 +232,9 @@ public CompletableFuture> list() { * List billable metrics * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final MetricsListOptions options) { return list(options, RequestOptions.none()); } @@ -225,9 +243,9 @@ public CompletableFuture> list( * List billable metrics * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(MetricsListOptions.none(), requestOptions); } @@ -237,11 +255,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final MetricsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/MetricsListAsyncPage.java b/src/main/java/com/meteroid/api/MetricsListAsyncPage.java new file mode 100644 index 0000000..09b849e --- /dev/null +++ b/src/main/java/com/meteroid/api/MetricsListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.MetricListResponse; +import com.meteroid.models.MetricSummary; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link MetricsAsync#list}: the {@link MetricSummary} items of one response, and the + * properties of its body, {@link MetricListResponse}. + */ +public final class MetricsListAsyncPage extends AsyncPage { + private final MetricListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public MetricsListAsyncPage( + MetricListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public MetricListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "MetricsListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/MetricsListPage.java b/src/main/java/com/meteroid/api/MetricsListPage.java new file mode 100644 index 0000000..01ca382 --- /dev/null +++ b/src/main/java/com/meteroid/api/MetricsListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.MetricListResponse; +import com.meteroid.models.MetricSummary; +import com.meteroid.models.PaginationResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Metrics#list}: the {@link MetricSummary} items of one response, and the + * properties of its body, {@link MetricListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class MetricsListPage extends Page { + private final MetricListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public MetricsListPage( + MetricListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public MetricListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "MetricsListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Plans.java b/src/main/java/com/meteroid/api/Plans.java index 3e3f596..572dfed 100644 --- a/src/main/java/com/meteroid/api/Plans.java +++ b/src/main/java/com/meteroid/api/Plans.java @@ -15,6 +15,7 @@ import com.meteroid.models.PlanStatusEnum; import com.meteroid.models.PlanTypeEnum; import com.meteroid.models.PlanVersionListResponse; +import com.meteroid.models.PlanVersionSummary; import com.meteroid.models.ReplacePlanRequest; import com.meteroid.models.ResolvedEntitlementListResponse; @@ -144,9 +145,9 @@ MeteroidHttpClient.Exchange exchangeCreatePlanVersionEn /** * List plans * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanListResponse list() { + public PlansListPage list() { return list(PlansListOptions.none(), RequestOptions.none()); } @@ -154,9 +155,9 @@ public PlanListResponse list() { * List plans * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanListResponse list(final PlansListOptions options) { + public PlansListPage list(final PlansListOptions options) { return list(options, RequestOptions.none()); } @@ -164,9 +165,9 @@ public PlanListResponse list(final PlansListOptions options) { * List plans * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanListResponse list(final RequestOptions requestOptions) { + public PlansListPage list(final RequestOptions requestOptions) { return list(PlansListOptions.none(), requestOptions); } @@ -175,11 +176,10 @@ public PlanListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanListResponse list( - final PlansListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + public PlansListPage list(final PlansListOptions options, final RequestOptions requestOptions) { + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -220,6 +220,40 @@ MeteroidHttpClient.Exchange exchangeList( .returning(PlanListResponse.class); } + private PlansListPage pageOfList( + PlanListResponse response, + final PlansListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new PlansListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(PlanListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList(PlanListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create a plan * @@ -634,9 +668,9 @@ MeteroidHttpClient.Exchange exchangeUnarchive( * List plan versions * * @param planId the {@code plan_id} path parameter - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanVersionListResponse listVersions(final String planId) { + public PlansListVersionsPage listVersions(final String planId) { return listVersions(planId, PlansListVersionsOptions.none(), RequestOptions.none()); } @@ -645,9 +679,9 @@ public PlanVersionListResponse listVersions(final String planId) { * * @param planId the {@code plan_id} path parameter * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanVersionListResponse listVersions( + public PlansListVersionsPage listVersions( final String planId, final PlansListVersionsOptions options) { return listVersions(planId, options, RequestOptions.none()); } @@ -657,9 +691,9 @@ public PlanVersionListResponse listVersions( * * @param planId the {@code plan_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanVersionListResponse listVersions( + public PlansListVersionsPage listVersions( final String planId, final RequestOptions requestOptions) { return listVersions(planId, PlansListVersionsOptions.none(), requestOptions); } @@ -670,13 +704,17 @@ public PlanVersionListResponse listVersions( * @param planId the {@code plan_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public PlanVersionListResponse listVersions( + public PlansListVersionsPage listVersions( final String planId, final PlansListVersionsOptions options, final RequestOptions requestOptions) { - return exchangeListVersions(planId, options, requestOptions).send(); + return pageOfListVersions( + exchangeListVersions(planId, options, requestOptions).send(), + planId, + options, + requestOptions); } MeteroidHttpClient.Exchange exchangeListVersions( @@ -704,6 +742,46 @@ MeteroidHttpClient.Exchange exchangeListVersions( .returning(PlanVersionListResponse.class); } + private PlansListVersionsPage pageOfListVersions( + PlanVersionListResponse response, + final String planId, + final PlansListVersionsOptions options, + final RequestOptions requestOptions) { + List items = itemsOfListVersions(response); + Integer next = nextOfListVersions(response, items, options.page().orElse(0)); + return new PlansListVersionsPage( + response, + items, + next == null + ? null + : () -> + listVersions( + planId, + options.toBuilder().page(next).build(), + requestOptions)); + } + + static List itemsOfListVersions(PlanVersionListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfListVersions( + PlanVersionListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** The operations, returning the status and headers along with the body. */ public final class WithRawResponse { private WithRawResponse() {} @@ -772,9 +850,9 @@ public ApiResponse createPlanVersionEntitlement( /** * List plans * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(PlansListOptions.none(), RequestOptions.none()); } @@ -782,9 +860,9 @@ public ApiResponse list() { * List plans * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final PlansListOptions options) { + public ApiResponse list(final PlansListOptions options) { return list(options, RequestOptions.none()); } @@ -792,9 +870,9 @@ public ApiResponse list(final PlansListOptions options) { * List plans * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(PlansListOptions.none(), requestOptions); } @@ -803,11 +881,16 @@ public ApiResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final PlansListOptions options, final RequestOptions requestOptions) { - return Plans.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** @@ -1089,9 +1172,9 @@ public ApiResponse unarchive( * List plan versions * * @param planId the {@code plan_id} path parameter - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listVersions(final String planId) { + public ApiResponse listVersions(final String planId) { return listVersions(planId, PlansListVersionsOptions.none(), RequestOptions.none()); } @@ -1100,9 +1183,9 @@ public ApiResponse listVersions(final String planId) { * * @param planId the {@code plan_id} path parameter * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listVersions( + public ApiResponse listVersions( final String planId, final PlansListVersionsOptions options) { return listVersions(planId, options, RequestOptions.none()); } @@ -1112,9 +1195,9 @@ public ApiResponse listVersions( * * @param planId the {@code plan_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listVersions( + public ApiResponse listVersions( final String planId, final RequestOptions requestOptions) { return listVersions(planId, PlansListVersionsOptions.none(), requestOptions); } @@ -1125,13 +1208,18 @@ public ApiResponse listVersions( * @param planId the {@code plan_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse listVersions( + public ApiResponse listVersions( final String planId, final PlansListVersionsOptions options, final RequestOptions requestOptions) { - return Plans.this.exchangeListVersions(planId, options, requestOptions).sendRaw(); + ApiResponse response = + exchangeListVersions(planId, options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfListVersions(response.body(), planId, options, requestOptions)); } } } diff --git a/src/main/java/com/meteroid/api/PlansAsync.java b/src/main/java/com/meteroid/api/PlansAsync.java index e4389aa..bacf7f6 100644 --- a/src/main/java/com/meteroid/api/PlansAsync.java +++ b/src/main/java/com/meteroid/api/PlansAsync.java @@ -11,9 +11,11 @@ import com.meteroid.models.Plan; import com.meteroid.models.PlanListResponse; import com.meteroid.models.PlanVersionListResponse; +import com.meteroid.models.PlanVersionSummary; import com.meteroid.models.ReplacePlanRequest; import com.meteroid.models.ResolvedEntitlementListResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -103,9 +105,9 @@ public CompletableFuture createPlanVersionEntitlement( /** * List plans * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(PlansListOptions.none(), RequestOptions.none()); } @@ -113,9 +115,9 @@ public CompletableFuture list() { * List plans * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final PlansListOptions options) { + public CompletableFuture list(final PlansListOptions options) { return list(options, RequestOptions.none()); } @@ -123,9 +125,9 @@ public CompletableFuture list(final PlansListOptions options) * List plans * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(PlansListOptions.none(), requestOptions); } @@ -134,11 +136,27 @@ public CompletableFuture list(final RequestOptions requestOpti * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final PlansListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private PlansListAsyncPage pageOfList( + PlanListResponse response, + final PlansListOptions options, + final RequestOptions requestOptions) { + List items = Plans.itemsOfList(response); + Integer next = Plans.nextOfList(response, items, options.page().orElse(0)); + return new PlansListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -422,9 +440,9 @@ public CompletableFuture unarchive( * List plan versions * * @param planId the {@code plan_id} path parameter - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listVersions(final String planId) { + public CompletableFuture listVersions(final String planId) { return listVersions(planId, PlansListVersionsOptions.none(), RequestOptions.none()); } @@ -433,9 +451,9 @@ public CompletableFuture listVersions(final String plan * * @param planId the {@code plan_id} path parameter * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listVersions( + public CompletableFuture listVersions( final String planId, final PlansListVersionsOptions options) { return listVersions(planId, options, RequestOptions.none()); } @@ -445,9 +463,9 @@ public CompletableFuture listVersions( * * @param planId the {@code plan_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listVersions( + public CompletableFuture listVersions( final String planId, final RequestOptions requestOptions) { return listVersions(planId, PlansListVersionsOptions.none(), requestOptions); } @@ -458,13 +476,35 @@ public CompletableFuture listVersions( * @param planId the {@code plan_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture listVersions( + public CompletableFuture listVersions( + final String planId, + final PlansListVersionsOptions options, + final RequestOptions requestOptions) { + return sync.exchangeListVersions(planId, options, requestOptions) + .sendAsync() + .thenApply( + response -> pageOfListVersions(response, planId, options, requestOptions)); + } + + private PlansListVersionsAsyncPage pageOfListVersions( + PlanVersionListResponse response, final String planId, final PlansListVersionsOptions options, final RequestOptions requestOptions) { - return sync.exchangeListVersions(planId, options, requestOptions).sendAsync(); + List items = Plans.itemsOfListVersions(response); + Integer next = Plans.nextOfListVersions(response, items, options.page().orElse(0)); + return new PlansListVersionsAsyncPage( + response, + items, + next == null + ? null + : () -> + listVersions( + planId, + options.toBuilder().page(next).build(), + requestOptions)); } /** The operations, returning the status and headers along with the body. */ @@ -534,9 +574,9 @@ public CompletableFuture> createPlanVersion /** * List plans * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(PlansListOptions.none(), RequestOptions.none()); } @@ -544,9 +584,9 @@ public CompletableFuture> list() { * List plans * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final PlansListOptions options) { return list(options, RequestOptions.none()); } @@ -555,9 +595,9 @@ public CompletableFuture> list( * List plans * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(PlansListOptions.none(), requestOptions); } @@ -567,11 +607,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final PlansListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** @@ -858,9 +905,9 @@ public CompletableFuture> unarchive( * List plan versions * * @param planId the {@code plan_id} path parameter - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listVersions( + public CompletableFuture> listVersions( final String planId) { return listVersions(planId, PlansListVersionsOptions.none(), RequestOptions.none()); } @@ -870,9 +917,9 @@ public CompletableFuture> listVersions( * * @param planId the {@code plan_id} path parameter * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listVersions( + public CompletableFuture> listVersions( final String planId, final PlansListVersionsOptions options) { return listVersions(planId, options, RequestOptions.none()); } @@ -882,9 +929,9 @@ public CompletableFuture> listVersions( * * @param planId the {@code plan_id} path parameter * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listVersions( + public CompletableFuture> listVersions( final String planId, final RequestOptions requestOptions) { return listVersions(planId, PlansListVersionsOptions.none(), requestOptions); } @@ -895,13 +942,24 @@ public CompletableFuture> listVersions( * @param planId the {@code plan_id} path parameter * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> listVersions( + public CompletableFuture> listVersions( final String planId, final PlansListVersionsOptions options, final RequestOptions requestOptions) { - return sync.exchangeListVersions(planId, options, requestOptions).sendRawAsync(); + return sync.exchangeListVersions(planId, options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfListVersions( + response.body(), + planId, + options, + requestOptions))); } } } diff --git a/src/main/java/com/meteroid/api/PlansListAsyncPage.java b/src/main/java/com/meteroid/api/PlansListAsyncPage.java new file mode 100644 index 0000000..4f7824b --- /dev/null +++ b/src/main/java/com/meteroid/api/PlansListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.Plan; +import com.meteroid.models.PlanListResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link PlansAsync#list}: the {@link Plan} items of one response, and the properties of + * its body, {@link PlanListResponse}. + */ +public final class PlansListAsyncPage extends AsyncPage { + private final PlanListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public PlansListAsyncPage( + PlanListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public PlanListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "PlansListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/PlansListPage.java b/src/main/java/com/meteroid/api/PlansListPage.java new file mode 100644 index 0000000..3ca8d8c --- /dev/null +++ b/src/main/java/com/meteroid/api/PlansListPage.java @@ -0,0 +1,65 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.Plan; +import com.meteroid.models.PlanListResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Plans#list}: the {@link Plan} items of one response, and the properties of its + * body, {@link PlanListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class PlansListPage extends Page { + private final PlanListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public PlansListPage(PlanListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public PlanListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "PlansListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/PlansListVersionsAsyncPage.java b/src/main/java/com/meteroid/api/PlansListVersionsAsyncPage.java new file mode 100644 index 0000000..3265cb2 --- /dev/null +++ b/src/main/java/com/meteroid/api/PlansListVersionsAsyncPage.java @@ -0,0 +1,67 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.PlanVersionListResponse; +import com.meteroid.models.PlanVersionSummary; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link PlansAsync#listVersions}: the {@link PlanVersionSummary} items of one response, + * and the properties of its body, {@link PlanVersionListResponse}. + */ +public final class PlansListVersionsAsyncPage + extends AsyncPage { + private final PlanVersionListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public PlansListVersionsAsyncPage( + PlanVersionListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public PlanVersionListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "PlansListVersionsAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/PlansListVersionsPage.java b/src/main/java/com/meteroid/api/PlansListVersionsPage.java new file mode 100644 index 0000000..27f341e --- /dev/null +++ b/src/main/java/com/meteroid/api/PlansListVersionsPage.java @@ -0,0 +1,68 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.PlanVersionListResponse; +import com.meteroid.models.PlanVersionSummary; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Plans#listVersions}: the {@link PlanVersionSummary} items of one response, and + * the properties of its body, {@link PlanVersionListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class PlansListVersionsPage extends Page { + private final PlanVersionListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public PlansListVersionsPage( + PlanVersionListResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public PlanVersionListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "PlansListVersionsPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/ProductFamilies.java b/src/main/java/com/meteroid/api/ProductFamilies.java index 5965721..7634cfa 100644 --- a/src/main/java/com/meteroid/api/ProductFamilies.java +++ b/src/main/java/com/meteroid/api/ProductFamilies.java @@ -11,6 +11,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -43,9 +44,9 @@ public WithRawResponse withRawResponse() { /** * List product families * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductFamilyListResponse list() { + public ProductFamiliesListPage list() { return list(ProductFamiliesListOptions.none(), RequestOptions.none()); } @@ -53,9 +54,9 @@ public ProductFamilyListResponse list() { * List product families * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductFamilyListResponse list(final ProductFamiliesListOptions options) { + public ProductFamiliesListPage list(final ProductFamiliesListOptions options) { return list(options, RequestOptions.none()); } @@ -63,9 +64,9 @@ public ProductFamilyListResponse list(final ProductFamiliesListOptions options) * List product families * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductFamilyListResponse list(final RequestOptions requestOptions) { + public ProductFamiliesListPage list(final RequestOptions requestOptions) { return list(ProductFamiliesListOptions.none(), requestOptions); } @@ -74,11 +75,11 @@ public ProductFamilyListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductFamilyListResponse list( + public ProductFamiliesListPage list( final ProductFamiliesListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -107,6 +108,41 @@ MeteroidHttpClient.Exchange exchangeList( .returning(ProductFamilyListResponse.class); } + private ProductFamiliesListPage pageOfList( + ProductFamilyListResponse response, + final ProductFamiliesListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new ProductFamiliesListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(ProductFamilyListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList( + ProductFamilyListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create product family * @@ -188,9 +224,9 @@ private WithRawResponse() {} /** * List product families * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(ProductFamiliesListOptions.none(), RequestOptions.none()); } @@ -198,10 +234,9 @@ public ApiResponse list() { * List product families * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( - final ProductFamiliesListOptions options) { + public ApiResponse list(final ProductFamiliesListOptions options) { return list(options, RequestOptions.none()); } @@ -209,9 +244,9 @@ public ApiResponse list( * List product families * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(ProductFamiliesListOptions.none(), requestOptions); } @@ -220,11 +255,16 @@ public ApiResponse list(final RequestOptions requestO * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final ProductFamiliesListOptions options, final RequestOptions requestOptions) { - return ProductFamilies.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/ProductFamiliesAsync.java b/src/main/java/com/meteroid/api/ProductFamiliesAsync.java index c566593..978a2fe 100644 --- a/src/main/java/com/meteroid/api/ProductFamiliesAsync.java +++ b/src/main/java/com/meteroid/api/ProductFamiliesAsync.java @@ -7,6 +7,7 @@ import com.meteroid.models.ProductFamilyCreateRequest; import com.meteroid.models.ProductFamilyListResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -39,9 +40,9 @@ public WithRawResponse withRawResponse() { /** * List product families * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(ProductFamiliesListOptions.none(), RequestOptions.none()); } @@ -49,9 +50,9 @@ public CompletableFuture list() { * List product families * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final ProductFamiliesListOptions options) { return list(options, RequestOptions.none()); } @@ -60,9 +61,10 @@ public CompletableFuture list( * List product families * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list( + final RequestOptions requestOptions) { return list(ProductFamiliesListOptions.none(), requestOptions); } @@ -71,11 +73,27 @@ public CompletableFuture list(final RequestOptions re * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final ProductFamiliesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private ProductFamiliesListAsyncPage pageOfList( + ProductFamilyListResponse response, + final ProductFamiliesListOptions options, + final RequestOptions requestOptions) { + List items = ProductFamilies.itemsOfList(response); + Integer next = ProductFamilies.nextOfList(response, items, options.page().orElse(0)); + return new ProductFamiliesListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -135,9 +153,9 @@ private WithRawResponse() {} /** * List product families * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(ProductFamiliesListOptions.none(), RequestOptions.none()); } @@ -145,9 +163,9 @@ public CompletableFuture> list() { * List product families * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final ProductFamiliesListOptions options) { return list(options, RequestOptions.none()); } @@ -156,9 +174,9 @@ public CompletableFuture> list( * List product families * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(ProductFamiliesListOptions.none(), requestOptions); } @@ -168,11 +186,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final ProductFamiliesListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/ProductFamiliesListAsyncPage.java b/src/main/java/com/meteroid/api/ProductFamiliesListAsyncPage.java new file mode 100644 index 0000000..810c4cb --- /dev/null +++ b/src/main/java/com/meteroid/api/ProductFamiliesListAsyncPage.java @@ -0,0 +1,67 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.ProductFamily; +import com.meteroid.models.ProductFamilyListResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link ProductFamiliesAsync#list}: the {@link ProductFamily} items of one response, and + * the properties of its body, {@link ProductFamilyListResponse}. + */ +public final class ProductFamiliesListAsyncPage + extends AsyncPage { + private final ProductFamilyListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public ProductFamiliesListAsyncPage( + ProductFamilyListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public ProductFamilyListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "ProductFamiliesListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/ProductFamiliesListPage.java b/src/main/java/com/meteroid/api/ProductFamiliesListPage.java new file mode 100644 index 0000000..655a561 --- /dev/null +++ b/src/main/java/com/meteroid/api/ProductFamiliesListPage.java @@ -0,0 +1,68 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.ProductFamily; +import com.meteroid.models.ProductFamilyListResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link ProductFamilies#list}: the {@link ProductFamily} items of one response, and the + * properties of its body, {@link ProductFamilyListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class ProductFamiliesListPage extends Page { + private final ProductFamilyListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public ProductFamiliesListPage( + ProductFamilyListResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public ProductFamilyListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "ProductFamiliesListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Products.java b/src/main/java/com/meteroid/api/Products.java index 65d3522..651c6df 100644 --- a/src/main/java/com/meteroid/api/Products.java +++ b/src/main/java/com/meteroid/api/Products.java @@ -15,6 +15,7 @@ import okhttp3.HttpUrl; +import java.util.List; import java.util.Objects; /** @@ -47,9 +48,9 @@ public WithRawResponse withRawResponse() { /** * List products * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductListResponse list() { + public ProductsListPage list() { return list(ProductsListOptions.none(), RequestOptions.none()); } @@ -57,9 +58,9 @@ public ProductListResponse list() { * List products * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductListResponse list(final ProductsListOptions options) { + public ProductsListPage list(final ProductsListOptions options) { return list(options, RequestOptions.none()); } @@ -67,9 +68,9 @@ public ProductListResponse list(final ProductsListOptions options) { * List products * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductListResponse list(final RequestOptions requestOptions) { + public ProductsListPage list(final RequestOptions requestOptions) { return list(ProductsListOptions.none(), requestOptions); } @@ -78,11 +79,11 @@ public ProductListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public ProductListResponse list( + public ProductsListPage list( final ProductsListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -115,6 +116,40 @@ MeteroidHttpClient.Exchange exchangeList( .returning(ProductListResponse.class); } + private ProductsListPage pageOfList( + ProductListResponse response, + final ProductsListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new ProductsListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(ProductListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList(ProductListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create a product * @@ -406,9 +441,9 @@ private WithRawResponse() {} /** * List products * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(ProductsListOptions.none(), RequestOptions.none()); } @@ -416,9 +451,9 @@ public ApiResponse list() { * List products * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final ProductsListOptions options) { + public ApiResponse list(final ProductsListOptions options) { return list(options, RequestOptions.none()); } @@ -426,9 +461,9 @@ public ApiResponse list(final ProductsListOptions options) * List products * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(ProductsListOptions.none(), requestOptions); } @@ -437,11 +472,16 @@ public ApiResponse list(final RequestOptions requestOptions * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final ProductsListOptions options, final RequestOptions requestOptions) { - return Products.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/ProductsAsync.java b/src/main/java/com/meteroid/api/ProductsAsync.java index de98d6b..a0b8f6d 100644 --- a/src/main/java/com/meteroid/api/ProductsAsync.java +++ b/src/main/java/com/meteroid/api/ProductsAsync.java @@ -11,6 +11,7 @@ import com.meteroid.models.ResolvedEntitlementListResponse; import com.meteroid.models.UpdateProductRequest; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -43,9 +44,9 @@ public WithRawResponse withRawResponse() { /** * List products * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(ProductsListOptions.none(), RequestOptions.none()); } @@ -53,9 +54,9 @@ public CompletableFuture list() { * List products * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final ProductsListOptions options) { + public CompletableFuture list(final ProductsListOptions options) { return list(options, RequestOptions.none()); } @@ -63,9 +64,9 @@ public CompletableFuture list(final ProductsListOptions opt * List products * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(ProductsListOptions.none(), requestOptions); } @@ -74,11 +75,27 @@ public CompletableFuture list(final RequestOptions requestO * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final ProductsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private ProductsListAsyncPage pageOfList( + ProductListResponse response, + final ProductsListOptions options, + final RequestOptions requestOptions) { + List items = Products.itemsOfList(response); + Integer next = Products.nextOfList(response, items, options.page().orElse(0)); + return new ProductsListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -274,9 +291,9 @@ private WithRawResponse() {} /** * List products * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(ProductsListOptions.none(), RequestOptions.none()); } @@ -284,9 +301,9 @@ public CompletableFuture> list() { * List products * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final ProductsListOptions options) { return list(options, RequestOptions.none()); } @@ -295,9 +312,9 @@ public CompletableFuture> list( * List products * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(ProductsListOptions.none(), requestOptions); } @@ -307,11 +324,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final ProductsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/ProductsListAsyncPage.java b/src/main/java/com/meteroid/api/ProductsListAsyncPage.java new file mode 100644 index 0000000..39f8111 --- /dev/null +++ b/src/main/java/com/meteroid/api/ProductsListAsyncPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.Product; +import com.meteroid.models.ProductListResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link ProductsAsync#list}: the {@link Product} items of one response, and the + * properties of its body, {@link ProductListResponse}. + */ +public final class ProductsListAsyncPage extends AsyncPage { + private final ProductListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public ProductsListAsyncPage( + ProductListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public ProductListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "ProductsListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/ProductsListPage.java b/src/main/java/com/meteroid/api/ProductsListPage.java new file mode 100644 index 0000000..3092b15 --- /dev/null +++ b/src/main/java/com/meteroid/api/ProductsListPage.java @@ -0,0 +1,66 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.Product; +import com.meteroid.models.ProductListResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Products#list}: the {@link Product} items of one response, and the properties of + * its body, {@link ProductListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class ProductsListPage extends Page { + private final ProductListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public ProductsListPage( + ProductListResponse body, List items, Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public ProductListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "ProductsListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/Subscriptions.java b/src/main/java/com/meteroid/api/Subscriptions.java index 74985b9..e6aa7e8 100644 --- a/src/main/java/com/meteroid/api/Subscriptions.java +++ b/src/main/java/com/meteroid/api/Subscriptions.java @@ -51,9 +51,9 @@ public WithRawResponse withRawResponse() { /** * List subscriptions with optional filtering by customer or plan. * - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public SubscriptionListResponse list() { + public SubscriptionsListPage list() { return list(SubscriptionsListOptions.none(), RequestOptions.none()); } @@ -61,9 +61,9 @@ public SubscriptionListResponse list() { * List subscriptions with optional filtering by customer or plan. * * @param options the optional parameters - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public SubscriptionListResponse list(final SubscriptionsListOptions options) { + public SubscriptionsListPage list(final SubscriptionsListOptions options) { return list(options, RequestOptions.none()); } @@ -71,9 +71,9 @@ public SubscriptionListResponse list(final SubscriptionsListOptions options) { * List subscriptions with optional filtering by customer or plan. * * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public SubscriptionListResponse list(final RequestOptions requestOptions) { + public SubscriptionsListPage list(final RequestOptions requestOptions) { return list(SubscriptionsListOptions.none(), requestOptions); } @@ -82,11 +82,11 @@ public SubscriptionListResponse list(final RequestOptions requestOptions) { * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body + * @return the page: the response body, its items and the way to the next pages */ - public SubscriptionListResponse list( + public SubscriptionsListPage list( final SubscriptionsListOptions options, final RequestOptions requestOptions) { - return exchangeList(options, requestOptions).send(); + return pageOfList(exchangeList(options, requestOptions).send(), options, requestOptions); } MeteroidHttpClient.Exchange exchangeList( @@ -123,6 +123,41 @@ MeteroidHttpClient.Exchange exchangeList( .returning(SubscriptionListResponse.class); } + private SubscriptionsListPage pageOfList( + SubscriptionListResponse response, + final SubscriptionsListOptions options, + final RequestOptions requestOptions) { + List items = itemsOfList(response); + Integer next = nextOfList(response, items, options.page().orElse(0)); + return new SubscriptionsListPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); + } + + static List itemsOfList(SubscriptionListResponse response) { + return Utils.optional(response.data()).orElse(List.of()); + } + + /** The parameter of the page after {@code response}, null after the last one. */ + static Integer nextOfList( + SubscriptionListResponse response, List items, Integer current) { + if (items.isEmpty()) { + return null; + } + long pages = + Utils.optional(response.paginationMeta()) + .flatMap(v2 -> Utils.optional(v2.totalPages())) + .map(Number::longValue) + .orElse(Long.MAX_VALUE); + if (current - 0 + 1 >= pages) { + return null; + } + return current + 1; + } + /** * Create subscription * @@ -394,9 +429,9 @@ private WithRawResponse() {} /** * List subscriptions with optional filtering by customer or plan. * - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list() { + public ApiResponse list() { return list(SubscriptionsListOptions.none(), RequestOptions.none()); } @@ -404,9 +439,9 @@ public ApiResponse list() { * List subscriptions with optional filtering by customer or plan. * * @param options the optional parameters - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final SubscriptionsListOptions options) { + public ApiResponse list(final SubscriptionsListOptions options) { return list(options, RequestOptions.none()); } @@ -414,9 +449,9 @@ public ApiResponse list(final SubscriptionsListOptions * List subscriptions with optional filtering by customer or plan. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list(final RequestOptions requestOptions) { + public ApiResponse list(final RequestOptions requestOptions) { return list(SubscriptionsListOptions.none(), requestOptions); } @@ -425,11 +460,16 @@ public ApiResponse list(final RequestOptions requestOp * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body + * @return the status, headers and page */ - public ApiResponse list( + public ApiResponse list( final SubscriptionsListOptions options, final RequestOptions requestOptions) { - return Subscriptions.this.exchangeList(options, requestOptions).sendRaw(); + ApiResponse response = + exchangeList(options, requestOptions).sendRaw(); + return new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions)); } /** diff --git a/src/main/java/com/meteroid/api/SubscriptionsAsync.java b/src/main/java/com/meteroid/api/SubscriptionsAsync.java index ce653d0..b8fd584 100644 --- a/src/main/java/com/meteroid/api/SubscriptionsAsync.java +++ b/src/main/java/com/meteroid/api/SubscriptionsAsync.java @@ -13,6 +13,7 @@ import com.meteroid.models.SubscriptionUpdateRequest; import com.meteroid.models.SubscriptionUpdateResponse; +import java.util.List; import java.util.concurrent.CompletableFuture; /** @@ -45,9 +46,9 @@ public WithRawResponse withRawResponse() { /** * List subscriptions with optional filtering by customer or plan. * - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list() { + public CompletableFuture list() { return list(SubscriptionsListOptions.none(), RequestOptions.none()); } @@ -55,9 +56,9 @@ public CompletableFuture list() { * List subscriptions with optional filtering by customer or plan. * * @param options the optional parameters - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final SubscriptionsListOptions options) { return list(options, RequestOptions.none()); } @@ -66,9 +67,9 @@ public CompletableFuture list( * List subscriptions with optional filtering by customer or plan. * * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list(final RequestOptions requestOptions) { + public CompletableFuture list(final RequestOptions requestOptions) { return list(SubscriptionsListOptions.none(), requestOptions); } @@ -77,11 +78,27 @@ public CompletableFuture list(final RequestOptions req * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the response body, once received + * @return the page, once received */ - public CompletableFuture list( + public CompletableFuture list( final SubscriptionsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendAsync(); + return sync.exchangeList(options, requestOptions) + .sendAsync() + .thenApply(response -> pageOfList(response, options, requestOptions)); + } + + private SubscriptionsListAsyncPage pageOfList( + SubscriptionListResponse response, + final SubscriptionsListOptions options, + final RequestOptions requestOptions) { + List items = Subscriptions.itemsOfList(response); + Integer next = Subscriptions.nextOfList(response, items, options.page().orElse(0)); + return new SubscriptionsListAsyncPage( + response, + items, + next == null + ? null + : () -> list(options.toBuilder().page(next).build(), requestOptions)); } /** @@ -260,9 +277,9 @@ private WithRawResponse() {} /** * List subscriptions with optional filtering by customer or plan. * - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list() { + public CompletableFuture> list() { return list(SubscriptionsListOptions.none(), RequestOptions.none()); } @@ -270,9 +287,9 @@ public CompletableFuture> list() { * List subscriptions with optional filtering by customer or plan. * * @param options the optional parameters - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final SubscriptionsListOptions options) { return list(options, RequestOptions.none()); } @@ -281,9 +298,9 @@ public CompletableFuture> list( * List subscriptions with optional filtering by customer or plan. * * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final RequestOptions requestOptions) { return list(SubscriptionsListOptions.none(), requestOptions); } @@ -293,11 +310,18 @@ public CompletableFuture> list( * * @param options the optional parameters * @param requestOptions headers, timeout and retries of this call - * @return the status, headers and body, once received + * @return the status, headers and page, once received */ - public CompletableFuture> list( + public CompletableFuture> list( final SubscriptionsListOptions options, final RequestOptions requestOptions) { - return sync.exchangeList(options, requestOptions).sendRawAsync(); + return sync.exchangeList(options, requestOptions) + .sendRawAsync() + .thenApply( + response -> + new ApiResponse<>( + response.statusCode(), + response.headers(), + pageOfList(response.body(), options, requestOptions))); } /** diff --git a/src/main/java/com/meteroid/api/SubscriptionsListAsyncPage.java b/src/main/java/com/meteroid/api/SubscriptionsListAsyncPage.java new file mode 100644 index 0000000..9c7fb07 --- /dev/null +++ b/src/main/java/com/meteroid/api/SubscriptionsListAsyncPage.java @@ -0,0 +1,67 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.AsyncPage; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.Subscription; +import com.meteroid.models.SubscriptionListResponse; + +import java.util.List; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * A page of {@link SubscriptionsAsync#list}: the {@link Subscription} items of one response, and + * the properties of its body, {@link SubscriptionListResponse}. + */ +public final class SubscriptionsListAsyncPage + extends AsyncPage { + private final SubscriptionListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public SubscriptionsListAsyncPage( + SubscriptionListResponse body, + List items, + Supplier> next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public SubscriptionListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "SubscriptionsListAsyncPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/api/SubscriptionsListPage.java b/src/main/java/com/meteroid/api/SubscriptionsListPage.java new file mode 100644 index 0000000..210bf5b --- /dev/null +++ b/src/main/java/com/meteroid/api/SubscriptionsListPage.java @@ -0,0 +1,68 @@ +// this file is @generated +package com.meteroid.api; + +import com.meteroid.Page; +import com.meteroid.models.PaginationResponse; +import com.meteroid.models.Subscription; +import com.meteroid.models.SubscriptionListResponse; + +import java.util.List; +import java.util.function.Supplier; + +/** + * A page of {@link Subscriptions#list}: the {@link Subscription} items of one response, and the + * properties of its body, {@link SubscriptionListResponse}. + * + *

Iterating it yields every item from this page on, fetching the next pages as the iteration + * goes. + */ +public final class SubscriptionsListPage extends Page { + private final SubscriptionListResponse body; + + /** + * A page, built by the SDK. + * + * @param body the response body + * @param items the items of the page + * @param next fetches the next page, or null on the last page + */ + public SubscriptionsListPage( + SubscriptionListResponse body, + List items, + Supplier next) { + super(items, next); + this.body = body; + } + + /** + * The response body, as received. + * + * @return the body + */ + public SubscriptionListResponse body() { + return body; + } + + /** + * The {@code data} property. + * + * @return the value, never null + */ + public List data() { + return body.data(); + } + + /** + * The {@code pagination_meta} property. + * + * @return the value, never null + */ + public PaginationResponse paginationMeta() { + return body.paginationMeta(); + } + + @Override + public String toString() { + return "SubscriptionsListPage{body=" + body + ", hasNextPage=" + hasNextPage() + "}"; + } +} diff --git a/src/main/java/com/meteroid/internal/MeteroidHttpClient.java b/src/main/java/com/meteroid/internal/MeteroidHttpClient.java index 6c35354..1f6261c 100644 --- a/src/main/java/com/meteroid/internal/MeteroidHttpClient.java +++ b/src/main/java/com/meteroid/internal/MeteroidHttpClient.java @@ -63,6 +63,13 @@ public final class MeteroidHttpClient implements AutoCloseable { private static final Set IDEMPOTENT_METHODS = Set.of("GET", "HEAD", "PUT", "DELETE", "OPTIONS", "TRACE"); private static final Set BODY_METHODS = Set.of("POST", "PUT", "PATCH"); + + /** + * Whether the API deduplicates POSTs by {@code Idempotency-Key}, so that each gets one to be + * retried. + */ + private static final boolean AUTO_IDEMPOTENCY_KEY = false; + private static final Duration MAX_RETRY_AFTER = Duration.ofSeconds(60); private static final Duration MAX_CONNECT_TIMEOUT = Duration.ofSeconds(10); private static final long DEFAULT_BACKOFF_MILLIS = 500; @@ -151,6 +158,8 @@ private MeteroidAuth.Grant fetchToken( JsonNode answer = withSecurity(List.of()) .call("POST", url) + // Another token is as good as the first: the request is safe to retry. + .retrySafe() .headers(headers) .body(form.build()) .returning(JsonNode.class) @@ -347,6 +356,7 @@ public final class Call { private RequestBody body; private final Map> errors = new HashMap<>(); private RequestOptions options = RequestOptions.none(); + private boolean retrySafe; private Call(String method, HttpUrl url) { this.method = method; @@ -404,6 +414,16 @@ public Call body(RequestBody body) { return this; } + /** + * Marks a POST as safe to retry without an idempotency key. + * + * @return this call + */ + public Call retrySafe() { + this.retrySafe = true; + return this; + } + /** * The schema of error bodies with these statuses. * @@ -581,6 +601,9 @@ private Request request(boolean streaming) { content = RequestBody.create(new byte[0], null); } Request.Builder request = new Request.Builder().url(url).method(verb, content); + if (retrySafe) { + request.tag(RetrySafe.class, RetrySafe.INSTANCE); + } defaultHeaders.forEach(request::header); if (auth != null) { auth.apply(request, url, security); @@ -600,7 +623,9 @@ private Request request(boolean streaming) { request.header("Cookie", String.join("; ", cookies)); } String idempotencyKey = request.build().header("idempotency-key"); - if ((idempotencyKey == null || idempotencyKey.isEmpty()) && verb.equals("POST")) { + if (AUTO_IDEMPOTENCY_KEY + && (idempotencyKey == null || idempotencyKey.isEmpty()) + && verb.equals("POST")) { request.header("idempotency-key", "auto_" + UUID.randomUUID()); } request.header( @@ -888,9 +913,15 @@ private static void setHeader(Request.Builder request, String name, String value } } + /** Tags the requests that are safe to retry whatever their method. */ + private enum RetrySafe { + INSTANCE + } + private static boolean retryable(Request request) { RequestBody body = request.body(); return (IDEMPOTENT_METHODS.contains(request.method()) + || request.tag(RetrySafe.class) != null || request.header("idempotency-key") != null) && (body == null || !body.isOneShot()); }