diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 94046873..ebbaa260 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -12,8 +12,6 @@ jobs:
lint:
name: lint
runs-on: ubuntu-latest
-
-
steps:
- uses: actions/checkout@v4
@@ -34,7 +32,6 @@ jobs:
test:
name: test
runs-on: ubuntu-latest
-
steps:
- uses: actions/checkout@v4
diff --git a/.release-please-manifest.json b/.release-please-manifest.json
index d940b600..87d3d84c 100644
--- a/.release-please-manifest.json
+++ b/.release-please-manifest.json
@@ -1,3 +1,3 @@
{
- ".": "0.55.0"
+ ".": "0.56.0"
}
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 51e113d8..7d6c32c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,36 @@
# Changelog
+## 0.56.0 (2025-04-09)
+
+Full Changelog: [v0.55.0...v0.56.0](https://github.com/orbcorp/orb-java/compare/v0.55.0...v0.56.0)
+
+### Features
+
+* **client:** make pagination robust to missing data ([bf8c89e](https://github.com/orbcorp/orb-java/commit/bf8c89e3e5148a99afd9b9e5f211dd3002c2d88e))
+* **client:** support setting base URL via env var ([#397](https://github.com/orbcorp/orb-java/issues/397)) ([4ac10b3](https://github.com/orbcorp/orb-java/commit/4ac10b3cf164a76c7da1e0c5fc12aeec0338d0d3))
+
+
+### Bug Fixes
+
+* **client:** bump to better jackson version ([#400](https://github.com/orbcorp/orb-java/issues/400)) ([b9c0a00](https://github.com/orbcorp/orb-java/commit/b9c0a00b0181bfbaf7a9a2f670b98000dfa4b996))
+
+
+### Chores
+
+* **internal:** expand CI branch coverage ([#399](https://github.com/orbcorp/orb-java/issues/399)) ([17d8399](https://github.com/orbcorp/orb-java/commit/17d8399351f5affa7a89fbc79df9e88c732c1330))
+* **internal:** reduce CI branch coverage ([06a8495](https://github.com/orbcorp/orb-java/commit/06a84957b55d697cbb0bd3a8c6f9a4a02f95d90c))
+
+
+### Documentation
+
+* add comments for page methods ([bf8c89e](https://github.com/orbcorp/orb-java/commit/bf8c89e3e5148a99afd9b9e5f211dd3002c2d88e))
+
+
+### Refactors
+
+* **client:** deduplicate page response classes ([#401](https://github.com/orbcorp/orb-java/issues/401)) ([bf8c89e](https://github.com/orbcorp/orb-java/commit/bf8c89e3e5148a99afd9b9e5f211dd3002c2d88e))
+* **client:** migrate pages to builder pattern ([#402](https://github.com/orbcorp/orb-java/issues/402)) ([bbcd954](https://github.com/orbcorp/orb-java/commit/bbcd9545d5fad36f5b241ecc5515b44454533265))
+
## 0.55.0 (2025-04-08)
Full Changelog: [v0.54.0...v0.55.0](https://github.com/orbcorp/orb-java/compare/v0.54.0...v0.55.0)
diff --git a/README.md b/README.md
index 9eb20414..6bb662be 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
-[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.55.0)
+[](https://central.sonatype.com/artifact/com.withorb.api/orb-java/0.56.0)
@@ -19,7 +19,7 @@ The REST API documentation can be found on [docs.withorb.com](https://docs.witho
### Gradle
```kotlin
-implementation("com.withorb.api:orb-java:0.55.0")
+implementation("com.withorb.api:orb-java:0.56.0")
```
### Maven
@@ -28,7 +28,7 @@ implementation("com.withorb.api:orb-java:0.55.0")
com.withorb.api
orb-java
- 0.55.0
+ 0.56.0
```
@@ -46,7 +46,7 @@ import com.withorb.api.client.okhttp.OrbOkHttpClient;
import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
-// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
+// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
OrbClient client = OrbOkHttpClient.fromEnv();
CustomerCreateParams params = CustomerCreateParams.builder()
@@ -64,7 +64,7 @@ Configure the client using environment variables:
import com.withorb.api.client.OrbClient;
import com.withorb.api.client.okhttp.OrbOkHttpClient;
-// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
+// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
OrbClient client = OrbOkHttpClient.fromEnv();
```
@@ -86,7 +86,7 @@ import com.withorb.api.client.OrbClient;
import com.withorb.api.client.okhttp.OrbOkHttpClient;
OrbClient client = OrbOkHttpClient.builder()
- // Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
+ // Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
.fromEnv()
.apiKey("My API Key")
.build();
@@ -94,10 +94,11 @@ OrbClient client = OrbOkHttpClient.builder()
See this table for the available options:
-| Setter | Environment variable | Required | Default value |
-| --------------- | -------------------- | -------- | ------------- |
-| `apiKey` | `ORB_API_KEY` | true | - |
-| `webhookSecret` | `ORB_WEBHOOK_SECRET` | false | - |
+| Setter | Environment variable | Required | Default value |
+| --------------- | -------------------- | -------- | ------------------------------ |
+| `apiKey` | `ORB_API_KEY` | true | - |
+| `webhookSecret` | `ORB_WEBHOOK_SECRET` | false | - |
+| `baseUrl` | `ORB_BASE_URL` | true | `"https://api.withorb.com/v1"` |
> [!TIP]
> Don't create more than one client in the same application. Each client has a connection pool and
@@ -128,7 +129,7 @@ import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
import java.util.concurrent.CompletableFuture;
-// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
+// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
OrbClient client = OrbOkHttpClient.fromEnv();
CustomerCreateParams params = CustomerCreateParams.builder()
@@ -147,7 +148,7 @@ import com.withorb.api.models.Customer;
import com.withorb.api.models.CustomerCreateParams;
import java.util.concurrent.CompletableFuture;
-// Configures using the `ORB_API_KEY` and `ORB_WEBHOOK_SECRET` environment variables
+// Configures using the `ORB_API_KEY`, `ORB_WEBHOOK_SECRET` and `ORB_BASE_URL` environment variables
OrbClientAsync client = OrbOkHttpClientAsync.fromEnv();
CustomerCreateParams params = CustomerCreateParams.builder()
diff --git a/build.gradle.kts b/build.gradle.kts
index f2cb58af..3973ccca 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,4 +1,4 @@
allprojects {
group = "com.withorb.api"
- version = "0.55.0" // x-release-please-version
+ version = "0.56.0" // x-release-please-version
}
diff --git a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt
index e3b5ce1e..458d3da8 100644
--- a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt
+++ b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClient.kt
@@ -29,14 +29,10 @@ class OrbOkHttpClient private constructor() {
class Builder internal constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
- private var baseUrl: String = ClientOptions.PRODUCTION_URL
private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
- fun baseUrl(baseUrl: String) = apply {
- clientOptions.baseUrl(baseUrl)
- this.baseUrl = baseUrl
- }
+ fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) }
/**
* Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -177,7 +173,7 @@ class OrbOkHttpClient private constructor() {
clientOptions
.httpClient(
OkHttpClient.builder()
- .baseUrl(baseUrl)
+ .baseUrl(clientOptions.baseUrl())
.timeout(timeout)
.proxy(proxy)
.build()
diff --git a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt
index ef9cbe65..f8d51c09 100644
--- a/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt
+++ b/orb-java-client-okhttp/src/main/kotlin/com/withorb/api/client/okhttp/OrbOkHttpClientAsync.kt
@@ -29,14 +29,10 @@ class OrbOkHttpClientAsync private constructor() {
class Builder internal constructor() {
private var clientOptions: ClientOptions.Builder = ClientOptions.builder()
- private var baseUrl: String = ClientOptions.PRODUCTION_URL
private var timeout: Timeout = Timeout.default()
private var proxy: Proxy? = null
- fun baseUrl(baseUrl: String) = apply {
- clientOptions.baseUrl(baseUrl)
- this.baseUrl = baseUrl
- }
+ fun baseUrl(baseUrl: String) = apply { clientOptions.baseUrl(baseUrl) }
/**
* Whether to throw an exception if any of the Jackson versions detected at runtime are
@@ -177,7 +173,7 @@ class OrbOkHttpClientAsync private constructor() {
clientOptions
.httpClient(
OkHttpClient.builder()
- .baseUrl(baseUrl)
+ .baseUrl(clientOptions.baseUrl())
.timeout(timeout)
.proxy(proxy)
.build()
diff --git a/orb-java-core/build.gradle.kts b/orb-java-core/build.gradle.kts
index 8a8d05d5..6955eac0 100644
--- a/orb-java-core/build.gradle.kts
+++ b/orb-java-core/build.gradle.kts
@@ -17,14 +17,14 @@ configurations.all {
}
dependencies {
- api("com.fasterxml.jackson.core:jackson-core:2.18.1")
- api("com.fasterxml.jackson.core:jackson-databind:2.18.1")
+ api("com.fasterxml.jackson.core:jackson-core:2.18.2")
+ api("com.fasterxml.jackson.core:jackson-databind:2.18.2")
api("com.google.errorprone:error_prone_annotations:2.33.0")
- implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.1")
- implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.1")
- implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.1")
- implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.1")
+ implementation("com.fasterxml.jackson.core:jackson-annotations:2.18.2")
+ implementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.18.2")
+ implementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.2")
+ implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.18.2")
implementation("org.apache.httpcomponents.core5:httpcore5:5.2.4")
implementation("org.apache.httpcomponents.client5:httpclient5:5.3.1")
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
index 82fe7ba1..df5773f1 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/Check.kt
@@ -47,6 +47,7 @@ internal fun checkMaxLength(name: String, value: String, maxLength: Int): String
internal fun checkJacksonVersionCompatibility() {
val incompatibleJacksonVersions =
RUNTIME_JACKSON_VERSIONS.mapNotNull {
+ val badVersionReason = BAD_JACKSON_VERSIONS[it.toString()]
when {
it.majorVersion != MINIMUM_JACKSON_VERSION.majorVersion ->
it to "incompatible major version"
@@ -55,6 +56,7 @@ internal fun checkJacksonVersionCompatibility() {
it.minorVersion == MINIMUM_JACKSON_VERSION.minorVersion &&
it.patchLevel < MINIMUM_JACKSON_VERSION.patchLevel ->
it to "patch version too low"
+ badVersionReason != null -> it to badVersionReason
else -> null
}
}
@@ -77,6 +79,8 @@ Double-check that you are depending on compatible Jackson versions.
}
private val MINIMUM_JACKSON_VERSION: Version = VersionUtil.parseVersion("2.13.4", null, null)
+private val BAD_JACKSON_VERSIONS: Map =
+ mapOf("2.18.1" to "due to https://github.com/FasterXML/jackson-databind/issues/4639")
private val RUNTIME_JACKSON_VERSIONS: List =
listOf(
com.fasterxml.jackson.core.json.PackageVersion.VERSION,
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt b/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
index 8fc681ad..33a56193 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/core/ClientOptions.kt
@@ -197,7 +197,10 @@ private constructor(
fun removeAllQueryParams(keys: Set) = apply { queryParams.removeAll(keys) }
+ fun baseUrl(): String = baseUrl
+
fun fromEnv() = apply {
+ System.getenv("ORB_BASE_URL")?.let { baseUrl(it) }
System.getenv("ORB_API_KEY")?.let { apiKey(it) }
System.getenv("ORB_WEBHOOK_SECRET")?.let { webhookSecret(it) }
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt
index 88911b52..e34c1eaf 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPage.kt
@@ -2,67 +2,40 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.blocking.AlertService
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.stream.Stream
import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/**
- * This endpoint returns a list of alerts within Orb.
- *
- * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`.
- *
- * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as
- * the plan level alerts associated with the subscription.
- *
- * The list of alerts is ordered starting from the most recently created alert. This endpoint
- * follows Orb's [standardized pagination format](/api-reference/pagination).
- */
+/** @see [AlertService.list] */
class AlertListPage
private constructor(
- private val alertsService: AlertService,
+ private val service: AlertService,
private val params: AlertListParams,
- private val response: Response,
+ private val response: AlertListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is AlertListPage && alertsService == other.alertsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertsService, params, response) /* spotless:on */
-
- override fun toString() =
- "AlertListPage{alertsService=$alertsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [AlertListPageResponse], but gracefully handles missing data.
+ *
+ * @see [AlertListPageResponse.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [AlertListPageResponse], but gracefully handles missing data.
+ *
+ * @see [AlertListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -70,138 +43,86 @@ private constructor(
}
return Optional.of(
- AlertListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): Optional {
- return getNextPageParams().map { alertsService.list(it) }
- }
+ fun getNextPage(): Optional = getNextPageParams().map { service.list(it) }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(alertsService: AlertService, params: AlertListParams, response: Response) =
- AlertListPage(alertsService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
+ /** The parameters that were used to request this page. */
+ fun params(): AlertListParams = params
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
+ /** The response that this page was parsed from. */
+ fun response(): AlertListPageResponse = response
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
+ fun toBuilder() = Builder().from(this)
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
-
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
-
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
-
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [AlertListPage].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [AlertListPage]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: AlertService? = null
+ private var params: AlertListParams? = null
+ private var response: AlertListPageResponse? = null
- /** Returns a mutable builder for constructing an instance of [AlertListPage]. */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(alertListPage: AlertListPage) = apply {
+ service = alertListPage.service
+ params = alertListPage.params
+ response = alertListPage.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: AlertService) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: AlertListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: AlertListPageResponse) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [AlertListPage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): AlertListPage =
+ AlertListPage(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: AlertListPage) : Iterable {
@@ -222,4 +143,16 @@ private constructor(
return StreamSupport.stream(spliterator(), false)
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AlertListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() = "AlertListPage{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt
index b8f17466..8a37ce8d 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageAsync.kt
@@ -2,17 +2,8 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.async.AlertServiceAsync
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.concurrent.CompletableFuture
@@ -20,50 +11,32 @@ import java.util.concurrent.Executor
import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/**
- * This endpoint returns a list of alerts within Orb.
- *
- * The request must specify one of `customer_id`, `external_customer_id`, or `subscription_id`.
- *
- * If querying by subscripion_id, the endpoint will return the subscription level alerts as well as
- * the plan level alerts associated with the subscription.
- *
- * The list of alerts is ordered starting from the most recently created alert. This endpoint
- * follows Orb's [standardized pagination format](/api-reference/pagination).
- */
+/** @see [AlertServiceAsync.list] */
class AlertListPageAsync
private constructor(
- private val alertsService: AlertServiceAsync,
+ private val service: AlertServiceAsync,
private val params: AlertListParams,
- private val response: Response,
+ private val response: AlertListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is AlertListPageAsync && alertsService == other.alertsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(alertsService, params, response) /* spotless:on */
-
- override fun toString() =
- "AlertListPageAsync{alertsService=$alertsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [AlertListPageResponse], but gracefully handles missing data.
+ *
+ * @see [AlertListPageResponse.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [AlertListPageResponse], but gracefully handles missing data.
+ *
+ * @see [AlertListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -71,140 +44,89 @@ private constructor(
}
return Optional.of(
- AlertListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): CompletableFuture> {
- return getNextPageParams()
- .map { alertsService.list(it).thenApply { Optional.of(it) } }
+ fun getNextPage(): CompletableFuture> =
+ getNextPageParams()
+ .map { service.list(it).thenApply { Optional.of(it) } }
.orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
- }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(alertsService: AlertServiceAsync, params: AlertListParams, response: Response) =
- AlertListPageAsync(alertsService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
-
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
-
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
+ /** The parameters that were used to request this page. */
+ fun params(): AlertListParams = params
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
+ /** The response that this page was parsed from. */
+ fun response(): AlertListPageResponse = response
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
+ fun toBuilder() = Builder().from(this)
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [AlertListPageAsync].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [AlertListPageAsync]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: AlertServiceAsync? = null
+ private var params: AlertListParams? = null
+ private var response: AlertListPageResponse? = null
- /** Returns a mutable builder for constructing an instance of [AlertListPageAsync]. */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(alertListPageAsync: AlertListPageAsync) = apply {
+ service = alertListPageAsync.service
+ params = alertListPageAsync.params
+ response = alertListPageAsync.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: AlertServiceAsync) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: AlertListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: AlertListPageResponse) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [AlertListPageAsync].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): AlertListPageAsync =
+ AlertListPageAsync(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: AlertListPageAsync) {
@@ -232,4 +154,17 @@ private constructor(
return forEach(values::add, executor).thenApply { values }
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AlertListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "AlertListPageAsync{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt
new file mode 100644
index 00000000..76540e99
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/AlertListPageResponse.kt
@@ -0,0 +1,231 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.withorb.api.models
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.withorb.api.core.ExcludeMissing
+import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
+import com.withorb.api.core.JsonValue
+import com.withorb.api.core.checkKnown
+import com.withorb.api.core.checkRequired
+import com.withorb.api.core.toImmutable
+import com.withorb.api.errors.OrbInvalidDataException
+import java.util.Collections
+import java.util.Objects
+import kotlin.jvm.optionals.getOrNull
+
+class AlertListPageResponse
+private constructor(
+ private val data: JsonField>,
+ private val paginationMetadata: JsonField,
+ private val additionalProperties: MutableMap,
+) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(),
+ @JsonProperty("pagination_metadata")
+ @ExcludeMissing
+ paginationMetadata: JsonField = JsonMissing.of(),
+ ) : this(data, paginationMetadata, mutableMapOf())
+
+ /**
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
+ * missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun data(): List = data.getRequired("data")
+
+ /**
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
+ * missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun paginationMetadata(): PaginationMetadata =
+ paginationMetadata.getRequired("pagination_metadata")
+
+ /**
+ * Returns the raw JSON value of [data].
+ *
+ * Unlike [data], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data
+
+ /**
+ * Returns the raw JSON value of [paginationMetadata].
+ *
+ * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("pagination_metadata")
+ @ExcludeMissing
+ fun _paginationMetadata(): JsonField = paginationMetadata
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [AlertListPageResponse].
+ *
+ * The following fields are required:
+ * ```java
+ * .data()
+ * .paginationMetadata()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [AlertListPageResponse]. */
+ class Builder internal constructor() {
+
+ private var data: JsonField>? = null
+ private var paginationMetadata: JsonField? = null
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(alertListPageResponse: AlertListPageResponse) = apply {
+ data = alertListPageResponse.data.map { it.toMutableList() }
+ paginationMetadata = alertListPageResponse.paginationMetadata
+ additionalProperties = alertListPageResponse.additionalProperties.toMutableMap()
+ }
+
+ fun data(data: List) = data(JsonField.of(data))
+
+ /**
+ * Sets [Builder.data] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.data] with a well-typed `List` value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun data(data: JsonField>) = apply {
+ this.data = data.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [Alert] to [Builder.data].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addData(data: Alert) = apply {
+ this.data =
+ (this.data ?: JsonField.of(mutableListOf())).also {
+ checkKnown("data", it).add(data)
+ }
+ }
+
+ fun paginationMetadata(paginationMetadata: PaginationMetadata) =
+ paginationMetadata(JsonField.of(paginationMetadata))
+
+ /**
+ * Sets [Builder.paginationMetadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.paginationMetadata] with a well-typed
+ * [PaginationMetadata] value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun paginationMetadata(paginationMetadata: JsonField) = apply {
+ this.paginationMetadata = paginationMetadata
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [AlertListPageResponse].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .data()
+ * .paginationMetadata()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): AlertListPageResponse =
+ AlertListPageResponse(
+ checkRequired("data", data).map { it.toImmutable() },
+ checkRequired("paginationMetadata", paginationMetadata),
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): AlertListPageResponse = apply {
+ if (validated) {
+ return@apply
+ }
+
+ data().forEach { it.validate() }
+ paginationMetadata().validate()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OrbInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0)
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is AlertListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "AlertListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt
index 60451764..8fd79bed 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPage.kt
@@ -2,63 +2,40 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.blocking.CouponService
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.stream.Stream
import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/**
- * This endpoint returns a list of all coupons for an account in a list format.
- *
- * The list of coupons is ordered starting from the most recently created coupon. The response also
- * includes `pagination_metadata`, which lets the caller retrieve the next page of results if they
- * exist. More information about pagination can be found in the Pagination-metadata schema.
- */
+/** @see [CouponService.list] */
class CouponListPage
private constructor(
- private val couponsService: CouponService,
+ private val service: CouponService,
private val params: CouponListParams,
- private val response: Response,
+ private val response: CouponListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CouponListPage && couponsService == other.couponsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponsService, params, response) /* spotless:on */
-
- override fun toString() =
- "CouponListPage{couponsService=$couponsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [CouponListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CouponListPageResponse.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [CouponListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CouponListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -66,138 +43,86 @@ private constructor(
}
return Optional.of(
- CouponListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): Optional {
- return getNextPageParams().map { couponsService.list(it) }
- }
+ fun getNextPage(): Optional = getNextPageParams().map { service.list(it) }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(couponsService: CouponService, params: CouponListParams, response: Response) =
- CouponListPage(couponsService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
+ /** The parameters that were used to request this page. */
+ fun params(): CouponListParams = params
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
+ /** The response that this page was parsed from. */
+ fun response(): CouponListPageResponse = response
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
+ fun toBuilder() = Builder().from(this)
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
-
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
-
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
-
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [CouponListPage].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [CouponListPage]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: CouponService? = null
+ private var params: CouponListParams? = null
+ private var response: CouponListPageResponse? = null
- /** Returns a mutable builder for constructing an instance of [CouponListPage]. */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(couponListPage: CouponListPage) = apply {
+ service = couponListPage.service
+ params = couponListPage.params
+ response = couponListPage.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: CouponService) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: CouponListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: CouponListPageResponse) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [CouponListPage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CouponListPage =
+ CouponListPage(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CouponListPage) : Iterable {
@@ -218,4 +143,16 @@ private constructor(
return StreamSupport.stream(spliterator(), false)
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CouponListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() = "CouponListPage{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt
index 7f1baec1..6486b6da 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageAsync.kt
@@ -2,17 +2,8 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.async.CouponServiceAsync
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.concurrent.CompletableFuture
@@ -20,46 +11,32 @@ import java.util.concurrent.Executor
import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/**
- * This endpoint returns a list of all coupons for an account in a list format.
- *
- * The list of coupons is ordered starting from the most recently created coupon. The response also
- * includes `pagination_metadata`, which lets the caller retrieve the next page of results if they
- * exist. More information about pagination can be found in the Pagination-metadata schema.
- */
+/** @see [CouponServiceAsync.list] */
class CouponListPageAsync
private constructor(
- private val couponsService: CouponServiceAsync,
+ private val service: CouponServiceAsync,
private val params: CouponListParams,
- private val response: Response,
+ private val response: CouponListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CouponListPageAsync && couponsService == other.couponsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(couponsService, params, response) /* spotless:on */
-
- override fun toString() =
- "CouponListPageAsync{couponsService=$couponsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [CouponListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CouponListPageResponse.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [CouponListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CouponListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -67,140 +44,89 @@ private constructor(
}
return Optional.of(
- CouponListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): CompletableFuture> {
- return getNextPageParams()
- .map { couponsService.list(it).thenApply { Optional.of(it) } }
+ fun getNextPage(): CompletableFuture> =
+ getNextPageParams()
+ .map { service.list(it).thenApply { Optional.of(it) } }
.orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
- }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(couponsService: CouponServiceAsync, params: CouponListParams, response: Response) =
- CouponListPageAsync(couponsService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
-
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
-
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
+ /** The parameters that were used to request this page. */
+ fun params(): CouponListParams = params
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
+ /** The response that this page was parsed from. */
+ fun response(): CouponListPageResponse = response
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
+ fun toBuilder() = Builder().from(this)
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [CouponListPageAsync].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [CouponListPageAsync]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: CouponServiceAsync? = null
+ private var params: CouponListParams? = null
+ private var response: CouponListPageResponse? = null
- /** Returns a mutable builder for constructing an instance of [CouponListPageAsync]. */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(couponListPageAsync: CouponListPageAsync) = apply {
+ service = couponListPageAsync.service
+ params = couponListPageAsync.params
+ response = couponListPageAsync.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: CouponServiceAsync) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: CouponListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: CouponListPageResponse) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [CouponListPageAsync].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CouponListPageAsync =
+ CouponListPageAsync(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CouponListPageAsync) {
@@ -228,4 +154,17 @@ private constructor(
return forEach(values::add, executor).thenApply { values }
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CouponListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "CouponListPageAsync{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt
new file mode 100644
index 00000000..77a5bcc3
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponListPageResponse.kt
@@ -0,0 +1,231 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.withorb.api.models
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.withorb.api.core.ExcludeMissing
+import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
+import com.withorb.api.core.JsonValue
+import com.withorb.api.core.checkKnown
+import com.withorb.api.core.checkRequired
+import com.withorb.api.core.toImmutable
+import com.withorb.api.errors.OrbInvalidDataException
+import java.util.Collections
+import java.util.Objects
+import kotlin.jvm.optionals.getOrNull
+
+class CouponListPageResponse
+private constructor(
+ private val data: JsonField>,
+ private val paginationMetadata: JsonField,
+ private val additionalProperties: MutableMap,
+) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(),
+ @JsonProperty("pagination_metadata")
+ @ExcludeMissing
+ paginationMetadata: JsonField = JsonMissing.of(),
+ ) : this(data, paginationMetadata, mutableMapOf())
+
+ /**
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
+ * missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun data(): List = data.getRequired("data")
+
+ /**
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
+ * missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun paginationMetadata(): PaginationMetadata =
+ paginationMetadata.getRequired("pagination_metadata")
+
+ /**
+ * Returns the raw JSON value of [data].
+ *
+ * Unlike [data], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data
+
+ /**
+ * Returns the raw JSON value of [paginationMetadata].
+ *
+ * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("pagination_metadata")
+ @ExcludeMissing
+ fun _paginationMetadata(): JsonField = paginationMetadata
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [CouponListPageResponse].
+ *
+ * The following fields are required:
+ * ```java
+ * .data()
+ * .paginationMetadata()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [CouponListPageResponse]. */
+ class Builder internal constructor() {
+
+ private var data: JsonField>? = null
+ private var paginationMetadata: JsonField? = null
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(couponListPageResponse: CouponListPageResponse) = apply {
+ data = couponListPageResponse.data.map { it.toMutableList() }
+ paginationMetadata = couponListPageResponse.paginationMetadata
+ additionalProperties = couponListPageResponse.additionalProperties.toMutableMap()
+ }
+
+ fun data(data: List) = data(JsonField.of(data))
+
+ /**
+ * Sets [Builder.data] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.data] with a well-typed `List` value instead.
+ * This method is primarily for setting the field to an undocumented or not yet supported
+ * value.
+ */
+ fun data(data: JsonField>) = apply {
+ this.data = data.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [Coupon] to [Builder.data].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addData(data: Coupon) = apply {
+ this.data =
+ (this.data ?: JsonField.of(mutableListOf())).also {
+ checkKnown("data", it).add(data)
+ }
+ }
+
+ fun paginationMetadata(paginationMetadata: PaginationMetadata) =
+ paginationMetadata(JsonField.of(paginationMetadata))
+
+ /**
+ * Sets [Builder.paginationMetadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.paginationMetadata] with a well-typed
+ * [PaginationMetadata] value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun paginationMetadata(paginationMetadata: JsonField) = apply {
+ this.paginationMetadata = paginationMetadata
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [CouponListPageResponse].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .data()
+ * .paginationMetadata()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CouponListPageResponse =
+ CouponListPageResponse(
+ checkRequired("data", data).map { it.toImmutable() },
+ checkRequired("paginationMetadata", paginationMetadata),
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): CouponListPageResponse = apply {
+ if (validated) {
+ return@apply
+ }
+
+ data().forEach { it.validate() }
+ paginationMetadata().validate()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OrbInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0)
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CouponListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "CouponListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt
index b2595f7d..77f17471 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPage.kt
@@ -2,62 +2,40 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.blocking.coupons.SubscriptionService
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.stream.Stream
import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/**
- * This endpoint returns a list of all subscriptions that have redeemed a given coupon as a
- * [paginated](/api-reference/pagination) list, ordered starting from the most recently created
- * subscription. For a full discussion of the subscription resource, see
- * [Subscription](/core-concepts#subscription).
- */
+/** @see [SubscriptionService.list] */
class CouponSubscriptionListPage
private constructor(
- private val subscriptionsService: SubscriptionService,
+ private val service: SubscriptionService,
private val params: CouponSubscriptionListParams,
- private val response: Response,
+ private val response: Subscriptions,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CouponSubscriptionListPage && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */
-
- override fun toString() =
- "CouponSubscriptionListPage{subscriptionsService=$subscriptionsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [Subscriptions], but gracefully handles missing data.
+ *
+ * @see [Subscriptions.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [Subscriptions], but gracefully handles missing data.
+ *
+ * @see [Subscriptions.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -65,144 +43,87 @@ private constructor(
}
return Optional.of(
- CouponSubscriptionListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): Optional {
- return getNextPageParams().map { subscriptionsService.list(it) }
- }
+ fun getNextPage(): Optional =
+ getNextPageParams().map { service.list(it) }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(
- subscriptionsService: SubscriptionService,
- params: CouponSubscriptionListParams,
- response: Response,
- ) = CouponSubscriptionListPage(subscriptionsService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
+ /** The parameters that were used to request this page. */
+ fun params(): CouponSubscriptionListParams = params
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
+ /** The response that this page was parsed from. */
+ fun response(): Subscriptions = response
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
+ fun toBuilder() = Builder().from(this)
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
-
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
-
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
-
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [CouponSubscriptionListPage].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [CouponSubscriptionListPage]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: SubscriptionService? = null
+ private var params: CouponSubscriptionListParams? = null
+ private var response: Subscriptions? = null
- /**
- * Returns a mutable builder for constructing an instance of
- * [CouponSubscriptionListPage].
- */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(couponSubscriptionListPage: CouponSubscriptionListPage) = apply {
+ service = couponSubscriptionListPage.service
+ params = couponSubscriptionListPage.params
+ response = couponSubscriptionListPage.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: SubscriptionService) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: CouponSubscriptionListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: Subscriptions) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [CouponSubscriptionListPage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CouponSubscriptionListPage =
+ CouponSubscriptionListPage(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CouponSubscriptionListPage) : Iterable {
@@ -223,4 +144,17 @@ private constructor(
return StreamSupport.stream(spliterator(), false)
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CouponSubscriptionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "CouponSubscriptionListPage{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt
index 86a187d6..47417e21 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CouponSubscriptionListPageAsync.kt
@@ -2,17 +2,8 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.async.coupons.SubscriptionServiceAsync
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.concurrent.CompletableFuture
@@ -20,45 +11,32 @@ import java.util.concurrent.Executor
import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/**
- * This endpoint returns a list of all subscriptions that have redeemed a given coupon as a
- * [paginated](/api-reference/pagination) list, ordered starting from the most recently created
- * subscription. For a full discussion of the subscription resource, see
- * [Subscription](/core-concepts#subscription).
- */
+/** @see [SubscriptionServiceAsync.list] */
class CouponSubscriptionListPageAsync
private constructor(
- private val subscriptionsService: SubscriptionServiceAsync,
+ private val service: SubscriptionServiceAsync,
private val params: CouponSubscriptionListParams,
- private val response: Response,
+ private val response: Subscriptions,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CouponSubscriptionListPageAsync && subscriptionsService == other.subscriptionsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(subscriptionsService, params, response) /* spotless:on */
-
- override fun toString() =
- "CouponSubscriptionListPageAsync{subscriptionsService=$subscriptionsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [Subscriptions], but gracefully handles missing data.
+ *
+ * @see [Subscriptions.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [Subscriptions], but gracefully handles missing data.
+ *
+ * @see [Subscriptions.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -66,146 +44,91 @@ private constructor(
}
return Optional.of(
- CouponSubscriptionListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): CompletableFuture> {
- return getNextPageParams()
- .map { subscriptionsService.list(it).thenApply { Optional.of(it) } }
+ fun getNextPage(): CompletableFuture> =
+ getNextPageParams()
+ .map { service.list(it).thenApply { Optional.of(it) } }
.orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
- }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(
- subscriptionsService: SubscriptionServiceAsync,
- params: CouponSubscriptionListParams,
- response: Response,
- ) = CouponSubscriptionListPageAsync(subscriptionsService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
-
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
-
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
-
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
-
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
-
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
+ /** The parameters that were used to request this page. */
+ fun params(): CouponSubscriptionListParams = params
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
-
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
-
- companion object {
+ /** The response that this page was parsed from. */
+ fun response(): Subscriptions = response
- /**
- * Returns a mutable builder for constructing an instance of
- * [CouponSubscriptionListPageAsync].
- */
- @JvmStatic fun builder() = Builder()
- }
-
- class Builder {
+ fun toBuilder() = Builder().from(this)
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
+ companion object {
- fun data(data: JsonField>) = apply { this.data = data }
+ /**
+ * Returns a mutable builder for constructing an instance of
+ * [CouponSubscriptionListPageAsync].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
+ /** A builder for [CouponSubscriptionListPageAsync]. */
+ class Builder internal constructor() {
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
+ private var service: SubscriptionServiceAsync? = null
+ private var params: CouponSubscriptionListParams? = null
+ private var response: Subscriptions? = null
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
+ @JvmSynthetic
+ internal fun from(couponSubscriptionListPageAsync: CouponSubscriptionListPageAsync) =
+ apply {
+ service = couponSubscriptionListPageAsync.service
+ params = couponSubscriptionListPageAsync.params
+ response = couponSubscriptionListPageAsync.response
}
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: SubscriptionServiceAsync) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: CouponSubscriptionListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: Subscriptions) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [CouponSubscriptionListPageAsync].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CouponSubscriptionListPageAsync =
+ CouponSubscriptionListPageAsync(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CouponSubscriptionListPageAsync) {
@@ -233,4 +156,17 @@ private constructor(
return forEach(values::add, executor).thenApply { values }
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CouponSubscriptionListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "CouponSubscriptionListPageAsync{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt
index 7a20c009..cbbd4f40 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPage.kt
@@ -2,61 +2,40 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.blocking.CreditNoteService
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.stream.Stream
import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/**
- * Get a paginated list of CreditNotes. Users can also filter by customer_id, subscription_id, or
- * external_customer_id. The credit notes will be returned in reverse chronological order by
- * `creation_time`.
- */
+/** @see [CreditNoteService.list] */
class CreditNoteListPage
private constructor(
- private val creditNotesService: CreditNoteService,
+ private val service: CreditNoteService,
private val params: CreditNoteListParams,
- private val response: Response,
+ private val response: CreditNoteListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CreditNoteListPage && creditNotesService == other.creditNotesService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditNotesService, params, response) /* spotless:on */
-
- override fun toString() =
- "CreditNoteListPage{creditNotesService=$creditNotesService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CreditNoteListPageResponse.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CreditNoteListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -64,141 +43,86 @@ private constructor(
}
return Optional.of(
- CreditNoteListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): Optional {
- return getNextPageParams().map { creditNotesService.list(it) }
- }
+ fun getNextPage(): Optional = getNextPageParams().map { service.list(it) }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(
- creditNotesService: CreditNoteService,
- params: CreditNoteListParams,
- response: Response,
- ) = CreditNoteListPage(creditNotesService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
+ /** The parameters that were used to request this page. */
+ fun params(): CreditNoteListParams = params
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
+ /** The response that this page was parsed from. */
+ fun response(): CreditNoteListPageResponse = response
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
+ fun toBuilder() = Builder().from(this)
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
-
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
-
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
-
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [CreditNoteListPage].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [CreditNoteListPage]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: CreditNoteService? = null
+ private var params: CreditNoteListParams? = null
+ private var response: CreditNoteListPageResponse? = null
- /** Returns a mutable builder for constructing an instance of [CreditNoteListPage]. */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(creditNoteListPage: CreditNoteListPage) = apply {
+ service = creditNoteListPage.service
+ params = creditNoteListPage.params
+ response = creditNoteListPage.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: CreditNoteService) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: CreditNoteListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: CreditNoteListPageResponse) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [CreditNoteListPage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CreditNoteListPage =
+ CreditNoteListPage(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CreditNoteListPage) : Iterable {
@@ -219,4 +143,17 @@ private constructor(
return StreamSupport.stream(spliterator(), false)
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CreditNoteListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "CreditNoteListPage{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt
index fe23817a..104920cc 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageAsync.kt
@@ -2,17 +2,8 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.async.CreditNoteServiceAsync
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.concurrent.CompletableFuture
@@ -20,44 +11,32 @@ import java.util.concurrent.Executor
import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/**
- * Get a paginated list of CreditNotes. Users can also filter by customer_id, subscription_id, or
- * external_customer_id. The credit notes will be returned in reverse chronological order by
- * `creation_time`.
- */
+/** @see [CreditNoteServiceAsync.list] */
class CreditNoteListPageAsync
private constructor(
- private val creditNotesService: CreditNoteServiceAsync,
+ private val service: CreditNoteServiceAsync,
private val params: CreditNoteListParams,
- private val response: Response,
+ private val response: CreditNoteListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CreditNoteListPageAsync && creditNotesService == other.creditNotesService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(creditNotesService, params, response) /* spotless:on */
-
- override fun toString() =
- "CreditNoteListPageAsync{creditNotesService=$creditNotesService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CreditNoteListPageResponse.data]
+ */
+ fun data(): List = response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [CreditNoteListPageResponse], but gracefully handles missing data.
+ *
+ * @see [CreditNoteListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -65,145 +44,89 @@ private constructor(
}
return Optional.of(
- CreditNoteListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): CompletableFuture> {
- return getNextPageParams()
- .map { creditNotesService.list(it).thenApply { Optional.of(it) } }
+ fun getNextPage(): CompletableFuture> =
+ getNextPageParams()
+ .map { service.list(it).thenApply { Optional.of(it) } }
.orElseGet { CompletableFuture.completedFuture(Optional.empty()) }
- }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
-
- @JvmStatic
- fun of(
- creditNotesService: CreditNoteServiceAsync,
- params: CreditNoteListParams,
- response: Response,
- ) = CreditNoteListPageAsync(creditNotesService, params, response)
- }
-
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data") data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List = data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
-
- @JsonProperty("data")
- fun _data(): Optional>> = Optional.ofNullable(data)
-
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
-
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
+ /** The parameters that were used to request this page. */
+ fun params(): CreditNoteListParams = params
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
-
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
+ /** The response that this page was parsed from. */
+ fun response(): CreditNoteListPageResponse = response
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
+ fun toBuilder() = Builder().from(this)
- fun toBuilder() = Builder().from(this)
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
+ companion object {
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
+ /**
+ * Returns a mutable builder for constructing an instance of [CreditNoteListPageAsync].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ /** A builder for [CreditNoteListPageAsync]. */
+ class Builder internal constructor() {
- companion object {
+ private var service: CreditNoteServiceAsync? = null
+ private var params: CreditNoteListParams? = null
+ private var response: CreditNoteListPageResponse? = null
- /**
- * Returns a mutable builder for constructing an instance of [CreditNoteListPageAsync].
- */
- @JvmStatic fun builder() = Builder()
+ @JvmSynthetic
+ internal fun from(creditNoteListPageAsync: CreditNoteListPageAsync) = apply {
+ service = creditNoteListPageAsync.service
+ params = creditNoteListPageAsync.params
+ response = creditNoteListPageAsync.response
}
- class Builder {
-
- private var data: JsonField> = JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply { this.data = data }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ fun service(service: CreditNoteServiceAsync) = apply { this.service = service }
+
+ /** The parameters that were used to request this page. */
+ fun params(params: CreditNoteListParams) = apply { this.params = params }
+
+ /** The response that this page was parsed from. */
+ fun response(response: CreditNoteListPageResponse) = apply { this.response = response }
+
+ /**
+ * Returns an immutable instance of [CreditNoteListPageAsync].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CreditNoteListPageAsync =
+ CreditNoteListPageAsync(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CreditNoteListPageAsync) {
@@ -231,4 +154,17 @@ private constructor(
return forEach(values::add, executor).thenApply { values }
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CreditNoteListPageAsync && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "CreditNoteListPageAsync{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt
new file mode 100644
index 00000000..c9e73d4b
--- /dev/null
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CreditNoteListPageResponse.kt
@@ -0,0 +1,231 @@
+// File generated from our OpenAPI spec by Stainless.
+
+package com.withorb.api.models
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.annotation.JsonAnySetter
+import com.fasterxml.jackson.annotation.JsonCreator
+import com.fasterxml.jackson.annotation.JsonProperty
+import com.withorb.api.core.ExcludeMissing
+import com.withorb.api.core.JsonField
+import com.withorb.api.core.JsonMissing
+import com.withorb.api.core.JsonValue
+import com.withorb.api.core.checkKnown
+import com.withorb.api.core.checkRequired
+import com.withorb.api.core.toImmutable
+import com.withorb.api.errors.OrbInvalidDataException
+import java.util.Collections
+import java.util.Objects
+import kotlin.jvm.optionals.getOrNull
+
+class CreditNoteListPageResponse
+private constructor(
+ private val data: JsonField>,
+ private val paginationMetadata: JsonField,
+ private val additionalProperties: MutableMap,
+) {
+
+ @JsonCreator
+ private constructor(
+ @JsonProperty("data") @ExcludeMissing data: JsonField> = JsonMissing.of(),
+ @JsonProperty("pagination_metadata")
+ @ExcludeMissing
+ paginationMetadata: JsonField = JsonMissing.of(),
+ ) : this(data, paginationMetadata, mutableMapOf())
+
+ /**
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
+ * missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun data(): List = data.getRequired("data")
+
+ /**
+ * @throws OrbInvalidDataException if the JSON field has an unexpected type or is unexpectedly
+ * missing or null (e.g. if the server responded with an unexpected value).
+ */
+ fun paginationMetadata(): PaginationMetadata =
+ paginationMetadata.getRequired("pagination_metadata")
+
+ /**
+ * Returns the raw JSON value of [data].
+ *
+ * Unlike [data], this method doesn't throw if the JSON field has an unexpected type.
+ */
+ @JsonProperty("data") @ExcludeMissing fun _data(): JsonField> = data
+
+ /**
+ * Returns the raw JSON value of [paginationMetadata].
+ *
+ * Unlike [paginationMetadata], this method doesn't throw if the JSON field has an unexpected
+ * type.
+ */
+ @JsonProperty("pagination_metadata")
+ @ExcludeMissing
+ fun _paginationMetadata(): JsonField = paginationMetadata
+
+ @JsonAnySetter
+ private fun putAdditionalProperty(key: String, value: JsonValue) {
+ additionalProperties.put(key, value)
+ }
+
+ @JsonAnyGetter
+ @ExcludeMissing
+ fun _additionalProperties(): Map =
+ Collections.unmodifiableMap(additionalProperties)
+
+ fun toBuilder() = Builder().from(this)
+
+ companion object {
+
+ /**
+ * Returns a mutable builder for constructing an instance of [CreditNoteListPageResponse].
+ *
+ * The following fields are required:
+ * ```java
+ * .data()
+ * .paginationMetadata()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
+
+ /** A builder for [CreditNoteListPageResponse]. */
+ class Builder internal constructor() {
+
+ private var data: JsonField>? = null
+ private var paginationMetadata: JsonField? = null
+ private var additionalProperties: MutableMap = mutableMapOf()
+
+ @JvmSynthetic
+ internal fun from(creditNoteListPageResponse: CreditNoteListPageResponse) = apply {
+ data = creditNoteListPageResponse.data.map { it.toMutableList() }
+ paginationMetadata = creditNoteListPageResponse.paginationMetadata
+ additionalProperties = creditNoteListPageResponse.additionalProperties.toMutableMap()
+ }
+
+ fun data(data: List) = data(JsonField.of(data))
+
+ /**
+ * Sets [Builder.data] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.data] with a well-typed `List` value
+ * instead. This method is primarily for setting the field to an undocumented or not yet
+ * supported value.
+ */
+ fun data(data: JsonField>) = apply {
+ this.data = data.map { it.toMutableList() }
+ }
+
+ /**
+ * Adds a single [CreditNote] to [Builder.data].
+ *
+ * @throws IllegalStateException if the field was previously set to a non-list.
+ */
+ fun addData(data: CreditNote) = apply {
+ this.data =
+ (this.data ?: JsonField.of(mutableListOf())).also {
+ checkKnown("data", it).add(data)
+ }
+ }
+
+ fun paginationMetadata(paginationMetadata: PaginationMetadata) =
+ paginationMetadata(JsonField.of(paginationMetadata))
+
+ /**
+ * Sets [Builder.paginationMetadata] to an arbitrary JSON value.
+ *
+ * You should usually call [Builder.paginationMetadata] with a well-typed
+ * [PaginationMetadata] value instead. This method is primarily for setting the field to an
+ * undocumented or not yet supported value.
+ */
+ fun paginationMetadata(paginationMetadata: JsonField) = apply {
+ this.paginationMetadata = paginationMetadata
+ }
+
+ fun additionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.clear()
+ putAllAdditionalProperties(additionalProperties)
+ }
+
+ fun putAdditionalProperty(key: String, value: JsonValue) = apply {
+ additionalProperties.put(key, value)
+ }
+
+ fun putAllAdditionalProperties(additionalProperties: Map) = apply {
+ this.additionalProperties.putAll(additionalProperties)
+ }
+
+ fun removeAdditionalProperty(key: String) = apply { additionalProperties.remove(key) }
+
+ fun removeAllAdditionalProperties(keys: Set) = apply {
+ keys.forEach(::removeAdditionalProperty)
+ }
+
+ /**
+ * Returns an immutable instance of [CreditNoteListPageResponse].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .data()
+ * .paginationMetadata()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CreditNoteListPageResponse =
+ CreditNoteListPageResponse(
+ checkRequired("data", data).map { it.toImmutable() },
+ checkRequired("paginationMetadata", paginationMetadata),
+ additionalProperties.toMutableMap(),
+ )
+ }
+
+ private var validated: Boolean = false
+
+ fun validate(): CreditNoteListPageResponse = apply {
+ if (validated) {
+ return@apply
+ }
+
+ data().forEach { it.validate() }
+ paginationMetadata().validate()
+ validated = true
+ }
+
+ fun isValid(): Boolean =
+ try {
+ validate()
+ true
+ } catch (e: OrbInvalidDataException) {
+ false
+ }
+
+ /**
+ * Returns a score indicating how many valid values are contained in this object recursively.
+ *
+ * Used for best match union deserialization.
+ */
+ @JvmSynthetic
+ internal fun validity(): Int =
+ (data.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) +
+ (paginationMetadata.asKnown().getOrNull()?.validity() ?: 0)
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CreditNoteListPageResponse && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
+ }
+
+ /* spotless:off */
+ private val hashCode: Int by lazy { Objects.hash(data, paginationMetadata, additionalProperties) }
+ /* spotless:on */
+
+ override fun hashCode(): Int = hashCode
+
+ override fun toString() =
+ "CreditNoteListPageResponse{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt
index 1885e264..a313acd6 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPage.kt
@@ -2,82 +2,43 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.blocking.customers.BalanceTransactionService
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.stream.Stream
import java.util.stream.StreamSupport
import kotlin.jvm.optionals.getOrNull
-/**
- * ## The customer balance
- *
- * The customer balance is an amount in the customer's currency, which Orb automatically applies to
- * subsequent invoices. This balance can be adjusted manually via Orb's webapp on the customer
- * details page. You can use this balance to provide a fixed mid-period credit to the customer.
- * Commonly, this is done due to system downtime/SLA violation, or an adhoc adjustment discussed
- * with the customer.
- *
- * If the balance is a positive value at the time of invoicing, it represents that the customer has
- * credit that should be used to offset the amount due on the next issued invoice. In this case, Orb
- * will automatically reduce the next invoice by the balance amount, and roll over any remaining
- * balance if the invoice is fully discounted.
- *
- * If the balance is a negative value at the time of invoicing, Orb will increase the invoice's
- * amount due with a positive adjustment, and reset the balance to 0.
- *
- * This endpoint retrieves all customer balance transactions in reverse chronological order for a
- * single customer, providing a complete audit trail of all adjustments and invoice applications.
- *
- * ## Eligibility
- *
- * The customer balance can only be applied to invoices or adjusted manually if invoices are not
- * synced to a separate invoicing provider. If a payment gateway such as Stripe is used, the balance
- * will be applied to the invoice before forwarding payment to the gateway.
- */
+/** @see [BalanceTransactionService.list] */
class CustomerBalanceTransactionListPage
private constructor(
- private val balanceTransactionsService: BalanceTransactionService,
+ private val service: BalanceTransactionService,
private val params: CustomerBalanceTransactionListParams,
- private val response: Response,
+ private val response: CustomerBalanceTransactionListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CustomerBalanceTransactionListPage && balanceTransactionsService == other.balanceTransactionsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(balanceTransactionsService, params, response) /* spotless:on */
-
- override fun toString() =
- "CustomerBalanceTransactionListPage{balanceTransactionsService=$balanceTransactionsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing
+ * data.
+ *
+ * @see [CustomerBalanceTransactionListPageResponse.data]
+ */
+ fun data(): List =
+ response._data().getOptional("data").getOrNull() ?: emptyList()
+
+ /**
+ * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing
+ * data.
+ *
+ * @see [CustomerBalanceTransactionListPageResponse.paginationMetadata]
+ */
+ fun paginationMetadata(): Optional =
+ response._paginationMetadata().getOptional("pagination_metadata")
+
+ fun hasNextPage(): Boolean =
+ data().isNotEmpty() &&
+ paginationMetadata().flatMap { it._nextCursor().getOptional("next_cursor") }.isPresent
fun getNextPageParams(): Optional {
if (!hasNextPage()) {
@@ -85,150 +46,91 @@ private constructor(
}
return Optional.of(
- CustomerBalanceTransactionListParams.builder()
- .from(params)
- .apply { paginationMetadata().nextCursor().ifPresent { this.cursor(it) } }
+ params
+ .toBuilder()
+ .apply {
+ paginationMetadata()
+ .flatMap { it._nextCursor().getOptional("next_cursor") }
+ .ifPresent { cursor(it) }
+ }
.build()
)
}
- fun getNextPage(): Optional {
- return getNextPageParams().map { balanceTransactionsService.list(it) }
- }
+ fun getNextPage(): Optional =
+ getNextPageParams().map { service.list(it) }
fun autoPager(): AutoPager = AutoPager(this)
- companion object {
+ /** The parameters that were used to request this page. */
+ fun params(): CustomerBalanceTransactionListParams = params
- @JvmStatic
- fun of(
- balanceTransactionsService: BalanceTransactionService,
- params: CustomerBalanceTransactionListParams,
- response: Response,
- ) = CustomerBalanceTransactionListPage(balanceTransactionsService, params, response)
- }
+ /** The response that this page was parsed from. */
+ fun response(): CustomerBalanceTransactionListPageResponse = response
- class Response(
- private val data: JsonField>,
- private val paginationMetadata: JsonField,
- private val additionalProperties: MutableMap,
- ) {
-
- @JsonCreator
- private constructor(
- @JsonProperty("data")
- data: JsonField> = JsonMissing.of(),
- @JsonProperty("pagination_metadata")
- paginationMetadata: JsonField = JsonMissing.of(),
- ) : this(data, paginationMetadata, mutableMapOf())
-
- fun data(): List =
- data.getOptional("data").getOrNull() ?: listOf()
-
- fun paginationMetadata(): PaginationMetadata =
- paginationMetadata.getRequired("pagination_metadata")
-
- @JsonProperty("data")
- fun _data(): Optional>> =
- Optional.ofNullable(data)
-
- @JsonProperty("pagination_metadata")
- fun _paginationMetadata(): Optional> =
- Optional.ofNullable(paginationMetadata)
-
- @JsonAnySetter
- private fun putAdditionalProperty(key: String, value: JsonValue) {
- additionalProperties.put(key, value)
- }
+ fun toBuilder() = Builder().from(this)
- @JsonAnyGetter
- @ExcludeMissing
- fun _additionalProperties(): Map =
- Collections.unmodifiableMap(additionalProperties)
-
- private var validated: Boolean = false
-
- fun validate(): Response = apply {
- if (validated) {
- return@apply
- }
+ companion object {
- data().map { it.validate() }
- paginationMetadata().validate()
- validated = true
- }
+ /**
+ * Returns a mutable builder for constructing an instance of
+ * [CustomerBalanceTransactionListPage].
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ */
+ @JvmStatic fun builder() = Builder()
+ }
- fun isValid(): Boolean =
- try {
- validate()
- true
- } catch (e: OrbInvalidDataException) {
- false
- }
+ /** A builder for [CustomerBalanceTransactionListPage]. */
+ class Builder internal constructor() {
- fun toBuilder() = Builder().from(this)
+ private var service: BalanceTransactionService? = null
+ private var params: CustomerBalanceTransactionListParams? = null
+ private var response: CustomerBalanceTransactionListPageResponse? = null
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
+ @JvmSynthetic
+ internal fun from(customerBalanceTransactionListPage: CustomerBalanceTransactionListPage) =
+ apply {
+ service = customerBalanceTransactionListPage.service
+ params = customerBalanceTransactionListPage.params
+ response = customerBalanceTransactionListPage.response
}
- return /* spotless:off */ other is Response && data == other.data && paginationMetadata == other.paginationMetadata && additionalProperties == other.additionalProperties /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(data, paginationMetadata, additionalProperties) /* spotless:on */
-
- override fun toString() =
- "Response{data=$data, paginationMetadata=$paginationMetadata, additionalProperties=$additionalProperties}"
+ fun service(service: BalanceTransactionService) = apply { this.service = service }
- companion object {
+ /** The parameters that were used to request this page. */
+ fun params(params: CustomerBalanceTransactionListParams) = apply { this.params = params }
- /**
- * Returns a mutable builder for constructing an instance of
- * [CustomerBalanceTransactionListPage].
- */
- @JvmStatic fun builder() = Builder()
+ /** The response that this page was parsed from. */
+ fun response(response: CustomerBalanceTransactionListPageResponse) = apply {
+ this.response = response
}
- class Builder {
-
- private var data: JsonField> =
- JsonMissing.of()
- private var paginationMetadata: JsonField = JsonMissing.of()
- private var additionalProperties: MutableMap = mutableMapOf()
-
- @JvmSynthetic
- internal fun from(page: Response) = apply {
- this.data = page.data
- this.paginationMetadata = page.paginationMetadata
- this.additionalProperties.putAll(page.additionalProperties)
- }
-
- fun data(data: List) = data(JsonField.of(data))
-
- fun data(data: JsonField>) = apply {
- this.data = data
- }
-
- fun paginationMetadata(paginationMetadata: PaginationMetadata) =
- paginationMetadata(JsonField.of(paginationMetadata))
-
- fun paginationMetadata(paginationMetadata: JsonField) = apply {
- this.paginationMetadata = paginationMetadata
- }
-
- fun putAdditionalProperty(key: String, value: JsonValue) = apply {
- this.additionalProperties.put(key, value)
- }
-
- /**
- * Returns an immutable instance of [Response].
- *
- * Further updates to this [Builder] will not mutate the returned instance.
- */
- fun build(): Response =
- Response(data, paginationMetadata, additionalProperties.toMutableMap())
- }
+ /**
+ * Returns an immutable instance of [CustomerBalanceTransactionListPage].
+ *
+ * Further updates to this [Builder] will not mutate the returned instance.
+ *
+ * The following fields are required:
+ * ```java
+ * .service()
+ * .params()
+ * .response()
+ * ```
+ *
+ * @throws IllegalStateException if any required field is unset.
+ */
+ fun build(): CustomerBalanceTransactionListPage =
+ CustomerBalanceTransactionListPage(
+ checkRequired("service", service),
+ checkRequired("params", params),
+ checkRequired("response", response),
+ )
}
class AutoPager(private val firstPage: CustomerBalanceTransactionListPage) :
@@ -250,4 +152,17 @@ private constructor(
return StreamSupport.stream(spliterator(), false)
}
}
+
+ override fun equals(other: Any?): Boolean {
+ if (this === other) {
+ return true
+ }
+
+ return /* spotless:off */ other is CustomerBalanceTransactionListPage && service == other.service && params == other.params && response == other.response /* spotless:on */
+ }
+
+ override fun hashCode(): Int = /* spotless:off */ Objects.hash(service, params, response) /* spotless:on */
+
+ override fun toString() =
+ "CustomerBalanceTransactionListPage{service=$service, params=$params, response=$response}"
}
diff --git a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt
index d25ae282..6214987f 100644
--- a/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt
+++ b/orb-java-core/src/main/kotlin/com/withorb/api/models/CustomerBalanceTransactionListPageAsync.kt
@@ -2,17 +2,8 @@
package com.withorb.api.models
-import com.fasterxml.jackson.annotation.JsonAnyGetter
-import com.fasterxml.jackson.annotation.JsonAnySetter
-import com.fasterxml.jackson.annotation.JsonCreator
-import com.fasterxml.jackson.annotation.JsonProperty
-import com.withorb.api.core.ExcludeMissing
-import com.withorb.api.core.JsonField
-import com.withorb.api.core.JsonMissing
-import com.withorb.api.core.JsonValue
-import com.withorb.api.errors.OrbInvalidDataException
+import com.withorb.api.core.checkRequired
import com.withorb.api.services.async.customers.BalanceTransactionServiceAsync
-import java.util.Collections
import java.util.Objects
import java.util.Optional
import java.util.concurrent.CompletableFuture
@@ -20,65 +11,35 @@ import java.util.concurrent.Executor
import java.util.function.Predicate
import kotlin.jvm.optionals.getOrNull
-/**
- * ## The customer balance
- *
- * The customer balance is an amount in the customer's currency, which Orb automatically applies to
- * subsequent invoices. This balance can be adjusted manually via Orb's webapp on the customer
- * details page. You can use this balance to provide a fixed mid-period credit to the customer.
- * Commonly, this is done due to system downtime/SLA violation, or an adhoc adjustment discussed
- * with the customer.
- *
- * If the balance is a positive value at the time of invoicing, it represents that the customer has
- * credit that should be used to offset the amount due on the next issued invoice. In this case, Orb
- * will automatically reduce the next invoice by the balance amount, and roll over any remaining
- * balance if the invoice is fully discounted.
- *
- * If the balance is a negative value at the time of invoicing, Orb will increase the invoice's
- * amount due with a positive adjustment, and reset the balance to 0.
- *
- * This endpoint retrieves all customer balance transactions in reverse chronological order for a
- * single customer, providing a complete audit trail of all adjustments and invoice applications.
- *
- * ## Eligibility
- *
- * The customer balance can only be applied to invoices or adjusted manually if invoices are not
- * synced to a separate invoicing provider. If a payment gateway such as Stripe is used, the balance
- * will be applied to the invoice before forwarding payment to the gateway.
- */
+/** @see [BalanceTransactionServiceAsync.list] */
class CustomerBalanceTransactionListPageAsync
private constructor(
- private val balanceTransactionsService: BalanceTransactionServiceAsync,
+ private val service: BalanceTransactionServiceAsync,
private val params: CustomerBalanceTransactionListParams,
- private val response: Response,
+ private val response: CustomerBalanceTransactionListPageResponse,
) {
- fun response(): Response = response
-
- fun data(): List = response().data()
-
- fun paginationMetadata(): PaginationMetadata = response().paginationMetadata()
-
- override fun equals(other: Any?): Boolean {
- if (this === other) {
- return true
- }
-
- return /* spotless:off */ other is CustomerBalanceTransactionListPageAsync && balanceTransactionsService == other.balanceTransactionsService && params == other.params && response == other.response /* spotless:on */
- }
-
- override fun hashCode(): Int = /* spotless:off */ Objects.hash(balanceTransactionsService, params, response) /* spotless:on */
-
- override fun toString() =
- "CustomerBalanceTransactionListPageAsync{balanceTransactionsService=$balanceTransactionsService, params=$params, response=$response}"
-
- fun hasNextPage(): Boolean {
- if (data().isEmpty()) {
- return false
- }
-
- return paginationMetadata().nextCursor().isPresent
- }
+ /**
+ * Delegates to [CustomerBalanceTransactionListPageResponse], but gracefully handles missing
+ * data.
+ *
+ * @see [CustomerBalanceTransactionListPageResponse.data]
+ */
+ fun data(): List