diff --git a/.stats.yml b/.stats.yml index 5fe5772a..ddcc51fc 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 158 +configured_endpoints: 167 diff --git a/build.gradle.kts b/build.gradle.kts index de8d3687..f501eab9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.courier" - version = "6.10.0" // x-release-please-version + version = "6.9.0" // x-release-please-version } subprojects { diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt index 9e4cafb9..c90d4f4e 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClient.kt @@ -16,6 +16,7 @@ import com.courier.services.blocking.JourneyService import com.courier.services.blocking.ListService import com.courier.services.blocking.MessageService import com.courier.services.blocking.NotificationService +import com.courier.services.blocking.PreviewService import com.courier.services.blocking.ProfileService import com.courier.services.blocking.ProviderService import com.courier.services.blocking.RequestService @@ -103,6 +104,12 @@ interface CourierClient { */ fun broadcasts(): BroadcastService + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + fun previews(): PreviewService + fun bulk(): BulkService /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ @@ -229,6 +236,12 @@ interface CourierClient { */ fun broadcasts(): BroadcastService.WithRawResponse + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + fun previews(): PreviewService.WithRawResponse + fun bulk(): BulkService.WithRawResponse /** diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt index 5ea8ada4..ad1eebab 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsync.kt @@ -16,6 +16,7 @@ import com.courier.services.async.JourneyServiceAsync import com.courier.services.async.ListServiceAsync import com.courier.services.async.MessageServiceAsync import com.courier.services.async.NotificationServiceAsync +import com.courier.services.async.PreviewServiceAsync import com.courier.services.async.ProfileServiceAsync import com.courier.services.async.ProviderServiceAsync import com.courier.services.async.RequestServiceAsync @@ -103,6 +104,12 @@ interface CourierClientAsync { */ fun broadcasts(): BroadcastServiceAsync + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + fun previews(): PreviewServiceAsync + fun bulk(): BulkServiceAsync /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ @@ -233,6 +240,12 @@ interface CourierClientAsync { */ fun broadcasts(): BroadcastServiceAsync.WithRawResponse + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + fun previews(): PreviewServiceAsync.WithRawResponse + fun bulk(): BulkServiceAsync.WithRawResponse /** diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt index 313fd842..747eba33 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientAsyncImpl.kt @@ -30,6 +30,8 @@ import com.courier.services.async.MessageServiceAsync import com.courier.services.async.MessageServiceAsyncImpl import com.courier.services.async.NotificationServiceAsync import com.courier.services.async.NotificationServiceAsyncImpl +import com.courier.services.async.PreviewServiceAsync +import com.courier.services.async.PreviewServiceAsyncImpl import com.courier.services.async.ProfileServiceAsync import com.courier.services.async.ProfileServiceAsyncImpl import com.courier.services.async.ProviderServiceAsync @@ -95,6 +97,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier BroadcastServiceAsyncImpl(clientOptionsWithUserAgent) } + private val previews: PreviewServiceAsync by lazy { + PreviewServiceAsyncImpl(clientOptionsWithUserAgent) + } + private val bulk: BulkServiceAsync by lazy { BulkServiceAsyncImpl(clientOptionsWithUserAgent) } private val brands: BrandServiceAsync by lazy { @@ -192,6 +198,12 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier */ override fun broadcasts(): BroadcastServiceAsync = broadcasts + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + override fun previews(): PreviewServiceAsync = previews + override fun bulk(): BulkServiceAsync = bulk /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ @@ -290,6 +302,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier BroadcastServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val previews: PreviewServiceAsync.WithRawResponse by lazy { + PreviewServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val bulk: BulkServiceAsync.WithRawResponse by lazy { BulkServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -395,6 +411,12 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier */ override fun broadcasts(): BroadcastServiceAsync.WithRawResponse = broadcasts + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + override fun previews(): PreviewServiceAsync.WithRawResponse = previews + override fun bulk(): BulkServiceAsync.WithRawResponse = bulk /** diff --git a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt index 67ebf6a8..cecbf259 100644 --- a/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/client/CourierClientImpl.kt @@ -30,6 +30,8 @@ import com.courier.services.blocking.MessageService import com.courier.services.blocking.MessageServiceImpl import com.courier.services.blocking.NotificationService import com.courier.services.blocking.NotificationServiceImpl +import com.courier.services.blocking.PreviewService +import com.courier.services.blocking.PreviewServiceImpl import com.courier.services.blocking.ProfileService import com.courier.services.blocking.ProfileServiceImpl import com.courier.services.blocking.ProviderService @@ -93,6 +95,8 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien BroadcastServiceImpl(clientOptionsWithUserAgent) } + private val previews: PreviewService by lazy { PreviewServiceImpl(clientOptionsWithUserAgent) } + private val bulk: BulkService by lazy { BulkServiceImpl(clientOptionsWithUserAgent) } private val brands: BrandService by lazy { BrandServiceImpl(clientOptionsWithUserAgent) } @@ -176,6 +180,12 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien */ override fun broadcasts(): BroadcastService = broadcasts + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + override fun previews(): PreviewService = previews + override fun bulk(): BulkService = bulk /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ @@ -274,6 +284,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien BroadcastServiceImpl.WithRawResponseImpl(clientOptions) } + private val previews: PreviewService.WithRawResponse by lazy { + PreviewServiceImpl.WithRawResponseImpl(clientOptions) + } + private val bulk: BulkService.WithRawResponse by lazy { BulkServiceImpl.WithRawResponseImpl(clientOptions) } @@ -379,6 +393,12 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien */ override fun broadcasts(): BroadcastService.WithRawResponse = broadcasts + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + override fun previews(): PreviewService.WithRawResponse = previews + override fun bulk(): BulkService.WithRawResponse = bulk /** diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/CreatePreviewRunRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/CreatePreviewRunRequest.kt new file mode 100644 index 00000000..6aab930f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/CreatePreviewRunRequest.kt @@ -0,0 +1,472 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Request body for creating a preview run of the template in the path. Provide exactly one of + * `device_set_id` or `device_ids`. The template is the path's `{id}`; a `template_id` here is an + * unknown key and a 400. + */ +class CreatePreviewRunRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val data: JsonField, + private val deviceIds: JsonField>, + private val deviceSetId: JsonField, + private val locale: JsonField, + private val templateVersion: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("data") @ExcludeMissing data: JsonField = JsonMissing.of(), + @JsonProperty("device_ids") + @ExcludeMissing + deviceIds: JsonField> = JsonMissing.of(), + @JsonProperty("device_set_id") + @ExcludeMissing + deviceSetId: JsonField = JsonMissing.of(), + @JsonProperty("locale") @ExcludeMissing locale: JsonField = JsonMissing.of(), + @JsonProperty("template_version") + @ExcludeMissing + templateVersion: JsonField = JsonMissing.of(), + ) : this(data, deviceIds, deviceSetId, locale, templateVersion, mutableMapOf()) + + /** + * Template variables to render with, the same shape as the `data` object on a send. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun data(): Optional = data.getOptional("data") + + /** + * The devices to render on, by `PreviewDevice.id`, for a one-off run. Mutually exclusive with + * `device_set_id`. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deviceIds(): Optional> = deviceIds.getOptional("device_ids") + + /** + * A saved device set naming the devices to render on. Mutually exclusive with `device_ids`. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun deviceSetId(): Optional = deviceSetId.getOptional("device_set_id") + + /** + * Render the template's content for this locale, e.g. "fr-FR". + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun locale(): Optional = locale.getOptional("locale") + + /** + * Which version of the template to render. Omit for the latest saved draft, which always exists + * and is what the editor shows. `published` renders the live version; a zero-padded `v002` + * renders that specific publish. Versions are 1-based, so `v000` is not a version, and the + * unpadded `v2` is rejected — that spelling belongs to journeys' AutomationVersionId, a + * different scheme in which `v0` means published. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun templateVersion(): Optional = templateVersion.getOptional("template_version") + + /** + * 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 [deviceIds]. + * + * Unlike [deviceIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_ids") + @ExcludeMissing + fun _deviceIds(): JsonField> = deviceIds + + /** + * Returns the raw JSON value of [deviceSetId]. + * + * Unlike [deviceSetId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_set_id") + @ExcludeMissing + fun _deviceSetId(): JsonField = deviceSetId + + /** + * Returns the raw JSON value of [locale]. + * + * Unlike [locale], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("locale") @ExcludeMissing fun _locale(): JsonField = locale + + /** + * Returns the raw JSON value of [templateVersion]. + * + * Unlike [templateVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_version") + @ExcludeMissing + fun _templateVersion(): JsonField = templateVersion + + @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 [CreatePreviewRunRequest]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreatePreviewRunRequest]. */ + class Builder internal constructor() { + + private var data: JsonField = JsonMissing.of() + private var deviceIds: JsonField>? = null + private var deviceSetId: JsonField = JsonMissing.of() + private var locale: JsonField = JsonMissing.of() + private var templateVersion: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createPreviewRunRequest: CreatePreviewRunRequest) = apply { + data = createPreviewRunRequest.data + deviceIds = createPreviewRunRequest.deviceIds.map { it.toMutableList() } + deviceSetId = createPreviewRunRequest.deviceSetId + locale = createPreviewRunRequest.locale + templateVersion = createPreviewRunRequest.templateVersion + additionalProperties = createPreviewRunRequest.additionalProperties.toMutableMap() + } + + /** Template variables to render with, the same shape as the `data` object on a send. */ + fun data(data: Data) = data(JsonField.of(data)) + + /** + * Sets [Builder.data] to an arbitrary JSON value. + * + * You should usually call [Builder.data] with a well-typed [Data] 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 } + + /** + * The devices to render on, by `PreviewDevice.id`, for a one-off run. Mutually exclusive + * with `device_set_id`. + */ + fun deviceIds(deviceIds: List) = deviceIds(JsonField.of(deviceIds)) + + /** + * Sets [Builder.deviceIds] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deviceIds(deviceIds: JsonField>) = apply { + this.deviceIds = deviceIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [deviceIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDeviceId(deviceId: String) = apply { + deviceIds = + (deviceIds ?: JsonField.of(mutableListOf())).also { + checkKnown("deviceIds", it).add(deviceId) + } + } + + /** + * A saved device set naming the devices to render on. Mutually exclusive with `device_ids`. + */ + fun deviceSetId(deviceSetId: String) = deviceSetId(JsonField.of(deviceSetId)) + + /** + * Sets [Builder.deviceSetId] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceSetId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun deviceSetId(deviceSetId: JsonField) = apply { this.deviceSetId = deviceSetId } + + /** Render the template's content for this locale, e.g. "fr-FR". */ + fun locale(locale: String) = locale(JsonField.of(locale)) + + /** + * Sets [Builder.locale] to an arbitrary JSON value. + * + * You should usually call [Builder.locale] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun locale(locale: JsonField) = apply { this.locale = locale } + + /** + * Which version of the template to render. Omit for the latest saved draft, which always + * exists and is what the editor shows. `published` renders the live version; a zero-padded + * `v002` renders that specific publish. Versions are 1-based, so `v000` is not a version, + * and the unpadded `v2` is rejected — that spelling belongs to journeys' + * AutomationVersionId, a different scheme in which `v0` means published. + */ + fun templateVersion(templateVersion: String) = + templateVersion(JsonField.of(templateVersion)) + + /** + * Sets [Builder.templateVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.templateVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun templateVersion(templateVersion: JsonField) = apply { + this.templateVersion = templateVersion + } + + 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 [CreatePreviewRunRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): CreatePreviewRunRequest = + CreatePreviewRunRequest( + data, + (deviceIds ?: JsonMissing.of()).map { it.toImmutable() }, + deviceSetId, + locale, + templateVersion, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CreatePreviewRunRequest = apply { + if (validated) { + return@apply + } + + data().ifPresent { it.validate() } + deviceIds() + deviceSetId() + locale() + templateVersion() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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()?.validity() ?: 0) + + (deviceIds.asKnown().getOrNull()?.size ?: 0) + + (if (deviceSetId.asKnown().isPresent) 1 else 0) + + (if (locale.asKnown().isPresent) 1 else 0) + + (if (templateVersion.asKnown().isPresent) 1 else 0) + + /** Template variables to render with, the same shape as the `data` object on a send. */ + class Data + @JsonCreator + private constructor( + @com.fasterxml.jackson.annotation.JsonValue + private val additionalProperties: Map + ) { + + @JsonAnyGetter + @ExcludeMissing + fun _additionalProperties(): Map = additionalProperties + + fun toBuilder() = Builder().from(this) + + companion object { + + /** Returns a mutable builder for constructing an instance of [Data]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Data]. */ + class Builder internal constructor() { + + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(data: Data) = apply { + additionalProperties = data.additionalProperties.toMutableMap() + } + + 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 [Data]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): Data = Data(additionalProperties.toImmutable()) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Data = apply { + if (validated) { + return@apply + } + + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + additionalProperties.count { (_, value) -> !value.isNull() && !value.isMissing() } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Data && additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = "Data{additionalProperties=$additionalProperties}" + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreatePreviewRunRequest && + data == other.data && + deviceIds == other.deviceIds && + deviceSetId == other.deviceSetId && + locale == other.locale && + templateVersion == other.templateVersion && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(data, deviceIds, deviceSetId, locale, templateVersion, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CreatePreviewRunRequest{data=$data, deviceIds=$deviceIds, deviceSetId=$deviceSetId, locale=$locale, templateVersion=$templateVersion, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResult.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResult.kt new file mode 100644 index 00000000..39740466 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResult.kt @@ -0,0 +1,393 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkRequired +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** One device's result within a preview run. */ +class PreviewResult +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val deviceId: JsonField, + private val screenshotUrl: JsonField, + private val status: JsonField, + private val thumbnailUrl: JsonField, + private val failureReason: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("device_id") @ExcludeMissing deviceId: JsonField = JsonMissing.of(), + @JsonProperty("screenshot_url") + @ExcludeMissing + screenshotUrl: JsonField = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("thumbnail_url") + @ExcludeMissing + thumbnailUrl: JsonField = JsonMissing.of(), + @JsonProperty("failure_reason") + @ExcludeMissing + failureReason: JsonField = JsonMissing.of(), + ) : this(deviceId, screenshotUrl, status, thumbnailUrl, failureReason, mutableMapOf()) + + /** + * The device this result is for, by `PreviewDevice.id`. + * + * @throws CourierInvalidDataException 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 deviceId(): String = deviceId.getRequired("device_id") + + /** + * Short-lived signed URL for the full-sized image. Null until the screenshot exists. Re-signed + * on every read, so fetch it rather than storing it. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun screenshotUrl(): Optional = screenshotUrl.getOptional("screenshot_url") + + /** + * One device's outcome. `COMPLETED` means the screenshot exists and its URLs are populated. + * `UNSUPPORTED`, `TIMED_OUT` and `FAILED` are all terminal, and none stands in for another — + * `UNSUPPORTED` means the device was retired at the vendor, `TIMED_OUT` means it did not report + * in time. + * + * @throws CourierInvalidDataException 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 status(): PreviewResultStatus = status.getRequired("status") + + /** + * Short-lived signed URL for the grid-sized image. Null until the screenshot exists. Re-signed + * on every read, so fetch it rather than storing it. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun thumbnailUrl(): Optional = thumbnailUrl.getOptional("thumbnail_url") + + /** + * Why one device's render failed, when its `status` is `FAILED` and the cause has a public + * name. `DELIVERY_FAILED` means the rendering service could not deliver the message to its own + * capture mailbox — infrastructure, not anything wrong with the template. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun failureReason(): Optional = + failureReason.getOptional("failure_reason") + + /** + * Returns the raw JSON value of [deviceId]. + * + * Unlike [deviceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_id") @ExcludeMissing fun _deviceId(): JsonField = deviceId + + /** + * Returns the raw JSON value of [screenshotUrl]. + * + * Unlike [screenshotUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("screenshot_url") + @ExcludeMissing + fun _screenshotUrl(): JsonField = screenshotUrl + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [thumbnailUrl]. + * + * Unlike [thumbnailUrl], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("thumbnail_url") + @ExcludeMissing + fun _thumbnailUrl(): JsonField = thumbnailUrl + + /** + * Returns the raw JSON value of [failureReason]. + * + * Unlike [failureReason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("failure_reason") + @ExcludeMissing + fun _failureReason(): JsonField = failureReason + + @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 [PreviewResult]. + * + * The following fields are required: + * ```java + * .deviceId() + * .screenshotUrl() + * .status() + * .thumbnailUrl() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewResult]. */ + class Builder internal constructor() { + + private var deviceId: JsonField? = null + private var screenshotUrl: JsonField? = null + private var status: JsonField? = null + private var thumbnailUrl: JsonField? = null + private var failureReason: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewResult: PreviewResult) = apply { + deviceId = previewResult.deviceId + screenshotUrl = previewResult.screenshotUrl + status = previewResult.status + thumbnailUrl = previewResult.thumbnailUrl + failureReason = previewResult.failureReason + additionalProperties = previewResult.additionalProperties.toMutableMap() + } + + /** The device this result is for, by `PreviewDevice.id`. */ + fun deviceId(deviceId: String) = deviceId(JsonField.of(deviceId)) + + /** + * Sets [Builder.deviceId] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun deviceId(deviceId: JsonField) = apply { this.deviceId = deviceId } + + /** + * Short-lived signed URL for the full-sized image. Null until the screenshot exists. + * Re-signed on every read, so fetch it rather than storing it. + */ + fun screenshotUrl(screenshotUrl: String?) = + screenshotUrl(JsonField.ofNullable(screenshotUrl)) + + /** Alias for calling [Builder.screenshotUrl] with `screenshotUrl.orElse(null)`. */ + fun screenshotUrl(screenshotUrl: Optional) = + screenshotUrl(screenshotUrl.getOrNull()) + + /** + * Sets [Builder.screenshotUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.screenshotUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun screenshotUrl(screenshotUrl: JsonField) = apply { + this.screenshotUrl = screenshotUrl + } + + /** + * One device's outcome. `COMPLETED` means the screenshot exists and its URLs are populated. + * `UNSUPPORTED`, `TIMED_OUT` and `FAILED` are all terminal, and none stands in for another + * — `UNSUPPORTED` means the device was retired at the vendor, `TIMED_OUT` means it did not + * report in time. + */ + fun status(status: PreviewResultStatus) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [PreviewResultStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** + * Short-lived signed URL for the grid-sized image. Null until the screenshot exists. + * Re-signed on every read, so fetch it rather than storing it. + */ + fun thumbnailUrl(thumbnailUrl: String?) = thumbnailUrl(JsonField.ofNullable(thumbnailUrl)) + + /** Alias for calling [Builder.thumbnailUrl] with `thumbnailUrl.orElse(null)`. */ + fun thumbnailUrl(thumbnailUrl: Optional) = thumbnailUrl(thumbnailUrl.getOrNull()) + + /** + * Sets [Builder.thumbnailUrl] to an arbitrary JSON value. + * + * You should usually call [Builder.thumbnailUrl] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun thumbnailUrl(thumbnailUrl: JsonField) = apply { + this.thumbnailUrl = thumbnailUrl + } + + /** + * Why one device's render failed, when its `status` is `FAILED` and the cause has a public + * name. `DELIVERY_FAILED` means the rendering service could not deliver the message to its + * own capture mailbox — infrastructure, not anything wrong with the template. + */ + fun failureReason(failureReason: PreviewResultFailureReason) = + failureReason(JsonField.of(failureReason)) + + /** + * Sets [Builder.failureReason] to an arbitrary JSON value. + * + * You should usually call [Builder.failureReason] with a well-typed + * [PreviewResultFailureReason] value instead. This method is primarily for setting the + * field to an undocumented or not yet supported value. + */ + fun failureReason(failureReason: JsonField) = apply { + this.failureReason = failureReason + } + + 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 [PreviewResult]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .deviceId() + * .screenshotUrl() + * .status() + * .thumbnailUrl() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewResult = + PreviewResult( + checkRequired("deviceId", deviceId), + checkRequired("screenshotUrl", screenshotUrl), + checkRequired("status", status), + checkRequired("thumbnailUrl", thumbnailUrl), + failureReason, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewResult = apply { + if (validated) { + return@apply + } + + deviceId() + screenshotUrl() + status().validate() + thumbnailUrl() + failureReason().ifPresent { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (if (deviceId.asKnown().isPresent) 1 else 0) + + (if (screenshotUrl.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (thumbnailUrl.asKnown().isPresent) 1 else 0) + + (failureReason.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewResult && + deviceId == other.deviceId && + screenshotUrl == other.screenshotUrl && + status == other.status && + thumbnailUrl == other.thumbnailUrl && + failureReason == other.failureReason && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + deviceId, + screenshotUrl, + status, + thumbnailUrl, + failureReason, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreviewResult{deviceId=$deviceId, screenshotUrl=$screenshotUrl, status=$status, thumbnailUrl=$thumbnailUrl, failureReason=$failureReason, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResultFailureReason.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResultFailureReason.kt new file mode 100644 index 00000000..d8dcff88 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResultFailureReason.kt @@ -0,0 +1,144 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +/** + * Why one device's render failed, when its `status` is `FAILED` and the cause has a public name. + * `DELIVERY_FAILED` means the rendering service could not deliver the message to its own capture + * mailbox — infrastructure, not anything wrong with the template. + */ +class PreviewResultFailureReason +@JsonCreator +private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't match + * any known member, and you want to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val DELIVERY_FAILED = of("DELIVERY_FAILED") + + @JvmStatic fun of(value: String) = PreviewResultFailureReason(JsonField.of(value)) + } + + /** An enum containing [PreviewResultFailureReason]'s known values. */ + enum class Known { + DELIVERY_FAILED + } + + /** + * An enum containing [PreviewResultFailureReason]'s known values, as well as an [_UNKNOWN] + * member. + * + * An instance of [PreviewResultFailureReason] can contain an unknown value in a couple of + * cases: + * - It was deserialized from data that doesn't match any known member. For example, if the SDK + * is on an older version than the API, then the API may respond with new members that the SDK + * is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + DELIVERY_FAILED, + /** + * An enum member indicating that [PreviewResultFailureReason] was instantiated with an + * unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if + * the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want to + * throw for the unknown case. + */ + fun value(): Value = + when (this) { + DELIVERY_FAILED -> Value.DELIVERY_FAILED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't want + * to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + DELIVERY_FAILED -> Known.DELIVERY_FAILED + else -> throw CourierInvalidDataException("Unknown PreviewResultFailureReason: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging and + * generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the expected + * primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewResultFailureReason = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewResultFailureReason && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResultStatus.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResultStatus.kt new file mode 100644 index 00000000..f960d4b2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewResultStatus.kt @@ -0,0 +1,172 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +/** + * One device's outcome. `COMPLETED` means the screenshot exists and its URLs are populated. + * `UNSUPPORTED`, `TIMED_OUT` and `FAILED` are all terminal, and none stands in for another — + * `UNSUPPORTED` means the device was retired at the vendor, `TIMED_OUT` means it did not report in + * time. + */ +class PreviewResultStatus @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't match + * any known member, and you want to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val PENDING = of("PENDING") + + @JvmField val PROCESSING = of("PROCESSING") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val UNSUPPORTED = of("UNSUPPORTED") + + @JvmField val TIMED_OUT = of("TIMED_OUT") + + @JvmField val FAILED = of("FAILED") + + @JvmStatic fun of(value: String) = PreviewResultStatus(JsonField.of(value)) + } + + /** An enum containing [PreviewResultStatus]'s known values. */ + enum class Known { + PENDING, + PROCESSING, + COMPLETED, + UNSUPPORTED, + TIMED_OUT, + FAILED, + } + + /** + * An enum containing [PreviewResultStatus]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PreviewResultStatus] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the SDK + * is on an older version than the API, then the API may respond with new members that the SDK + * is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + PENDING, + PROCESSING, + COMPLETED, + UNSUPPORTED, + TIMED_OUT, + FAILED, + /** + * An enum member indicating that [PreviewResultStatus] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if + * the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want to + * throw for the unknown case. + */ + fun value(): Value = + when (this) { + PENDING -> Value.PENDING + PROCESSING -> Value.PROCESSING + COMPLETED -> Value.COMPLETED + UNSUPPORTED -> Value.UNSUPPORTED + TIMED_OUT -> Value.TIMED_OUT + FAILED -> Value.FAILED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't want + * to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + PENDING -> Known.PENDING + PROCESSING -> Known.PROCESSING + COMPLETED -> Known.COMPLETED + UNSUPPORTED -> Known.UNSUPPORTED + TIMED_OUT -> Known.TIMED_OUT + FAILED -> Known.FAILED + else -> throw CourierInvalidDataException("Unknown PreviewResultStatus: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging and + * generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the expected + * primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewResultStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewResultStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRun.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRun.kt new file mode 100644 index 00000000..3d172e19 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRun.kt @@ -0,0 +1,482 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** One render of a template across a set of devices. Billable. */ +class PreviewRun +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val deviceIds: JsonField>, + private val status: JsonField, + private val templateId: JsonField, + private val failureReason: JsonField, + private val templateVersion: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("device_ids") + @ExcludeMissing + deviceIds: JsonField> = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("template_id") + @ExcludeMissing + templateId: JsonField = JsonMissing.of(), + @JsonProperty("failure_reason") + @ExcludeMissing + failureReason: JsonField = JsonMissing.of(), + @JsonProperty("template_version") + @ExcludeMissing + templateVersion: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + deviceIds, + status, + templateId, + failureReason, + templateVersion, + mutableMapOf(), + ) + + /** + * Unique identifier for the preview run. + * + * @throws CourierInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * ISO-8601 timestamp of when the run was created. + * + * @throws CourierInvalidDataException 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 createdAt(): String = createdAt.getRequired("created_at") + + /** + * The devices this run was submitted for, snapshotted when the run was created. + * + * @throws CourierInvalidDataException 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 deviceIds(): List = deviceIds.getRequired("device_ids") + + /** + * Where the run itself has got to. `PENDING` and `RENDERED` mean Courier is still preparing the + * email, `SUBMITTED` means it is with the rendering service, and `COMPLETED` means every device + * has reported. `FAILED` is the run as a whole failing — an individual device failing never + * fails the run. + * + * @throws CourierInvalidDataException 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 status(): PreviewRunStatus = status.getRequired("status") + + /** + * The template that was rendered. + * + * @throws CourierInvalidDataException 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 templateId(): String = templateId.getRequired("template_id") + + /** + * Why the run failed, when `status` is `FAILED`. `NO_EMAIL_CHANNEL` and + * `TEMPLATE_NOT_SUPPORTED` mean there was nothing to render; `ALL_DEVICES_UNSUPPORTED` means + * every requested device has been retired and the request can be fixed by choosing others. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun failureReason(): Optional = + failureReason.getOptional("failure_reason") + + /** + * The version of the template that was rendered — `draft`, or a zero-padded published version + * such as `v002`. Absent until the render settles. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun templateVersion(): Optional = templateVersion.getOptional("template_version") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [deviceIds]. + * + * Unlike [deviceIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_ids") + @ExcludeMissing + fun _deviceIds(): JsonField> = deviceIds + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [templateId]. + * + * Unlike [templateId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_id") @ExcludeMissing fun _templateId(): JsonField = templateId + + /** + * Returns the raw JSON value of [failureReason]. + * + * Unlike [failureReason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("failure_reason") + @ExcludeMissing + fun _failureReason(): JsonField = failureReason + + /** + * Returns the raw JSON value of [templateVersion]. + * + * Unlike [templateVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_version") + @ExcludeMissing + fun _templateVersion(): JsonField = templateVersion + + @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 [PreviewRun]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .deviceIds() + * .status() + * .templateId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewRun]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var deviceIds: JsonField>? = null + private var status: JsonField? = null + private var templateId: JsonField? = null + private var failureReason: JsonField = JsonMissing.of() + private var templateVersion: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewRun: PreviewRun) = apply { + id = previewRun.id + createdAt = previewRun.createdAt + deviceIds = previewRun.deviceIds.map { it.toMutableList() } + status = previewRun.status + templateId = previewRun.templateId + failureReason = previewRun.failureReason + templateVersion = previewRun.templateVersion + additionalProperties = previewRun.additionalProperties.toMutableMap() + } + + /** Unique identifier for the preview run. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ISO-8601 timestamp of when the run was created. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** The devices this run was submitted for, snapshotted when the run was created. */ + fun deviceIds(deviceIds: List) = deviceIds(JsonField.of(deviceIds)) + + /** + * Sets [Builder.deviceIds] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deviceIds(deviceIds: JsonField>) = apply { + this.deviceIds = deviceIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [deviceIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDeviceId(deviceId: String) = apply { + deviceIds = + (deviceIds ?: JsonField.of(mutableListOf())).also { + checkKnown("deviceIds", it).add(deviceId) + } + } + + /** + * Where the run itself has got to. `PENDING` and `RENDERED` mean Courier is still preparing + * the email, `SUBMITTED` means it is with the rendering service, and `COMPLETED` means + * every device has reported. `FAILED` is the run as a whole failing — an individual device + * failing never fails the run. + */ + fun status(status: PreviewRunStatus) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [PreviewRunStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The template that was rendered. */ + fun templateId(templateId: String) = templateId(JsonField.of(templateId)) + + /** + * Sets [Builder.templateId] to an arbitrary JSON value. + * + * You should usually call [Builder.templateId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun templateId(templateId: JsonField) = apply { this.templateId = templateId } + + /** + * Why the run failed, when `status` is `FAILED`. `NO_EMAIL_CHANNEL` and + * `TEMPLATE_NOT_SUPPORTED` mean there was nothing to render; `ALL_DEVICES_UNSUPPORTED` + * means every requested device has been retired and the request can be fixed by choosing + * others. + */ + fun failureReason(failureReason: PreviewRunFailureReason) = + failureReason(JsonField.of(failureReason)) + + /** + * Sets [Builder.failureReason] to an arbitrary JSON value. + * + * You should usually call [Builder.failureReason] with a well-typed + * [PreviewRunFailureReason] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun failureReason(failureReason: JsonField) = apply { + this.failureReason = failureReason + } + + /** + * The version of the template that was rendered — `draft`, or a zero-padded published + * version such as `v002`. Absent until the render settles. + */ + fun templateVersion(templateVersion: String) = + templateVersion(JsonField.of(templateVersion)) + + /** + * Sets [Builder.templateVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.templateVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun templateVersion(templateVersion: JsonField) = apply { + this.templateVersion = templateVersion + } + + 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 [PreviewRun]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .deviceIds() + * .status() + * .templateId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewRun = + PreviewRun( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("deviceIds", deviceIds).map { it.toImmutable() }, + checkRequired("status", status), + checkRequired("templateId", templateId), + failureReason, + templateVersion, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewRun = apply { + if (validated) { + return@apply + } + + id() + createdAt() + deviceIds() + status().validate() + templateId() + failureReason().ifPresent { it.validate() } + templateVersion() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (deviceIds.asKnown().getOrNull()?.size ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (templateId.asKnown().isPresent) 1 else 0) + + (failureReason.asKnown().getOrNull()?.validity() ?: 0) + + (if (templateVersion.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewRun && + id == other.id && + createdAt == other.createdAt && + deviceIds == other.deviceIds && + status == other.status && + templateId == other.templateId && + failureReason == other.failureReason && + templateVersion == other.templateVersion && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + deviceIds, + status, + templateId, + failureReason, + templateVersion, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreviewRun{id=$id, createdAt=$createdAt, deviceIds=$deviceIds, status=$status, templateId=$templateId, failureReason=$failureReason, templateVersion=$templateVersion, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunDetail.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunDetail.kt new file mode 100644 index 00000000..37eac2e0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunDetail.kt @@ -0,0 +1,539 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A preview run together with its per-device results. */ +class PreviewRunDetail +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val deviceIds: JsonField>, + private val results: JsonField>, + private val status: JsonField, + private val templateId: JsonField, + private val failureReason: JsonField, + private val templateVersion: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("device_ids") + @ExcludeMissing + deviceIds: JsonField> = JsonMissing.of(), + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of(), + @JsonProperty("status") + @ExcludeMissing + status: JsonField = JsonMissing.of(), + @JsonProperty("template_id") + @ExcludeMissing + templateId: JsonField = JsonMissing.of(), + @JsonProperty("failure_reason") + @ExcludeMissing + failureReason: JsonField = JsonMissing.of(), + @JsonProperty("template_version") + @ExcludeMissing + templateVersion: JsonField = JsonMissing.of(), + ) : this( + id, + createdAt, + deviceIds, + results, + status, + templateId, + failureReason, + templateVersion, + mutableMapOf(), + ) + + /** + * Unique identifier for the preview run. + * + * @throws CourierInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * ISO-8601 timestamp of when the run was created. + * + * @throws CourierInvalidDataException 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 createdAt(): String = createdAt.getRequired("created_at") + + /** + * The devices this run was submitted for, snapshotted when the run was created. + * + * @throws CourierInvalidDataException 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 deviceIds(): List = deviceIds.getRequired("device_ids") + + /** + * One entry per device in `device_ids`. + * + * @throws CourierInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * Where the run itself has got to. `PENDING` and `RENDERED` mean Courier is still preparing the + * email, `SUBMITTED` means it is with the rendering service, and `COMPLETED` means every device + * has reported. `FAILED` is the run as a whole failing — an individual device failing never + * fails the run. + * + * @throws CourierInvalidDataException 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 status(): PreviewRunStatus = status.getRequired("status") + + /** + * The template that was rendered. + * + * @throws CourierInvalidDataException 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 templateId(): String = templateId.getRequired("template_id") + + /** + * Why the run failed, when `status` is `FAILED`. `NO_EMAIL_CHANNEL` and + * `TEMPLATE_NOT_SUPPORTED` mean there was nothing to render; `ALL_DEVICES_UNSUPPORTED` means + * every requested device has been retired and the request can be fixed by choosing others. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun failureReason(): Optional = + failureReason.getOptional("failure_reason") + + /** + * The version of the template that was rendered — `draft`, or a zero-padded published version + * such as `v002`. Absent until the render settles. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun templateVersion(): Optional = templateVersion.getOptional("template_version") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [deviceIds]. + * + * Unlike [deviceIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_ids") + @ExcludeMissing + fun _deviceIds(): JsonField> = deviceIds + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") + @ExcludeMissing + fun _results(): JsonField> = results + + /** + * Returns the raw JSON value of [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [templateId]. + * + * Unlike [templateId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_id") @ExcludeMissing fun _templateId(): JsonField = templateId + + /** + * Returns the raw JSON value of [failureReason]. + * + * Unlike [failureReason], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("failure_reason") + @ExcludeMissing + fun _failureReason(): JsonField = failureReason + + /** + * Returns the raw JSON value of [templateVersion]. + * + * Unlike [templateVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_version") + @ExcludeMissing + fun _templateVersion(): JsonField = templateVersion + + @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 [PreviewRunDetail]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .deviceIds() + * .results() + * .status() + * .templateId() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewRunDetail]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var deviceIds: JsonField>? = null + private var results: JsonField>? = null + private var status: JsonField? = null + private var templateId: JsonField? = null + private var failureReason: JsonField = JsonMissing.of() + private var templateVersion: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewRunDetail: PreviewRunDetail) = apply { + id = previewRunDetail.id + createdAt = previewRunDetail.createdAt + deviceIds = previewRunDetail.deviceIds.map { it.toMutableList() } + results = previewRunDetail.results.map { it.toMutableList() } + status = previewRunDetail.status + templateId = previewRunDetail.templateId + failureReason = previewRunDetail.failureReason + templateVersion = previewRunDetail.templateVersion + additionalProperties = previewRunDetail.additionalProperties.toMutableMap() + } + + /** Unique identifier for the preview run. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ISO-8601 timestamp of when the run was created. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** The devices this run was submitted for, snapshotted when the run was created. */ + fun deviceIds(deviceIds: List) = deviceIds(JsonField.of(deviceIds)) + + /** + * Sets [Builder.deviceIds] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deviceIds(deviceIds: JsonField>) = apply { + this.deviceIds = deviceIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [deviceIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDeviceId(deviceId: String) = apply { + deviceIds = + (deviceIds ?: JsonField.of(mutableListOf())).also { + checkKnown("deviceIds", it).add(deviceId) + } + } + + /** One entry per device in `device_ids`. */ + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [PreviewResult] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: PreviewResult) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + /** + * Where the run itself has got to. `PENDING` and `RENDERED` mean Courier is still preparing + * the email, `SUBMITTED` means it is with the rendering service, and `COMPLETED` means + * every device has reported. `FAILED` is the run as a whole failing — an individual device + * failing never fails the run. + */ + fun status(status: PreviewRunStatus) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [PreviewRunStatus] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The template that was rendered. */ + fun templateId(templateId: String) = templateId(JsonField.of(templateId)) + + /** + * Sets [Builder.templateId] to an arbitrary JSON value. + * + * You should usually call [Builder.templateId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun templateId(templateId: JsonField) = apply { this.templateId = templateId } + + /** + * Why the run failed, when `status` is `FAILED`. `NO_EMAIL_CHANNEL` and + * `TEMPLATE_NOT_SUPPORTED` mean there was nothing to render; `ALL_DEVICES_UNSUPPORTED` + * means every requested device has been retired and the request can be fixed by choosing + * others. + */ + fun failureReason(failureReason: PreviewRunFailureReason) = + failureReason(JsonField.of(failureReason)) + + /** + * Sets [Builder.failureReason] to an arbitrary JSON value. + * + * You should usually call [Builder.failureReason] with a well-typed + * [PreviewRunFailureReason] value instead. This method is primarily for setting the field + * to an undocumented or not yet supported value. + */ + fun failureReason(failureReason: JsonField) = apply { + this.failureReason = failureReason + } + + /** + * The version of the template that was rendered — `draft`, or a zero-padded published + * version such as `v002`. Absent until the render settles. + */ + fun templateVersion(templateVersion: String) = + templateVersion(JsonField.of(templateVersion)) + + /** + * Sets [Builder.templateVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.templateVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun templateVersion(templateVersion: JsonField) = apply { + this.templateVersion = templateVersion + } + + 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 [PreviewRunDetail]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .deviceIds() + * .results() + * .status() + * .templateId() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewRunDetail = + PreviewRunDetail( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("deviceIds", deviceIds).map { it.toImmutable() }, + checkRequired("results", results).map { it.toImmutable() }, + checkRequired("status", status), + checkRequired("templateId", templateId), + failureReason, + templateVersion, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewRunDetail = apply { + if (validated) { + return@apply + } + + id() + createdAt() + deviceIds() + results().forEach { it.validate() } + status().validate() + templateId() + failureReason().ifPresent { it.validate() } + templateVersion() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (deviceIds.asKnown().getOrNull()?.size ?: 0) + + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (templateId.asKnown().isPresent) 1 else 0) + + (failureReason.asKnown().getOrNull()?.validity() ?: 0) + + (if (templateVersion.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewRunDetail && + id == other.id && + createdAt == other.createdAt && + deviceIds == other.deviceIds && + results == other.results && + status == other.status && + templateId == other.templateId && + failureReason == other.failureReason && + templateVersion == other.templateVersion && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + createdAt, + deviceIds, + results, + status, + templateId, + failureReason, + templateVersion, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreviewRunDetail{id=$id, createdAt=$createdAt, deviceIds=$deviceIds, results=$results, status=$status, templateId=$templateId, failureReason=$failureReason, templateVersion=$templateVersion, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunFailureReason.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunFailureReason.kt new file mode 100644 index 00000000..d6d76282 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunFailureReason.kt @@ -0,0 +1,166 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +/** + * Why the run failed, when `status` is `FAILED`. `NO_EMAIL_CHANNEL` and `TEMPLATE_NOT_SUPPORTED` + * mean there was nothing to render; `ALL_DEVICES_UNSUPPORTED` means every requested device has been + * retired and the request can be fixed by choosing others. + */ +class PreviewRunFailureReason +@JsonCreator +private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't match + * any known member, and you want to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val TEMPLATE_NOT_SUPPORTED = of("TEMPLATE_NOT_SUPPORTED") + + @JvmField val NO_EMAIL_CHANNEL = of("NO_EMAIL_CHANNEL") + + @JvmField val RENDER_FAILED = of("RENDER_FAILED") + + @JvmField val ALL_DEVICES_UNSUPPORTED = of("ALL_DEVICES_UNSUPPORTED") + + @JvmField val VENDOR_ERROR = of("VENDOR_ERROR") + + @JvmStatic fun of(value: String) = PreviewRunFailureReason(JsonField.of(value)) + } + + /** An enum containing [PreviewRunFailureReason]'s known values. */ + enum class Known { + TEMPLATE_NOT_SUPPORTED, + NO_EMAIL_CHANNEL, + RENDER_FAILED, + ALL_DEVICES_UNSUPPORTED, + VENDOR_ERROR, + } + + /** + * An enum containing [PreviewRunFailureReason]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PreviewRunFailureReason] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the SDK + * is on an older version than the API, then the API may respond with new members that the SDK + * is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + TEMPLATE_NOT_SUPPORTED, + NO_EMAIL_CHANNEL, + RENDER_FAILED, + ALL_DEVICES_UNSUPPORTED, + VENDOR_ERROR, + /** + * An enum member indicating that [PreviewRunFailureReason] was instantiated with an unknown + * value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if + * the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want to + * throw for the unknown case. + */ + fun value(): Value = + when (this) { + TEMPLATE_NOT_SUPPORTED -> Value.TEMPLATE_NOT_SUPPORTED + NO_EMAIL_CHANNEL -> Value.NO_EMAIL_CHANNEL + RENDER_FAILED -> Value.RENDER_FAILED + ALL_DEVICES_UNSUPPORTED -> Value.ALL_DEVICES_UNSUPPORTED + VENDOR_ERROR -> Value.VENDOR_ERROR + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't want + * to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + TEMPLATE_NOT_SUPPORTED -> Known.TEMPLATE_NOT_SUPPORTED + NO_EMAIL_CHANNEL -> Known.NO_EMAIL_CHANNEL + RENDER_FAILED -> Known.RENDER_FAILED + ALL_DEVICES_UNSUPPORTED -> Known.ALL_DEVICES_UNSUPPORTED + VENDOR_ERROR -> Known.VENDOR_ERROR + else -> throw CourierInvalidDataException("Unknown PreviewRunFailureReason: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging and + * generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the expected + * primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewRunFailureReason = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewRunFailureReason && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunListResponse.kt new file mode 100644 index 00000000..427214cc --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunListResponse.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.courier.models.Paging +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 java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Paginated list of preview runs, newest first. */ +class PreviewRunListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val paging: JsonField, + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("paging") @ExcludeMissing paging: JsonField = JsonMissing.of(), + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of(), + ) : this(paging, results, mutableMapOf()) + + /** + * @throws CourierInvalidDataException 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 paging(): Paging = paging.getRequired("paging") + + /** + * @throws CourierInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * Returns the raw JSON value of [paging]. + * + * Unlike [paging], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("paging") @ExcludeMissing fun _paging(): JsonField = paging + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") @ExcludeMissing fun _results(): JsonField> = results + + @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 [PreviewRunListResponse]. + * + * The following fields are required: + * ```java + * .paging() + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewRunListResponse]. */ + class Builder internal constructor() { + + private var paging: JsonField? = null + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewRunListResponse: PreviewRunListResponse) = apply { + paging = previewRunListResponse.paging + results = previewRunListResponse.results.map { it.toMutableList() } + additionalProperties = previewRunListResponse.additionalProperties.toMutableMap() + } + + fun paging(paging: Paging) = paging(JsonField.of(paging)) + + /** + * Sets [Builder.paging] to an arbitrary JSON value. + * + * You should usually call [Builder.paging] with a well-typed [Paging] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun paging(paging: JsonField) = apply { this.paging = paging } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [PreviewRun] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: PreviewRun) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + 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 [PreviewRunListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .paging() + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewRunListResponse = + PreviewRunListResponse( + checkRequired("paging", paging), + checkRequired("results", results).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewRunListResponse = apply { + if (validated) { + return@apply + } + + paging().validate() + results().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (paging.asKnown().getOrNull()?.validity() ?: 0) + + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewRunListResponse && + paging == other.paging && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(paging, results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreviewRunListResponse{paging=$paging, results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunStatus.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunStatus.kt new file mode 100644 index 00000000..7fa0dd3d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/PreviewRunStatus.kt @@ -0,0 +1,165 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.Enum +import com.courier.core.JsonField +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonCreator + +/** + * Where the run itself has got to. `PENDING` and `RENDERED` mean Courier is still preparing the + * email, `SUBMITTED` means it is with the rendering service, and `COMPLETED` means every device has + * reported. `FAILED` is the run as a whole failing — an individual device failing never fails the + * run. + */ +class PreviewRunStatus @JsonCreator private constructor(private val value: JsonField) : + Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't match + * any known member, and you want to know that value. For example, if the SDK is on an older + * version than the API, then the API may respond with new members that the SDK is unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val PENDING = of("PENDING") + + @JvmField val RENDERED = of("RENDERED") + + @JvmField val SUBMITTED = of("SUBMITTED") + + @JvmField val COMPLETED = of("COMPLETED") + + @JvmField val FAILED = of("FAILED") + + @JvmStatic fun of(value: String) = PreviewRunStatus(JsonField.of(value)) + } + + /** An enum containing [PreviewRunStatus]'s known values. */ + enum class Known { + PENDING, + RENDERED, + SUBMITTED, + COMPLETED, + FAILED, + } + + /** + * An enum containing [PreviewRunStatus]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [PreviewRunStatus] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the SDK + * is on an older version than the API, then the API may respond with new members that the SDK + * is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + PENDING, + RENDERED, + SUBMITTED, + COMPLETED, + FAILED, + /** + * An enum member indicating that [PreviewRunStatus] was instantiated with an unknown value. + */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] if + * the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want to + * throw for the unknown case. + */ + fun value(): Value = + when (this) { + PENDING -> Value.PENDING + RENDERED -> Value.RENDERED + SUBMITTED -> Value.SUBMITTED + COMPLETED -> Value.COMPLETED + FAILED -> Value.FAILED + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't want + * to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known member. + */ + fun known(): Known = + when (this) { + PENDING -> Known.PENDING + RENDERED -> Known.RENDERED + SUBMITTED -> Known.SUBMITTED + COMPLETED -> Known.COMPLETED + FAILED -> Known.FAILED + else -> throw CourierInvalidDataException("Unknown PreviewRunStatus: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging and + * generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the expected + * primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewRunStatus = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewRunStatus && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunCreateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunCreateParams.kt new file mode 100644 index 00000000..d1ed13f0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunCreateParams.kt @@ -0,0 +1,296 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Render this template's email content on each of the requested devices. + * + * Returns as soon as the run exists and its render is queued — the screenshots are produced + * asynchronously. Poll `GET /notifications/{id}/previews/runs/{previewRunId}` until every result + * reaches a terminal status. + * + * Name the devices either with `device_set_id`, for a saved set, or with `device_ids`, for a + * one-off list. Exactly one of the two is required. Inline `device_ids` must be ids listed by `GET + * /previews/devices`; any other id is a 422, refused before the run exists or is billed. + * + * A template that does not exist is a 404. One that exists but cannot be previewed — not a Design + * Studio template, no email channel, or no such `template_version` — is a 422, also refused before + * the run exists or is billed. + * + * Preview runs are a metered add-on. A workspace without it, or with its billing suspended, + * receives a 402. + */ +class RunCreateParams +private constructor( + private val id: String?, + private val idempotencyKey: String?, + private val xIdempotencyExpiration: String?, + private val createPreviewRunRequest: CreatePreviewRunRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + fun idempotencyKey(): Optional = Optional.ofNullable(idempotencyKey) + + fun xIdempotencyExpiration(): Optional = Optional.ofNullable(xIdempotencyExpiration) + + /** + * Request body for creating a preview run of the template in the path. Provide exactly one of + * `device_set_id` or `device_ids`. The template is the path's `{id}`; a `template_id` here is + * an unknown key and a 400. + */ + fun createPreviewRunRequest(): CreatePreviewRunRequest = createPreviewRunRequest + + fun _additionalBodyProperties(): Map = + createPreviewRunRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RunCreateParams]. + * + * The following fields are required: + * ```java + * .createPreviewRunRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunCreateParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var idempotencyKey: String? = null + private var xIdempotencyExpiration: String? = null + private var createPreviewRunRequest: CreatePreviewRunRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runCreateParams: RunCreateParams) = apply { + id = runCreateParams.id + idempotencyKey = runCreateParams.idempotencyKey + xIdempotencyExpiration = runCreateParams.xIdempotencyExpiration + createPreviewRunRequest = runCreateParams.createPreviewRunRequest + additionalHeaders = runCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = runCreateParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + fun idempotencyKey(idempotencyKey: String?) = apply { this.idempotencyKey = idempotencyKey } + + /** Alias for calling [Builder.idempotencyKey] with `idempotencyKey.orElse(null)`. */ + fun idempotencyKey(idempotencyKey: Optional) = + idempotencyKey(idempotencyKey.getOrNull()) + + fun xIdempotencyExpiration(xIdempotencyExpiration: String?) = apply { + this.xIdempotencyExpiration = xIdempotencyExpiration + } + + /** + * Alias for calling [Builder.xIdempotencyExpiration] with + * `xIdempotencyExpiration.orElse(null)`. + */ + fun xIdempotencyExpiration(xIdempotencyExpiration: Optional) = + xIdempotencyExpiration(xIdempotencyExpiration.getOrNull()) + + /** + * Request body for creating a preview run of the template in the path. Provide exactly one + * of `device_set_id` or `device_ids`. The template is the path's `{id}`; a `template_id` + * here is an unknown key and a 400. + */ + fun createPreviewRunRequest(createPreviewRunRequest: CreatePreviewRunRequest) = apply { + this.createPreviewRunRequest = createPreviewRunRequest + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RunCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .createPreviewRunRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunCreateParams = + RunCreateParams( + id, + idempotencyKey, + xIdempotencyExpiration, + checkRequired("createPreviewRunRequest", createPreviewRunRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): CreatePreviewRunRequest = createPreviewRunRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + else -> "" + } + + override fun _headers(): Headers = + Headers.builder() + .apply { + idempotencyKey?.let { put("Idempotency-Key", it) } + xIdempotencyExpiration?.let { put("x-idempotency-expiration", it) } + putAll(additionalHeaders) + } + .build() + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RunCreateParams && + id == other.id && + idempotencyKey == other.idempotencyKey && + xIdempotencyExpiration == other.xIdempotencyExpiration && + createPreviewRunRequest == other.createPreviewRunRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + id, + idempotencyKey, + xIdempotencyExpiration, + createPreviewRunRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "RunCreateParams{id=$id, idempotencyKey=$idempotencyKey, xIdempotencyExpiration=$xIdempotencyExpiration, createPreviewRunRequest=$createPreviewRunRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunListParams.kt new file mode 100644 index 00000000..ed80f39d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunListParams.kt @@ -0,0 +1,240 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * List this template's preview runs, newest first. Cursor-paginated. + * + * A template that does not exist is a 404, the same as every other `/notifications/{id}` route. + */ +class RunListParams +private constructor( + private val id: String?, + private val cursor: String?, + private val limit: Long?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** Opaque pagination cursor from a previous response. Omit for the first page. */ + fun cursor(): Optional = Optional.ofNullable(cursor) + + /** Maximum number of results per page. */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): RunListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RunListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var cursor: String? = null + private var limit: Long? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runListParams: RunListParams) = apply { + id = runListParams.id + cursor = runListParams.cursor + limit = runListParams.limit + additionalHeaders = runListParams.additionalHeaders.toBuilder() + additionalQueryParams = runListParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + /** Opaque pagination cursor from a previous response. Omit for the first page. */ + fun cursor(cursor: String?) = apply { this.cursor = cursor } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** Maximum number of results per page. */ + fun limit(limit: Long?) = apply { this.limit = limit } + + /** + * Alias for [Builder.limit]. + * + * This unboxed primitive overload exists for backwards compatibility. + */ + fun limit(limit: Long) = limit(limit as Long?) + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RunListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RunListParams = + RunListParams( + id, + cursor, + limit, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + cursor?.let { put("cursor", it) } + limit?.let { put("limit", it.toString()) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RunListParams && + id == other.id && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(id, cursor, limit, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RunListParams{id=$id, cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunRetrieveParams.kt new file mode 100644 index 00000000..1fa441a1 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/notifications/previews/runs/RunRetrieveParams.kt @@ -0,0 +1,226 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Retrieve one of this template's preview runs together with its per-device results. + * + * A run is only readable under the template it previewed: under any other template it is a 404, the + * same as a run that does not exist. + * + * `thumbnail_url` and `screenshot_url` are short-lived signed URLs, re-signed on every read. Fetch + * them now rather than storing them. Both are null until Courier's own copy of the image exists, + * which is what `status: COMPLETED` on a result means. + */ +class RunRetrieveParams +private constructor( + private val id: String, + private val previewRunId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): String = id + + fun previewRunId(): Optional = Optional.ofNullable(previewRunId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [RunRetrieveParams]. + * + * The following fields are required: + * ```java + * .id() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunRetrieveParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var previewRunId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runRetrieveParams: RunRetrieveParams) = apply { + id = runRetrieveParams.id + previewRunId = runRetrieveParams.previewRunId + additionalHeaders = runRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = runRetrieveParams.additionalQueryParams.toBuilder() + } + + fun id(id: String) = apply { this.id = id } + + fun previewRunId(previewRunId: String?) = apply { this.previewRunId = previewRunId } + + /** Alias for calling [Builder.previewRunId] with `previewRunId.orElse(null)`. */ + fun previewRunId(previewRunId: Optional) = previewRunId(previewRunId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RunRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): RunRetrieveParams = + RunRetrieveParams( + checkRequired("id", id), + previewRunId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id + 1 -> previewRunId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RunRetrieveParams && + id == other.id && + previewRunId == other.previewRunId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(id, previewRunId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RunRetrieveParams{id=$id, previewRunId=$previewRunId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/CreateDeviceSetRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/CreateDeviceSetRequest.kt new file mode 100644 index 00000000..0209913b --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/CreateDeviceSetRequest.kt @@ -0,0 +1,244 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** + * Request body for creating or replacing a device set. A full replace, not a patch — both fields + * are always written. + */ +class CreateDeviceSetRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val deviceIds: JsonField>, + private val name: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("device_ids") + @ExcludeMissing + deviceIds: JsonField> = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(deviceIds, name, mutableMapOf()) + + /** + * The devices the set contains, by `PreviewDevice.id`. At least one is required. + * + * @throws CourierInvalidDataException 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 deviceIds(): List = deviceIds.getRequired("device_ids") + + /** + * Human-readable name. + * + * @throws CourierInvalidDataException 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 name(): String = name.getRequired("name") + + /** + * Returns the raw JSON value of [deviceIds]. + * + * Unlike [deviceIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_ids") + @ExcludeMissing + fun _deviceIds(): JsonField> = deviceIds + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + @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 [CreateDeviceSetRequest]. + * + * The following fields are required: + * ```java + * .deviceIds() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreateDeviceSetRequest]. */ + class Builder internal constructor() { + + private var deviceIds: JsonField>? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createDeviceSetRequest: CreateDeviceSetRequest) = apply { + deviceIds = createDeviceSetRequest.deviceIds.map { it.toMutableList() } + name = createDeviceSetRequest.name + additionalProperties = createDeviceSetRequest.additionalProperties.toMutableMap() + } + + /** The devices the set contains, by `PreviewDevice.id`. At least one is required. */ + fun deviceIds(deviceIds: List) = deviceIds(JsonField.of(deviceIds)) + + /** + * Sets [Builder.deviceIds] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deviceIds(deviceIds: JsonField>) = apply { + this.deviceIds = deviceIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [deviceIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDeviceId(deviceId: String) = apply { + deviceIds = + (deviceIds ?: JsonField.of(mutableListOf())).also { + checkKnown("deviceIds", it).add(deviceId) + } + } + + /** Human-readable name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + 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 [CreateDeviceSetRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .deviceIds() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreateDeviceSetRequest = + CreateDeviceSetRequest( + checkRequired("deviceIds", deviceIds).map { it.toImmutable() }, + checkRequired("name", name), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): CreateDeviceSetRequest = apply { + if (validated) { + return@apply + } + + deviceIds() + name() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (deviceIds.asKnown().getOrNull()?.size ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is CreateDeviceSetRequest && + deviceIds == other.deviceIds && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(deviceIds, name, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CreateDeviceSetRequest{deviceIds=$deviceIds, name=$name, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/DeviceSet.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/DeviceSet.kt new file mode 100644 index 00000000..14d6f9da --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/DeviceSet.kt @@ -0,0 +1,396 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A named, reusable list of preview devices. */ +class DeviceSet +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val createdAt: JsonField, + private val deviceIds: JsonField>, + private val name: JsonField, + private val updatedAt: JsonField, + private val archivedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("device_ids") + @ExcludeMissing + deviceIds: JsonField> = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("archived_at") + @ExcludeMissing + archivedAt: JsonField = JsonMissing.of(), + ) : this(id, createdAt, deviceIds, name, updatedAt, archivedAt, mutableMapOf()) + + /** + * Unique identifier for the device set. + * + * @throws CourierInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * ISO-8601 timestamp of when the set was created. + * + * @throws CourierInvalidDataException 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 createdAt(): String = createdAt.getRequired("created_at") + + /** + * The devices in this set, by `PreviewDevice.id`. + * + * @throws CourierInvalidDataException 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 deviceIds(): List = deviceIds.getRequired("device_ids") + + /** + * Human-readable name. + * + * @throws CourierInvalidDataException 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 name(): String = name.getRequired("name") + + /** + * ISO-8601 timestamp of when the set was last written. + * + * @throws CourierInvalidDataException 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 updatedAt(): String = updatedAt.getRequired("updated_at") + + /** + * ISO-8601 timestamp of when the set was archived. Present only on the archive response, which + * is the one place the state is observable. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun archivedAt(): Optional = archivedAt.getOptional("archived_at") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [createdAt]. + * + * Unlike [createdAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_at") @ExcludeMissing fun _createdAt(): JsonField = createdAt + + /** + * Returns the raw JSON value of [deviceIds]. + * + * Unlike [deviceIds], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("device_ids") + @ExcludeMissing + fun _deviceIds(): JsonField> = deviceIds + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + + /** + * Returns the raw JSON value of [archivedAt]. + * + * Unlike [archivedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("archived_at") @ExcludeMissing fun _archivedAt(): JsonField = archivedAt + + @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 [DeviceSet]. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .deviceIds() + * .name() + * .updatedAt() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DeviceSet]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var createdAt: JsonField? = null + private var deviceIds: JsonField>? = null + private var name: JsonField? = null + private var updatedAt: JsonField? = null + private var archivedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(deviceSet: DeviceSet) = apply { + id = deviceSet.id + createdAt = deviceSet.createdAt + deviceIds = deviceSet.deviceIds.map { it.toMutableList() } + name = deviceSet.name + updatedAt = deviceSet.updatedAt + archivedAt = deviceSet.archivedAt + additionalProperties = deviceSet.additionalProperties.toMutableMap() + } + + /** Unique identifier for the device set. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** ISO-8601 timestamp of when the set was created. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** The devices in this set, by `PreviewDevice.id`. */ + fun deviceIds(deviceIds: List) = deviceIds(JsonField.of(deviceIds)) + + /** + * Sets [Builder.deviceIds] to an arbitrary JSON value. + * + * You should usually call [Builder.deviceIds] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun deviceIds(deviceIds: JsonField>) = apply { + this.deviceIds = deviceIds.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [deviceIds]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addDeviceId(deviceId: String) = apply { + deviceIds = + (deviceIds ?: JsonField.of(mutableListOf())).also { + checkKnown("deviceIds", it).add(deviceId) + } + } + + /** Human-readable name. */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** ISO-8601 timestamp of when the set was last written. */ + fun updatedAt(updatedAt: String) = updatedAt(JsonField.of(updatedAt)) + + /** + * Sets [Builder.updatedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun updatedAt(updatedAt: JsonField) = apply { this.updatedAt = updatedAt } + + /** + * ISO-8601 timestamp of when the set was archived. Present only on the archive response, + * which is the one place the state is observable. + */ + fun archivedAt(archivedAt: String) = archivedAt(JsonField.of(archivedAt)) + + /** + * Sets [Builder.archivedAt] to an arbitrary JSON value. + * + * You should usually call [Builder.archivedAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun archivedAt(archivedAt: JsonField) = apply { this.archivedAt = archivedAt } + + 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 [DeviceSet]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .createdAt() + * .deviceIds() + * .name() + * .updatedAt() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DeviceSet = + DeviceSet( + checkRequired("id", id), + checkRequired("createdAt", createdAt), + checkRequired("deviceIds", deviceIds).map { it.toImmutable() }, + checkRequired("name", name), + checkRequired("updatedAt", updatedAt), + archivedAt, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DeviceSet = apply { + if (validated) { + return@apply + } + + id() + createdAt() + deviceIds() + name() + updatedAt() + archivedAt() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (if (id.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (deviceIds.asKnown().getOrNull()?.size ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (if (archivedAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DeviceSet && + id == other.id && + createdAt == other.createdAt && + deviceIds == other.deviceIds && + name == other.name && + updatedAt == other.updatedAt && + archivedAt == other.archivedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(id, createdAt, deviceIds, name, updatedAt, archivedAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DeviceSet{id=$id, createdAt=$createdAt, deviceIds=$deviceIds, name=$name, updatedAt=$updatedAt, archivedAt=$archivedAt, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/DeviceSetListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/DeviceSetListResponse.kt new file mode 100644 index 00000000..f21466b0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/DeviceSetListResponse.kt @@ -0,0 +1,201 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** The workspace's active device sets. Not paginated. */ +class DeviceSetListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of() + ) : this(results, mutableMapOf()) + + /** + * @throws CourierInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") @ExcludeMissing fun _results(): JsonField> = results + + @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 [DeviceSetListResponse]. + * + * The following fields are required: + * ```java + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [DeviceSetListResponse]. */ + class Builder internal constructor() { + + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(deviceSetListResponse: DeviceSetListResponse) = apply { + results = deviceSetListResponse.results.map { it.toMutableList() } + additionalProperties = deviceSetListResponse.additionalProperties.toMutableMap() + } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [DeviceSet] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: DeviceSet) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + 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 [DeviceSetListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): DeviceSetListResponse = + DeviceSetListResponse( + checkRequired("results", results).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): DeviceSetListResponse = apply { + if (validated) { + return@apply + } + + results().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is DeviceSetListResponse && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "DeviceSetListResponse{results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewArchiveDeviceSetParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewArchiveDeviceSetParams.kt new file mode 100644 index 00000000..d37996c2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewArchiveDeviceSetParams.kt @@ -0,0 +1,242 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import com.courier.core.toImmutable +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Archive a device set. This is a soft delete — the archived set is returned and no longer appears + * in list results. Runs already created against it keep their own copy of the device list and are + * unaffected. The Courier-provided default set cannot be archived and returns 409. + */ +class PreviewArchiveDeviceSetParams +private constructor( + private val deviceSetId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun deviceSetId(): Optional = Optional.ofNullable(deviceSetId) + + /** Additional body properties to send with the request. */ + fun _additionalBodyProperties(): Map = additionalBodyProperties + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreviewArchiveDeviceSetParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [PreviewArchiveDeviceSetParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewArchiveDeviceSetParams]. */ + class Builder internal constructor() { + + private var deviceSetId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + private var additionalBodyProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewArchiveDeviceSetParams: PreviewArchiveDeviceSetParams) = apply { + deviceSetId = previewArchiveDeviceSetParams.deviceSetId + additionalHeaders = previewArchiveDeviceSetParams.additionalHeaders.toBuilder() + additionalQueryParams = previewArchiveDeviceSetParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + previewArchiveDeviceSetParams.additionalBodyProperties.toMutableMap() + } + + fun deviceSetId(deviceSetId: String?) = apply { this.deviceSetId = deviceSetId } + + /** Alias for calling [Builder.deviceSetId] with `deviceSetId.orElse(null)`. */ + fun deviceSetId(deviceSetId: Optional) = deviceSetId(deviceSetId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + fun additionalBodyProperties(additionalBodyProperties: Map) = apply { + this.additionalBodyProperties.clear() + putAllAdditionalBodyProperties(additionalBodyProperties) + } + + fun putAdditionalBodyProperty(key: String, value: JsonValue) = apply { + additionalBodyProperties.put(key, value) + } + + fun putAllAdditionalBodyProperties(additionalBodyProperties: Map) = + apply { + this.additionalBodyProperties.putAll(additionalBodyProperties) + } + + fun removeAdditionalBodyProperty(key: String) = apply { + additionalBodyProperties.remove(key) + } + + fun removeAllAdditionalBodyProperties(keys: Set) = apply { + keys.forEach(::removeAdditionalBodyProperty) + } + + /** + * Returns an immutable instance of [PreviewArchiveDeviceSetParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreviewArchiveDeviceSetParams = + PreviewArchiveDeviceSetParams( + deviceSetId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> deviceSetId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewArchiveDeviceSetParams && + deviceSetId == other.deviceSetId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + deviceSetId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "PreviewArchiveDeviceSetParams{deviceSetId=$deviceSetId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewCreateDeviceSetParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewCreateDeviceSetParams.kt new file mode 100644 index 00000000..115ab481 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewCreateDeviceSetParams.kt @@ -0,0 +1,215 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects + +/** + * Create a named, reusable set of preview devices. Every id must be one listed by `GET + * /previews/devices`; any other is a 422. + */ +class PreviewCreateDeviceSetParams +private constructor( + private val createDeviceSetRequest: CreateDeviceSetRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * Request body for creating or replacing a device set. A full replace, not a patch — both + * fields are always written. + */ + fun createDeviceSetRequest(): CreateDeviceSetRequest = createDeviceSetRequest + + fun _additionalBodyProperties(): Map = + createDeviceSetRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PreviewCreateDeviceSetParams]. + * + * The following fields are required: + * ```java + * .createDeviceSetRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewCreateDeviceSetParams]. */ + class Builder internal constructor() { + + private var createDeviceSetRequest: CreateDeviceSetRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(previewCreateDeviceSetParams: PreviewCreateDeviceSetParams) = apply { + createDeviceSetRequest = previewCreateDeviceSetParams.createDeviceSetRequest + additionalHeaders = previewCreateDeviceSetParams.additionalHeaders.toBuilder() + additionalQueryParams = previewCreateDeviceSetParams.additionalQueryParams.toBuilder() + } + + /** + * Request body for creating or replacing a device set. A full replace, not a patch — both + * fields are always written. + */ + fun createDeviceSetRequest(createDeviceSetRequest: CreateDeviceSetRequest) = apply { + this.createDeviceSetRequest = createDeviceSetRequest + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreviewCreateDeviceSetParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .createDeviceSetRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewCreateDeviceSetParams = + PreviewCreateDeviceSetParams( + checkRequired("createDeviceSetRequest", createDeviceSetRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): CreateDeviceSetRequest = createDeviceSetRequest + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewCreateDeviceSetParams && + createDeviceSetRequest == other.createDeviceSetRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(createDeviceSetRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreviewCreateDeviceSetParams{createDeviceSetRequest=$createDeviceSetRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewDevice.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewDevice.kt new file mode 100644 index 00000000..e043e029 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewDevice.kt @@ -0,0 +1,819 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.Enum +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkRequired +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * One mail app on one platform, operating system and theme that a preview can be rendered on. + * Reference data, identical for every workspace. Every field is always present; `platform` and + * `platform_version` are null where they do not apply. + */ +class PreviewDevice +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val app: JsonField, + private val category: JsonField, + private val name: JsonField, + private val os: JsonField, + private val osVersion: JsonField, + private val platform: JsonField, + private val platformVersion: JsonField, + private val theme: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("app") @ExcludeMissing app: JsonField = JsonMissing.of(), + @JsonProperty("category") @ExcludeMissing category: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("os") @ExcludeMissing os: JsonField = JsonMissing.of(), + @JsonProperty("os_version") @ExcludeMissing osVersion: JsonField = JsonMissing.of(), + @JsonProperty("platform") @ExcludeMissing platform: JsonField = JsonMissing.of(), + @JsonProperty("platform_version") + @ExcludeMissing + platformVersion: JsonField = JsonMissing.of(), + @JsonProperty("theme") @ExcludeMissing theme: JsonField = JsonMissing.of(), + ) : this( + id, + app, + category, + name, + os, + osVersion, + platform, + platformVersion, + theme, + mutableMapOf(), + ) + + /** + * The device's identifier, used in `device_ids` when creating a device set or a run. + * + * @throws CourierInvalidDataException 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 id(): String = id.getRequired("id") + + /** + * The mail app. For webmail it is the service (`outlook_com`, `gmail_com`); for mobile the app + * (`apple_mail`, `gmail`); for desktop the app together with the version it is sold under + * (`outlook_2019`, `outlook_microsoft_365`, `apple_mail_16`), because that version is what + * separates one desktop Outlook from another. + * + * @throws CourierInvalidDataException 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 app(): String = app.getRequired("app") + + /** + * Where the app runs. + * + * @throws CourierInvalidDataException 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 category(): Category = category.getRequired("category") + + /** + * Display name. Render it as-is rather than parsing it. It is also what separates the two + * 120-dpi Outlook renders from their 100% siblings, which are otherwise identical field for + * field. + * + * @throws CourierInvalidDataException 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 name(): String = name.getRequired("name") + + /** + * The operating system. + * + * @throws CourierInvalidDataException 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 os(): String = os.getRequired("os") + + /** + * The operating system's version. Always set. + * + * @throws CourierInvalidDataException 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 osVersion(): String = osVersion.getRequired("os_version") + + /** + * What the app runs on — the browser for webmail (`chrome`, `edge`, `firefox`), the phone for + * mobile (`iphone`, `pixel`). Null for desktop, where the app runs on nothing but the OS. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun platform(): Optional = platform.getOptional("platform") + + /** + * Which one of the platform — the phone model for mobile (`15_pro_max`, `10`). Null for + * webmail, which always renders in the current browser, and for desktop. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun platformVersion(): Optional = platformVersion.getOptional("platform_version") + + /** + * Whether the email is rendered in light or dark mode. + * + * @throws CourierInvalidDataException 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 theme(): Theme = theme.getRequired("theme") + + /** + * Returns the raw JSON value of [id]. + * + * Unlike [id], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("id") @ExcludeMissing fun _id(): JsonField = id + + /** + * Returns the raw JSON value of [app]. + * + * Unlike [app], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("app") @ExcludeMissing fun _app(): JsonField = app + + /** + * Returns the raw JSON value of [category]. + * + * Unlike [category], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("category") @ExcludeMissing fun _category(): JsonField = category + + /** + * Returns the raw JSON value of [name]. + * + * Unlike [name], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("name") @ExcludeMissing fun _name(): JsonField = name + + /** + * Returns the raw JSON value of [os]. + * + * Unlike [os], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("os") @ExcludeMissing fun _os(): JsonField = os + + /** + * Returns the raw JSON value of [osVersion]. + * + * Unlike [osVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("os_version") @ExcludeMissing fun _osVersion(): JsonField = osVersion + + /** + * Returns the raw JSON value of [platform]. + * + * Unlike [platform], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("platform") @ExcludeMissing fun _platform(): JsonField = platform + + /** + * Returns the raw JSON value of [platformVersion]. + * + * Unlike [platformVersion], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("platform_version") + @ExcludeMissing + fun _platformVersion(): JsonField = platformVersion + + /** + * Returns the raw JSON value of [theme]. + * + * Unlike [theme], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("theme") @ExcludeMissing fun _theme(): JsonField = theme + + @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 [PreviewDevice]. + * + * The following fields are required: + * ```java + * .id() + * .app() + * .category() + * .name() + * .os() + * .osVersion() + * .platform() + * .platformVersion() + * .theme() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewDevice]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var app: JsonField? = null + private var category: JsonField? = null + private var name: JsonField? = null + private var os: JsonField? = null + private var osVersion: JsonField? = null + private var platform: JsonField? = null + private var platformVersion: JsonField? = null + private var theme: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewDevice: PreviewDevice) = apply { + id = previewDevice.id + app = previewDevice.app + category = previewDevice.category + name = previewDevice.name + os = previewDevice.os + osVersion = previewDevice.osVersion + platform = previewDevice.platform + platformVersion = previewDevice.platformVersion + theme = previewDevice.theme + additionalProperties = previewDevice.additionalProperties.toMutableMap() + } + + /** The device's identifier, used in `device_ids` when creating a device set or a run. */ + fun id(id: String) = id(JsonField.of(id)) + + /** + * Sets [Builder.id] to an arbitrary JSON value. + * + * You should usually call [Builder.id] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun id(id: JsonField) = apply { this.id = id } + + /** + * The mail app. For webmail it is the service (`outlook_com`, `gmail_com`); for mobile the + * app (`apple_mail`, `gmail`); for desktop the app together with the version it is sold + * under (`outlook_2019`, `outlook_microsoft_365`, `apple_mail_16`), because that version is + * what separates one desktop Outlook from another. + */ + fun app(app: String) = app(JsonField.of(app)) + + /** + * Sets [Builder.app] to an arbitrary JSON value. + * + * You should usually call [Builder.app] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun app(app: JsonField) = apply { this.app = app } + + /** Where the app runs. */ + fun category(category: Category) = category(JsonField.of(category)) + + /** + * Sets [Builder.category] to an arbitrary JSON value. + * + * You should usually call [Builder.category] with a well-typed [Category] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun category(category: JsonField) = apply { this.category = category } + + /** + * Display name. Render it as-is rather than parsing it. It is also what separates the two + * 120-dpi Outlook renders from their 100% siblings, which are otherwise identical field for + * field. + */ + fun name(name: String) = name(JsonField.of(name)) + + /** + * Sets [Builder.name] to an arbitrary JSON value. + * + * You should usually call [Builder.name] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun name(name: JsonField) = apply { this.name = name } + + /** The operating system. */ + fun os(os: String) = os(JsonField.of(os)) + + /** + * Sets [Builder.os] to an arbitrary JSON value. + * + * You should usually call [Builder.os] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun os(os: JsonField) = apply { this.os = os } + + /** The operating system's version. Always set. */ + fun osVersion(osVersion: String) = osVersion(JsonField.of(osVersion)) + + /** + * Sets [Builder.osVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.osVersion] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun osVersion(osVersion: JsonField) = apply { this.osVersion = osVersion } + + /** + * What the app runs on — the browser for webmail (`chrome`, `edge`, `firefox`), the phone + * for mobile (`iphone`, `pixel`). Null for desktop, where the app runs on nothing but the + * OS. + */ + fun platform(platform: String?) = platform(JsonField.ofNullable(platform)) + + /** Alias for calling [Builder.platform] with `platform.orElse(null)`. */ + fun platform(platform: Optional) = platform(platform.getOrNull()) + + /** + * Sets [Builder.platform] to an arbitrary JSON value. + * + * You should usually call [Builder.platform] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun platform(platform: JsonField) = apply { this.platform = platform } + + /** + * Which one of the platform — the phone model for mobile (`15_pro_max`, `10`). Null for + * webmail, which always renders in the current browser, and for desktop. + */ + fun platformVersion(platformVersion: String?) = + platformVersion(JsonField.ofNullable(platformVersion)) + + /** Alias for calling [Builder.platformVersion] with `platformVersion.orElse(null)`. */ + fun platformVersion(platformVersion: Optional) = + platformVersion(platformVersion.getOrNull()) + + /** + * Sets [Builder.platformVersion] to an arbitrary JSON value. + * + * You should usually call [Builder.platformVersion] with a well-typed [String] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun platformVersion(platformVersion: JsonField) = apply { + this.platformVersion = platformVersion + } + + /** Whether the email is rendered in light or dark mode. */ + fun theme(theme: Theme) = theme(JsonField.of(theme)) + + /** + * Sets [Builder.theme] to an arbitrary JSON value. + * + * You should usually call [Builder.theme] with a well-typed [Theme] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun theme(theme: JsonField) = apply { this.theme = theme } + + 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 [PreviewDevice]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .app() + * .category() + * .name() + * .os() + * .osVersion() + * .platform() + * .platformVersion() + * .theme() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewDevice = + PreviewDevice( + checkRequired("id", id), + checkRequired("app", app), + checkRequired("category", category), + checkRequired("name", name), + checkRequired("os", os), + checkRequired("osVersion", osVersion), + checkRequired("platform", platform), + checkRequired("platformVersion", platformVersion), + checkRequired("theme", theme), + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewDevice = apply { + if (validated) { + return@apply + } + + id() + app() + category().validate() + name() + os() + osVersion() + platform() + platformVersion() + theme().validate() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (if (id.asKnown().isPresent) 1 else 0) + + (if (app.asKnown().isPresent) 1 else 0) + + (category.asKnown().getOrNull()?.validity() ?: 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (if (os.asKnown().isPresent) 1 else 0) + + (if (osVersion.asKnown().isPresent) 1 else 0) + + (if (platform.asKnown().isPresent) 1 else 0) + + (if (platformVersion.asKnown().isPresent) 1 else 0) + + (theme.asKnown().getOrNull()?.validity() ?: 0) + + /** Where the app runs. */ + class Category @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val WEBMAIL = of("webmail") + + @JvmField val MOBILE = of("mobile") + + @JvmField val DESKTOP = of("desktop") + + @JvmStatic fun of(value: String) = Category(JsonField.of(value)) + } + + /** An enum containing [Category]'s known values. */ + enum class Known { + WEBMAIL, + MOBILE, + DESKTOP, + } + + /** + * An enum containing [Category]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Category] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + WEBMAIL, + MOBILE, + DESKTOP, + /** An enum member indicating that [Category] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + WEBMAIL -> Value.WEBMAIL + MOBILE -> Value.MOBILE + DESKTOP -> Value.DESKTOP + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + WEBMAIL -> Known.WEBMAIL + MOBILE -> Known.MOBILE + DESKTOP -> Known.DESKTOP + else -> throw CourierInvalidDataException("Unknown Category: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Category = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Category && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Whether the email is rendered in light or dark mode. */ + class Theme @JsonCreator private constructor(private val value: JsonField) : Enum { + + /** + * Returns this class instance's raw value. + * + * This is usually only useful if this instance was deserialized from data that doesn't + * match any known member, and you want to know that value. For example, if the SDK is on an + * older version than the API, then the API may respond with new members that the SDK is + * unaware of. + */ + @com.fasterxml.jackson.annotation.JsonValue fun _value(): JsonField = value + + companion object { + + @JvmField val LIGHT = of("light") + + @JvmField val DARK = of("dark") + + @JvmStatic fun of(value: String) = Theme(JsonField.of(value)) + } + + /** An enum containing [Theme]'s known values. */ + enum class Known { + LIGHT, + DARK, + } + + /** + * An enum containing [Theme]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Theme] can contain an unknown value in a couple of cases: + * - It was deserialized from data that doesn't match any known member. For example, if the + * SDK is on an older version than the API, then the API may respond with new members that + * the SDK is unaware of. + * - It was constructed with an arbitrary value using the [of] method. + */ + enum class Value { + LIGHT, + DARK, + /** An enum member indicating that [Theme] was instantiated with an unknown value. */ + _UNKNOWN, + } + + /** + * Returns an enum member corresponding to this class instance's value, or [Value._UNKNOWN] + * if the class was instantiated with an unknown value. + * + * Use the [known] method instead if you're certain the value is always known or if you want + * to throw for the unknown case. + */ + fun value(): Value = + when (this) { + LIGHT -> Value.LIGHT + DARK -> Value.DARK + else -> Value._UNKNOWN + } + + /** + * Returns an enum member corresponding to this class instance's value. + * + * Use the [value] method instead if you're uncertain the value is always known and don't + * want to throw for the unknown case. + * + * @throws CourierInvalidDataException if this class instance's value is a not a known + * member. + */ + fun known(): Known = + when (this) { + LIGHT -> Known.LIGHT + DARK -> Known.DARK + else -> throw CourierInvalidDataException("Unknown Theme: $value") + } + + /** + * Returns this class instance's primitive wire representation. + * + * This differs from the [toString] method because that method is primarily for debugging + * and generally doesn't throw. + * + * @throws CourierInvalidDataException if this class instance's value does not have the + * expected primitive type. + */ + fun asString(): String = + _value().asString().orElseThrow { CourierInvalidDataException("Value is not a String") } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types + * recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): Theme = apply { + if (validated) { + return@apply + } + + known() + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = if (value() == Value._UNKNOWN) 0 else 1 + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is Theme && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewDevice && + id == other.id && + app == other.app && + category == other.category && + name == other.name && + os == other.os && + osVersion == other.osVersion && + platform == other.platform && + platformVersion == other.platformVersion && + theme == other.theme && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + app, + category, + name, + os, + osVersion, + platform, + platformVersion, + theme, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreviewDevice{id=$id, app=$app, category=$category, name=$name, os=$os, osVersion=$osVersion, platform=$platform, platformVersion=$platformVersion, theme=$theme, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewDeviceListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewDeviceListResponse.kt new file mode 100644 index 00000000..9a9d590d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewDeviceListResponse.kt @@ -0,0 +1,203 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +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 java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** The full catalog of renderable devices. Not paginated. */ +class PreviewDeviceListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val results: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("results") + @ExcludeMissing + results: JsonField> = JsonMissing.of() + ) : this(results, mutableMapOf()) + + /** + * @throws CourierInvalidDataException 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 results(): List = results.getRequired("results") + + /** + * Returns the raw JSON value of [results]. + * + * Unlike [results], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("results") + @ExcludeMissing + fun _results(): JsonField> = results + + @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 [PreviewDeviceListResponse]. + * + * The following fields are required: + * ```java + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewDeviceListResponse]. */ + class Builder internal constructor() { + + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(previewDeviceListResponse: PreviewDeviceListResponse) = apply { + results = previewDeviceListResponse.results.map { it.toMutableList() } + additionalProperties = previewDeviceListResponse.additionalProperties.toMutableMap() + } + + fun results(results: List) = results(JsonField.of(results)) + + /** + * Sets [Builder.results] to an arbitrary JSON value. + * + * You should usually call [Builder.results] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun results(results: JsonField>) = apply { + this.results = results.map { it.toMutableList() } + } + + /** + * Adds a single [PreviewDevice] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: PreviewDevice) = apply { + results = + (results ?: JsonField.of(mutableListOf())).also { + checkKnown("results", it).add(result) + } + } + + 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 [PreviewDeviceListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .results() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewDeviceListResponse = + PreviewDeviceListResponse( + checkRequired("results", results).map { it.toImmutable() }, + additionalProperties.toMutableMap(), + ) + } + + private var validated: Boolean = false + + /** + * Validates that the types of all values in this object match their expected types recursively. + * + * This method is _not_ forwards compatible with new types from the API for existing fields. + * + * @throws CourierInvalidDataException if any value type in this object doesn't match its + * expected type. + */ + fun validate(): PreviewDeviceListResponse = apply { + if (validated) { + return@apply + } + + results().forEach { it.validate() } + validated = true + } + + fun isValid(): Boolean = + try { + validate() + true + } catch (e: CourierInvalidDataException) { + 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 = + (results.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewDeviceListResponse && + results == other.results && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(results, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "PreviewDeviceListResponse{results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewListDeviceSetsParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewListDeviceSetsParams.kt new file mode 100644 index 00000000..6c40bf9e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewListDeviceSetsParams.kt @@ -0,0 +1,172 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects + +/** List the workspace's preview sets. Archived sets are not returned. */ +class PreviewListDeviceSetsParams +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreviewListDeviceSetsParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of [PreviewListDeviceSetsParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewListDeviceSetsParams]. */ + class Builder internal constructor() { + + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(previewListDeviceSetsParams: PreviewListDeviceSetsParams) = apply { + additionalHeaders = previewListDeviceSetsParams.additionalHeaders.toBuilder() + additionalQueryParams = previewListDeviceSetsParams.additionalQueryParams.toBuilder() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreviewListDeviceSetsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreviewListDeviceSetsParams = + PreviewListDeviceSetsParams(additionalHeaders.build(), additionalQueryParams.build()) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewListDeviceSetsParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreviewListDeviceSetsParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewListDevicesParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewListDevicesParams.kt new file mode 100644 index 00000000..dc70f028 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewListDevicesParams.kt @@ -0,0 +1,173 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects + +/** + * List the devices a preview can be rendered on. Reference data, identical for every workspace — + * these ids are what a device set is built from and what a run reports results for. + */ +class PreviewListDevicesParams +private constructor( + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreviewListDevicesParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [PreviewListDevicesParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewListDevicesParams]. */ + class Builder internal constructor() { + + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(previewListDevicesParams: PreviewListDevicesParams) = apply { + additionalHeaders = previewListDevicesParams.additionalHeaders.toBuilder() + additionalQueryParams = previewListDevicesParams.additionalQueryParams.toBuilder() + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreviewListDevicesParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreviewListDevicesParams = + PreviewListDevicesParams(additionalHeaders.build(), additionalQueryParams.build()) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewListDevicesParams && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreviewListDevicesParams{additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewRetrieveDeviceSetParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewRetrieveDeviceSetParams.kt new file mode 100644 index 00000000..60c42242 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewRetrieveDeviceSetParams.kt @@ -0,0 +1,197 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** Retrieve a preview set by ID. Archived sets return 404. */ +class PreviewRetrieveDeviceSetParams +private constructor( + private val deviceSetId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun deviceSetId(): Optional = Optional.ofNullable(deviceSetId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): PreviewRetrieveDeviceSetParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [PreviewRetrieveDeviceSetParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewRetrieveDeviceSetParams]. */ + class Builder internal constructor() { + + private var deviceSetId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(previewRetrieveDeviceSetParams: PreviewRetrieveDeviceSetParams) = apply { + deviceSetId = previewRetrieveDeviceSetParams.deviceSetId + additionalHeaders = previewRetrieveDeviceSetParams.additionalHeaders.toBuilder() + additionalQueryParams = previewRetrieveDeviceSetParams.additionalQueryParams.toBuilder() + } + + fun deviceSetId(deviceSetId: String?) = apply { this.deviceSetId = deviceSetId } + + /** Alias for calling [Builder.deviceSetId] with `deviceSetId.orElse(null)`. */ + fun deviceSetId(deviceSetId: Optional) = deviceSetId(deviceSetId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreviewRetrieveDeviceSetParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): PreviewRetrieveDeviceSetParams = + PreviewRetrieveDeviceSetParams( + deviceSetId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> deviceSetId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewRetrieveDeviceSetParams && + deviceSetId == other.deviceSetId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(deviceSetId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreviewRetrieveDeviceSetParams{deviceSetId=$deviceSetId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewUpdateDeviceSetParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewUpdateDeviceSetParams.kt new file mode 100644 index 00000000..69035b11 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/previews/PreviewUpdateDeviceSetParams.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.JsonValue +import com.courier.core.Params +import com.courier.core.checkRequired +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Replace a device set. This is a full replace, not a patch — both the name and the device list are + * always written. The Courier-provided default set cannot be changed and returns 409. + */ +class PreviewUpdateDeviceSetParams +private constructor( + private val deviceSetId: String?, + private val createDeviceSetRequest: CreateDeviceSetRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun deviceSetId(): Optional = Optional.ofNullable(deviceSetId) + + /** + * Request body for creating or replacing a device set. A full replace, not a patch — both + * fields are always written. + */ + fun createDeviceSetRequest(): CreateDeviceSetRequest = createDeviceSetRequest + + fun _additionalBodyProperties(): Map = + createDeviceSetRequest._additionalProperties() + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + /** + * Returns a mutable builder for constructing an instance of [PreviewUpdateDeviceSetParams]. + * + * The following fields are required: + * ```java + * .createDeviceSetRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [PreviewUpdateDeviceSetParams]. */ + class Builder internal constructor() { + + private var deviceSetId: String? = null + private var createDeviceSetRequest: CreateDeviceSetRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(previewUpdateDeviceSetParams: PreviewUpdateDeviceSetParams) = apply { + deviceSetId = previewUpdateDeviceSetParams.deviceSetId + createDeviceSetRequest = previewUpdateDeviceSetParams.createDeviceSetRequest + additionalHeaders = previewUpdateDeviceSetParams.additionalHeaders.toBuilder() + additionalQueryParams = previewUpdateDeviceSetParams.additionalQueryParams.toBuilder() + } + + fun deviceSetId(deviceSetId: String?) = apply { this.deviceSetId = deviceSetId } + + /** Alias for calling [Builder.deviceSetId] with `deviceSetId.orElse(null)`. */ + fun deviceSetId(deviceSetId: Optional) = deviceSetId(deviceSetId.getOrNull()) + + /** + * Request body for creating or replacing a device set. A full replace, not a patch — both + * fields are always written. + */ + fun createDeviceSetRequest(createDeviceSetRequest: CreateDeviceSetRequest) = apply { + this.createDeviceSetRequest = createDeviceSetRequest + } + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [PreviewUpdateDeviceSetParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .createDeviceSetRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): PreviewUpdateDeviceSetParams = + PreviewUpdateDeviceSetParams( + deviceSetId, + checkRequired("createDeviceSetRequest", createDeviceSetRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): CreateDeviceSetRequest = createDeviceSetRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> deviceSetId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is PreviewUpdateDeviceSetParams && + deviceSetId == other.deviceSetId && + createDeviceSetRequest == other.createDeviceSetRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(deviceSetId, createDeviceSetRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "PreviewUpdateDeviceSetParams{deviceSetId=$deviceSetId, createDeviceSetRequest=$createDeviceSetRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt index 00fc6d2e..5b50f33a 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsync.kt @@ -26,6 +26,7 @@ import com.courier.models.notifications.NotificationTemplateCreateRequest import com.courier.models.notifications.NotificationTemplateResponse import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.async.notifications.CheckServiceAsync +import com.courier.services.async.notifications.PreviewServiceAsync import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -47,6 +48,8 @@ interface NotificationServiceAsync { /** Create, update, version, publish, and localize notification templates and their content. */ fun checks(): CheckServiceAsync + fun previews(): PreviewServiceAsync + /** * Create a notification template. Requires all fields in the notification object. Templates are * created in draft state by default. @@ -489,6 +492,8 @@ interface NotificationServiceAsync { */ fun checks(): CheckServiceAsync.WithRawResponse + fun previews(): PreviewServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /notifications`, but is otherwise the same as * [NotificationServiceAsync.create]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt index 7d716f48..a65cb616 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/NotificationServiceAsyncImpl.kt @@ -37,6 +37,8 @@ import com.courier.models.notifications.NotificationTemplateResponse import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.async.notifications.CheckServiceAsync import com.courier.services.async.notifications.CheckServiceAsyncImpl +import com.courier.services.async.notifications.PreviewServiceAsync +import com.courier.services.async.notifications.PreviewServiceAsyncImpl import java.util.concurrent.CompletableFuture import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -51,6 +53,8 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption private val checks: CheckServiceAsync by lazy { CheckServiceAsyncImpl(clientOptions) } + private val previews: PreviewServiceAsync by lazy { PreviewServiceAsyncImpl(clientOptions) } + override fun withRawResponse(): NotificationServiceAsync.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): NotificationServiceAsync = @@ -59,6 +63,8 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption /** Create, update, version, publish, and localize notification templates and their content. */ override fun checks(): CheckServiceAsync = checks + override fun previews(): PreviewServiceAsync = previews + override fun create( params: NotificationCreateParams, requestOptions: RequestOptions, @@ -153,6 +159,10 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption CheckServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val previews: PreviewServiceAsync.WithRawResponse by lazy { + PreviewServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): NotificationServiceAsync.WithRawResponse = @@ -165,6 +175,8 @@ class NotificationServiceAsyncImpl internal constructor(private val clientOption */ override fun checks(): CheckServiceAsync.WithRawResponse = checks + override fun previews(): PreviewServiceAsync.WithRawResponse = previews + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/PreviewServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/PreviewServiceAsync.kt new file mode 100644 index 00000000..5f15be5e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/PreviewServiceAsync.kt @@ -0,0 +1,420 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.previews.CreateDeviceSetRequest +import com.courier.models.previews.DeviceSet +import com.courier.models.previews.DeviceSetListResponse +import com.courier.models.previews.PreviewArchiveDeviceSetParams +import com.courier.models.previews.PreviewCreateDeviceSetParams +import com.courier.models.previews.PreviewDeviceListResponse +import com.courier.models.previews.PreviewListDeviceSetsParams +import com.courier.models.previews.PreviewListDevicesParams +import com.courier.models.previews.PreviewRetrieveDeviceSetParams +import com.courier.models.previews.PreviewUpdateDeviceSetParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +interface PreviewServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreviewServiceAsync + + /** + * Archive a device set. This is a soft delete — the archived set is returned and no longer + * appears in list results. Runs already created against it keep their own copy of the device + * list and are unaffected. The Courier-provided default set cannot be archived and returns 409. + */ + fun archiveDeviceSet(deviceSetId: String): CompletableFuture = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archiveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + ): CompletableFuture = archiveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archiveDeviceSet */ + fun archiveDeviceSet(params: PreviewArchiveDeviceSetParams): CompletableFuture = + archiveDeviceSet(params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none(), requestOptions) + + /** + * Create a named, reusable set of preview devices. Every id must be one listed by `GET + * /previews/devices`; any other is a 422. + */ + fun createDeviceSet(params: PreviewCreateDeviceSetParams): CompletableFuture = + createDeviceSet(params, RequestOptions.none()) + + /** @see createDeviceSet */ + fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see createDeviceSet */ + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + createDeviceSet( + PreviewCreateDeviceSetParams.builder() + .createDeviceSetRequest(createDeviceSetRequest) + .build(), + requestOptions, + ) + + /** @see createDeviceSet */ + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest + ): CompletableFuture = createDeviceSet(createDeviceSetRequest, RequestOptions.none()) + + /** List the workspace's preview sets. Archived sets are not returned. */ + fun listDeviceSets(): CompletableFuture = + listDeviceSets(PreviewListDeviceSetsParams.none()) + + /** @see listDeviceSets */ + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see listDeviceSets */ + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none() + ): CompletableFuture = listDeviceSets(params, RequestOptions.none()) + + /** @see listDeviceSets */ + fun listDeviceSets(requestOptions: RequestOptions): CompletableFuture = + listDeviceSets(PreviewListDeviceSetsParams.none(), requestOptions) + + /** + * List the devices a preview can be rendered on. Reference data, identical for every workspace + * — these ids are what a device set is built from and what a run reports results for. + */ + fun listDevices(): CompletableFuture = + listDevices(PreviewListDevicesParams.none()) + + /** @see listDevices */ + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see listDevices */ + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none() + ): CompletableFuture = listDevices(params, RequestOptions.none()) + + /** @see listDevices */ + fun listDevices(requestOptions: RequestOptions): CompletableFuture = + listDevices(PreviewListDevicesParams.none(), requestOptions) + + /** Retrieve a preview set by ID. Archived sets return 404. */ + fun retrieveDeviceSet(deviceSetId: String): CompletableFuture = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + ): CompletableFuture = retrieveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet(params: PreviewRetrieveDeviceSetParams): CompletableFuture = + retrieveDeviceSet(params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none(), requestOptions) + + /** + * Replace a device set. This is a full replace, not a patch — both the name and the device list + * are always written. The Courier-provided default set cannot be changed and returns 409. + */ + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + ): CompletableFuture = updateDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + updateDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see updateDeviceSet */ + fun updateDeviceSet(params: PreviewUpdateDeviceSetParams): CompletableFuture = + updateDeviceSet(params, RequestOptions.none()) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [PreviewServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): PreviewServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `delete /previews/device-sets/{deviceSetId}`, but is + * otherwise the same as [PreviewServiceAsync.archiveDeviceSet]. + */ + fun archiveDeviceSet(deviceSetId: String): CompletableFuture> = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + archiveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + ): CompletableFuture> = + archiveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams + ): CompletableFuture> = + archiveDeviceSet(params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /previews/device-sets`, but is otherwise the same + * as [PreviewServiceAsync.createDeviceSet]. + */ + fun createDeviceSet( + params: PreviewCreateDeviceSetParams + ): CompletableFuture> = + createDeviceSet(params, RequestOptions.none()) + + /** @see createDeviceSet */ + fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see createDeviceSet */ + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + createDeviceSet( + PreviewCreateDeviceSetParams.builder() + .createDeviceSetRequest(createDeviceSetRequest) + .build(), + requestOptions, + ) + + /** @see createDeviceSet */ + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest + ): CompletableFuture> = + createDeviceSet(createDeviceSetRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /previews/device-sets`, but is otherwise the same as + * [PreviewServiceAsync.listDeviceSets]. + */ + fun listDeviceSets(): CompletableFuture> = + listDeviceSets(PreviewListDeviceSetsParams.none()) + + /** @see listDeviceSets */ + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see listDeviceSets */ + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none() + ): CompletableFuture> = + listDeviceSets(params, RequestOptions.none()) + + /** @see listDeviceSets */ + fun listDeviceSets( + requestOptions: RequestOptions + ): CompletableFuture> = + listDeviceSets(PreviewListDeviceSetsParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /previews/devices`, but is otherwise the same as + * [PreviewServiceAsync.listDevices]. + */ + fun listDevices(): CompletableFuture> = + listDevices(PreviewListDevicesParams.none()) + + /** @see listDevices */ + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see listDevices */ + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none() + ): CompletableFuture> = + listDevices(params, RequestOptions.none()) + + /** @see listDevices */ + fun listDevices( + requestOptions: RequestOptions + ): CompletableFuture> = + listDevices(PreviewListDevicesParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /previews/device-sets/{deviceSetId}`, but is + * otherwise the same as [PreviewServiceAsync.retrieveDeviceSet]. + */ + fun retrieveDeviceSet(deviceSetId: String): CompletableFuture> = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + ): CompletableFuture> = + retrieveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams + ): CompletableFuture> = + retrieveDeviceSet(params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /previews/device-sets/{deviceSetId}`, but is + * otherwise the same as [PreviewServiceAsync.updateDeviceSet]. + */ + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + ): CompletableFuture> = + updateDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + updateDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams + ): CompletableFuture> = + updateDeviceSet(params, RequestOptions.none()) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/PreviewServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/PreviewServiceAsyncImpl.kt new file mode 100644 index 00000000..494eb131 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/PreviewServiceAsyncImpl.kt @@ -0,0 +1,295 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepareAsync +import com.courier.models.previews.DeviceSet +import com.courier.models.previews.DeviceSetListResponse +import com.courier.models.previews.PreviewArchiveDeviceSetParams +import com.courier.models.previews.PreviewCreateDeviceSetParams +import com.courier.models.previews.PreviewDeviceListResponse +import com.courier.models.previews.PreviewListDeviceSetsParams +import com.courier.models.previews.PreviewListDevicesParams +import com.courier.models.previews.PreviewRetrieveDeviceSetParams +import com.courier.models.previews.PreviewUpdateDeviceSetParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +class PreviewServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewServiceAsync { + + private val withRawResponse: PreviewServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): PreviewServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): PreviewServiceAsync = + PreviewServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /previews/device-sets/{deviceSetId} + withRawResponse().archiveDeviceSet(params, requestOptions).thenApply { it.parse() } + + override fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /previews/device-sets + withRawResponse().createDeviceSet(params, requestOptions).thenApply { it.parse() } + + override fun listDeviceSets( + params: PreviewListDeviceSetsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /previews/device-sets + withRawResponse().listDeviceSets(params, requestOptions).thenApply { it.parse() } + + override fun listDevices( + params: PreviewListDevicesParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /previews/devices + withRawResponse().listDevices(params, requestOptions).thenApply { it.parse() } + + override fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /previews/device-sets/{deviceSetId} + withRawResponse().retrieveDeviceSet(params, requestOptions).thenApply { it.parse() } + + override fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /previews/device-sets/{deviceSetId} + withRawResponse().updateDeviceSet(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): PreviewServiceAsync.WithRawResponse = + PreviewServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val archiveDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("deviceSetId", params.deviceSetId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { archiveDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val createDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listDeviceSetsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listDeviceSets( + params: PreviewListDeviceSetsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listDeviceSetsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listDevicesHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listDevices( + params: PreviewListDevicesParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "devices") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listDevicesHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("deviceSetId", params.deviceSetId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets", params._pathParam(0)) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("deviceSetId", params.deviceSetId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { updateDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/PreviewServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/PreviewServiceAsync.kt new file mode 100644 index 00000000..2c0b97c9 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/PreviewServiceAsync.kt @@ -0,0 +1,49 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.notifications + +import com.courier.core.ClientOptions +import com.courier.services.async.notifications.previews.RunServiceAsync +import java.util.function.Consumer + +interface PreviewServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreviewServiceAsync + + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + fun runs(): RunServiceAsync + + /** + * A view of [PreviewServiceAsync] that provides access to raw HTTP responses for each method. + */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions( + modifier: Consumer + ): PreviewServiceAsync.WithRawResponse + + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + fun runs(): RunServiceAsync.WithRawResponse + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/PreviewServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/PreviewServiceAsyncImpl.kt new file mode 100644 index 00000000..f9ffd9e8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/PreviewServiceAsyncImpl.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.notifications + +import com.courier.core.ClientOptions +import com.courier.services.async.notifications.previews.RunServiceAsync +import com.courier.services.async.notifications.previews.RunServiceAsyncImpl +import java.util.function.Consumer + +class PreviewServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewServiceAsync { + + private val withRawResponse: PreviewServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val runs: RunServiceAsync by lazy { RunServiceAsyncImpl(clientOptions) } + + override fun withRawResponse(): PreviewServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): PreviewServiceAsync = + PreviewServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + override fun runs(): RunServiceAsync = runs + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewServiceAsync.WithRawResponse { + + private val runs: RunServiceAsync.WithRawResponse by lazy { + RunServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): PreviewServiceAsync.WithRawResponse = + PreviewServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + override fun runs(): RunServiceAsync.WithRawResponse = runs + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/previews/RunServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/previews/RunServiceAsync.kt new file mode 100644 index 00000000..c37fee0a --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/previews/RunServiceAsync.kt @@ -0,0 +1,252 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.notifications.previews + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.notifications.previews.runs.PreviewRun +import com.courier.models.notifications.previews.runs.PreviewRunDetail +import com.courier.models.notifications.previews.runs.PreviewRunListResponse +import com.courier.models.notifications.previews.runs.RunCreateParams +import com.courier.models.notifications.previews.runs.RunListParams +import com.courier.models.notifications.previews.runs.RunRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +interface RunServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunServiceAsync + + /** + * Render this template's email content on each of the requested devices. + * + * Returns as soon as the run exists and its render is queued — the screenshots are produced + * asynchronously. Poll `GET /notifications/{id}/previews/runs/{previewRunId}` until every + * result reaches a terminal status. + * + * Name the devices either with `device_set_id`, for a saved set, or with `device_ids`, for a + * one-off list. Exactly one of the two is required. Inline `device_ids` must be ids listed by + * `GET /previews/devices`; any other id is a 422, refused before the run exists or is billed. + * + * A template that does not exist is a 404. One that exists but cannot be previewed — not a + * Design Studio template, no email channel, or no such `template_version` — is a 422, also + * refused before the run exists or is billed. + * + * Preview runs are a metered add-on. A workspace without it, or with its billing suspended, + * receives a 402. + */ + fun create(id: String, params: RunCreateParams): CompletableFuture = + create(id, params, RequestOptions.none()) + + /** @see create */ + fun create( + id: String, + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = create(params.toBuilder().id(id).build(), requestOptions) + + /** @see create */ + fun create(params: RunCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Retrieve one of this template's preview runs together with its per-device results. + * + * A run is only readable under the template it previewed: under any other template it is a 404, + * the same as a run that does not exist. + * + * `thumbnail_url` and `screenshot_url` are short-lived signed URLs, re-signed on every read. + * Fetch them now rather than storing them. Both are null until Courier's own copy of the image + * exists, which is what `status: COMPLETED` on a result means. + */ + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + ): CompletableFuture = retrieve(previewRunId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().previewRunId(previewRunId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RunRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * List this template's preview runs, newest first. Cursor-paginated. + * + * A template that does not exist is a 404, the same as every other `/notifications/{id}` route. + */ + fun list(id: String): CompletableFuture = list(id, RunListParams.none()) + + /** @see list */ + fun list( + id: String, + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + list(params.toBuilder().id(id).build(), requestOptions) + + /** @see list */ + fun list( + id: String, + params: RunListParams = RunListParams.none(), + ): CompletableFuture = list(id, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: RunListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list(params: RunListParams): CompletableFuture = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = list(id, RunListParams.none(), requestOptions) + + /** A view of [RunServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /notifications/{id}/previews/runs`, but is + * otherwise the same as [RunServiceAsync.create]. + */ + fun create( + id: String, + params: RunCreateParams, + ): CompletableFuture> = + create(id, params, RequestOptions.none()) + + /** @see create */ + fun create( + id: String, + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create(params.toBuilder().id(id).build(), requestOptions) + + /** @see create */ + fun create(params: RunCreateParams): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /notifications/{id}/previews/runs/{previewRunId}`, + * but is otherwise the same as [RunServiceAsync.retrieve]. + */ + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + ): CompletableFuture> = + retrieve(previewRunId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().previewRunId(previewRunId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /notifications/{id}/previews/runs`, but is otherwise + * the same as [RunServiceAsync.list]. + */ + fun list(id: String): CompletableFuture> = + list(id, RunListParams.none()) + + /** @see list */ + fun list( + id: String, + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + list(params.toBuilder().id(id).build(), requestOptions) + + /** @see list */ + fun list( + id: String, + params: RunListParams = RunListParams.none(), + ): CompletableFuture> = + list(id, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: RunListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: RunListParams + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + list(id, RunListParams.none(), requestOptions) + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/previews/RunServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/previews/RunServiceAsyncImpl.kt new file mode 100644 index 00000000..d19bdfc5 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/notifications/previews/RunServiceAsyncImpl.kt @@ -0,0 +1,185 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.notifications.previews + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepareAsync +import com.courier.models.notifications.previews.runs.PreviewRun +import com.courier.models.notifications.previews.runs.PreviewRunDetail +import com.courier.models.notifications.previews.runs.PreviewRunListResponse +import com.courier.models.notifications.previews.runs.RunCreateParams +import com.courier.models.notifications.previews.runs.RunListParams +import com.courier.models.notifications.previews.runs.RunRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +class RunServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + RunServiceAsync { + + private val withRawResponse: RunServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RunServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RunServiceAsync = + RunServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: RunCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /notifications/{id}/previews/runs + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /notifications/{id}/previews/runs/{previewRunId} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /notifications/{id}/previews/runs + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RunServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RunServiceAsync.WithRawResponse = + RunServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: RunCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "previews", "runs") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("previewRunId", params.previewRunId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "notifications", + params._pathParam(0), + "previews", + "runs", + params._pathParam(1), + ) + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "previews", "runs") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt index 847aa599..37a17bb5 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationService.kt @@ -26,6 +26,7 @@ import com.courier.models.notifications.NotificationTemplateCreateRequest import com.courier.models.notifications.NotificationTemplateResponse import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.blocking.notifications.CheckService +import com.courier.services.blocking.notifications.PreviewService import com.google.errorprone.annotations.MustBeClosed import java.util.function.Consumer @@ -47,6 +48,8 @@ interface NotificationService { /** Create, update, version, publish, and localize notification templates and their content. */ fun checks(): CheckService + fun previews(): PreviewService + /** * Create a notification template. Requires all fields in the notification object. Templates are * created in draft state by default. @@ -452,6 +455,8 @@ interface NotificationService { */ fun checks(): CheckService.WithRawResponse + fun previews(): PreviewService.WithRawResponse + /** * Returns a raw HTTP response for `post /notifications`, but is otherwise the same as * [NotificationService.create]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt index a03d349b..317d462a 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/NotificationServiceImpl.kt @@ -37,6 +37,8 @@ import com.courier.models.notifications.NotificationTemplateResponse import com.courier.models.notifications.NotificationTemplateVersionListResponse import com.courier.services.blocking.notifications.CheckService import com.courier.services.blocking.notifications.CheckServiceImpl +import com.courier.services.blocking.notifications.PreviewService +import com.courier.services.blocking.notifications.PreviewServiceImpl import java.util.function.Consumer import kotlin.jvm.optionals.getOrNull @@ -50,6 +52,8 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl private val checks: CheckService by lazy { CheckServiceImpl(clientOptions) } + private val previews: PreviewService by lazy { PreviewServiceImpl(clientOptions) } + override fun withRawResponse(): NotificationService.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): NotificationService = @@ -58,6 +62,8 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl /** Create, update, version, publish, and localize notification templates and their content. */ override fun checks(): CheckService = checks + override fun previews(): PreviewService = previews + override fun create( params: NotificationCreateParams, requestOptions: RequestOptions, @@ -148,6 +154,10 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl CheckServiceImpl.WithRawResponseImpl(clientOptions) } + private val previews: PreviewService.WithRawResponse by lazy { + PreviewServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): NotificationService.WithRawResponse = @@ -160,6 +170,8 @@ class NotificationServiceImpl internal constructor(private val clientOptions: Cl */ override fun checks(): CheckService.WithRawResponse = checks + override fun previews(): PreviewService.WithRawResponse = previews + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreviewService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreviewService.kt new file mode 100644 index 00000000..17f000bd --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreviewService.kt @@ -0,0 +1,419 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.previews.CreateDeviceSetRequest +import com.courier.models.previews.DeviceSet +import com.courier.models.previews.DeviceSetListResponse +import com.courier.models.previews.PreviewArchiveDeviceSetParams +import com.courier.models.previews.PreviewCreateDeviceSetParams +import com.courier.models.previews.PreviewDeviceListResponse +import com.courier.models.previews.PreviewListDeviceSetsParams +import com.courier.models.previews.PreviewListDevicesParams +import com.courier.models.previews.PreviewRetrieveDeviceSetParams +import com.courier.models.previews.PreviewUpdateDeviceSetParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +interface PreviewService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreviewService + + /** + * Archive a device set. This is a soft delete — the archived set is returned and no longer + * appears in list results. Runs already created against it keep their own copy of the device + * list and are unaffected. The Courier-provided default set cannot be archived and returns 409. + */ + fun archiveDeviceSet(deviceSetId: String): DeviceSet = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet = + archiveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + ): DeviceSet = archiveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet + + /** @see archiveDeviceSet */ + fun archiveDeviceSet(params: PreviewArchiveDeviceSetParams): DeviceSet = + archiveDeviceSet(params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + fun archiveDeviceSet(deviceSetId: String, requestOptions: RequestOptions): DeviceSet = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none(), requestOptions) + + /** + * Create a named, reusable set of preview devices. Every id must be one listed by `GET + * /previews/devices`; any other is a 422. + */ + fun createDeviceSet(params: PreviewCreateDeviceSetParams): DeviceSet = + createDeviceSet(params, RequestOptions.none()) + + /** @see createDeviceSet */ + fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet + + /** @see createDeviceSet */ + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet = + createDeviceSet( + PreviewCreateDeviceSetParams.builder() + .createDeviceSetRequest(createDeviceSetRequest) + .build(), + requestOptions, + ) + + /** @see createDeviceSet */ + fun createDeviceSet(createDeviceSetRequest: CreateDeviceSetRequest): DeviceSet = + createDeviceSet(createDeviceSetRequest, RequestOptions.none()) + + /** List the workspace's preview sets. Archived sets are not returned. */ + fun listDeviceSets(): DeviceSetListResponse = listDeviceSets(PreviewListDeviceSetsParams.none()) + + /** @see listDeviceSets */ + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSetListResponse + + /** @see listDeviceSets */ + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none() + ): DeviceSetListResponse = listDeviceSets(params, RequestOptions.none()) + + /** @see listDeviceSets */ + fun listDeviceSets(requestOptions: RequestOptions): DeviceSetListResponse = + listDeviceSets(PreviewListDeviceSetsParams.none(), requestOptions) + + /** + * List the devices a preview can be rendered on. Reference data, identical for every workspace + * — these ids are what a device set is built from and what a run reports results for. + */ + fun listDevices(): PreviewDeviceListResponse = listDevices(PreviewListDevicesParams.none()) + + /** @see listDevices */ + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewDeviceListResponse + + /** @see listDevices */ + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none() + ): PreviewDeviceListResponse = listDevices(params, RequestOptions.none()) + + /** @see listDevices */ + fun listDevices(requestOptions: RequestOptions): PreviewDeviceListResponse = + listDevices(PreviewListDevicesParams.none(), requestOptions) + + /** Retrieve a preview set by ID. Archived sets return 404. */ + fun retrieveDeviceSet(deviceSetId: String): DeviceSet = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet = + retrieveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + ): DeviceSet = retrieveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet(params: PreviewRetrieveDeviceSetParams): DeviceSet = + retrieveDeviceSet(params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + fun retrieveDeviceSet(deviceSetId: String, requestOptions: RequestOptions): DeviceSet = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none(), requestOptions) + + /** + * Replace a device set. This is a full replace, not a patch — both the name and the device list + * are always written. The Courier-provided default set cannot be changed and returns 409. + */ + fun updateDeviceSet(deviceSetId: String, params: PreviewUpdateDeviceSetParams): DeviceSet = + updateDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet = + updateDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see updateDeviceSet */ + fun updateDeviceSet(params: PreviewUpdateDeviceSetParams): DeviceSet = + updateDeviceSet(params, RequestOptions.none()) + + /** @see updateDeviceSet */ + fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): DeviceSet + + /** A view of [PreviewService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreviewService.WithRawResponse + + /** + * Returns a raw HTTP response for `delete /previews/device-sets/{deviceSetId}`, but is + * otherwise the same as [PreviewService.archiveDeviceSet]. + */ + @MustBeClosed + fun archiveDeviceSet(deviceSetId: String): HttpResponseFor = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none()) + + /** @see archiveDeviceSet */ + @MustBeClosed + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + archiveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see archiveDeviceSet */ + @MustBeClosed + fun archiveDeviceSet( + deviceSetId: String, + params: PreviewArchiveDeviceSetParams = PreviewArchiveDeviceSetParams.none(), + ): HttpResponseFor = archiveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + @MustBeClosed + fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see archiveDeviceSet */ + @MustBeClosed + fun archiveDeviceSet(params: PreviewArchiveDeviceSetParams): HttpResponseFor = + archiveDeviceSet(params, RequestOptions.none()) + + /** @see archiveDeviceSet */ + @MustBeClosed + fun archiveDeviceSet( + deviceSetId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + archiveDeviceSet(deviceSetId, PreviewArchiveDeviceSetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /previews/device-sets`, but is otherwise the same + * as [PreviewService.createDeviceSet]. + */ + @MustBeClosed + fun createDeviceSet(params: PreviewCreateDeviceSetParams): HttpResponseFor = + createDeviceSet(params, RequestOptions.none()) + + /** @see createDeviceSet */ + @MustBeClosed + fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see createDeviceSet */ + @MustBeClosed + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + createDeviceSet( + PreviewCreateDeviceSetParams.builder() + .createDeviceSetRequest(createDeviceSetRequest) + .build(), + requestOptions, + ) + + /** @see createDeviceSet */ + @MustBeClosed + fun createDeviceSet( + createDeviceSetRequest: CreateDeviceSetRequest + ): HttpResponseFor = + createDeviceSet(createDeviceSetRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /previews/device-sets`, but is otherwise the same as + * [PreviewService.listDeviceSets]. + */ + @MustBeClosed + fun listDeviceSets(): HttpResponseFor = + listDeviceSets(PreviewListDeviceSetsParams.none()) + + /** @see listDeviceSets */ + @MustBeClosed + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see listDeviceSets */ + @MustBeClosed + fun listDeviceSets( + params: PreviewListDeviceSetsParams = PreviewListDeviceSetsParams.none() + ): HttpResponseFor = listDeviceSets(params, RequestOptions.none()) + + /** @see listDeviceSets */ + @MustBeClosed + fun listDeviceSets(requestOptions: RequestOptions): HttpResponseFor = + listDeviceSets(PreviewListDeviceSetsParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /previews/devices`, but is otherwise the same as + * [PreviewService.listDevices]. + */ + @MustBeClosed + fun listDevices(): HttpResponseFor = + listDevices(PreviewListDevicesParams.none()) + + /** @see listDevices */ + @MustBeClosed + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see listDevices */ + @MustBeClosed + fun listDevices( + params: PreviewListDevicesParams = PreviewListDevicesParams.none() + ): HttpResponseFor = listDevices(params, RequestOptions.none()) + + /** @see listDevices */ + @MustBeClosed + fun listDevices( + requestOptions: RequestOptions + ): HttpResponseFor = + listDevices(PreviewListDevicesParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /previews/device-sets/{deviceSetId}`, but is + * otherwise the same as [PreviewService.retrieveDeviceSet]. + */ + @MustBeClosed + fun retrieveDeviceSet(deviceSetId: String): HttpResponseFor = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none()) + + /** @see retrieveDeviceSet */ + @MustBeClosed + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieveDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see retrieveDeviceSet */ + @MustBeClosed + fun retrieveDeviceSet( + deviceSetId: String, + params: PreviewRetrieveDeviceSetParams = PreviewRetrieveDeviceSetParams.none(), + ): HttpResponseFor = + retrieveDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + @MustBeClosed + fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieveDeviceSet */ + @MustBeClosed + fun retrieveDeviceSet(params: PreviewRetrieveDeviceSetParams): HttpResponseFor = + retrieveDeviceSet(params, RequestOptions.none()) + + /** @see retrieveDeviceSet */ + @MustBeClosed + fun retrieveDeviceSet( + deviceSetId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieveDeviceSet(deviceSetId, PreviewRetrieveDeviceSetParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /previews/device-sets/{deviceSetId}`, but is + * otherwise the same as [PreviewService.updateDeviceSet]. + */ + @MustBeClosed + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + ): HttpResponseFor = updateDeviceSet(deviceSetId, params, RequestOptions.none()) + + /** @see updateDeviceSet */ + @MustBeClosed + fun updateDeviceSet( + deviceSetId: String, + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + updateDeviceSet(params.toBuilder().deviceSetId(deviceSetId).build(), requestOptions) + + /** @see updateDeviceSet */ + @MustBeClosed + fun updateDeviceSet(params: PreviewUpdateDeviceSetParams): HttpResponseFor = + updateDeviceSet(params, RequestOptions.none()) + + /** @see updateDeviceSet */ + @MustBeClosed + fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreviewServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreviewServiceImpl.kt new file mode 100644 index 00000000..e81c72e0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/PreviewServiceImpl.kt @@ -0,0 +1,276 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepare +import com.courier.models.previews.DeviceSet +import com.courier.models.previews.DeviceSetListResponse +import com.courier.models.previews.PreviewArchiveDeviceSetParams +import com.courier.models.previews.PreviewCreateDeviceSetParams +import com.courier.models.previews.PreviewDeviceListResponse +import com.courier.models.previews.PreviewListDeviceSetsParams +import com.courier.models.previews.PreviewListDevicesParams +import com.courier.models.previews.PreviewRetrieveDeviceSetParams +import com.courier.models.previews.PreviewUpdateDeviceSetParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +class PreviewServiceImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewService { + + private val withRawResponse: PreviewService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): PreviewService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): PreviewService = + PreviewServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions, + ): DeviceSet = + // delete /previews/device-sets/{deviceSetId} + withRawResponse().archiveDeviceSet(params, requestOptions).parse() + + override fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions, + ): DeviceSet = + // post /previews/device-sets + withRawResponse().createDeviceSet(params, requestOptions).parse() + + override fun listDeviceSets( + params: PreviewListDeviceSetsParams, + requestOptions: RequestOptions, + ): DeviceSetListResponse = + // get /previews/device-sets + withRawResponse().listDeviceSets(params, requestOptions).parse() + + override fun listDevices( + params: PreviewListDevicesParams, + requestOptions: RequestOptions, + ): PreviewDeviceListResponse = + // get /previews/devices + withRawResponse().listDevices(params, requestOptions).parse() + + override fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions, + ): DeviceSet = + // get /previews/device-sets/{deviceSetId} + withRawResponse().retrieveDeviceSet(params, requestOptions).parse() + + override fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions, + ): DeviceSet = + // put /previews/device-sets/{deviceSetId} + withRawResponse().updateDeviceSet(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): PreviewService.WithRawResponse = + PreviewServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val archiveDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun archiveDeviceSet( + params: PreviewArchiveDeviceSetParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("deviceSetId", params.deviceSetId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets", params._pathParam(0)) + .apply { params._body().ifPresent { body(json(clientOptions.jsonMapper, it)) } } + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { archiveDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val createDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun createDeviceSet( + params: PreviewCreateDeviceSetParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listDeviceSetsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listDeviceSets( + params: PreviewListDeviceSetsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listDeviceSetsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listDevicesHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listDevices( + params: PreviewListDevicesParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "devices") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listDevicesHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieveDeviceSet( + params: PreviewRetrieveDeviceSetParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("deviceSetId", params.deviceSetId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets", params._pathParam(0)) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateDeviceSetHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun updateDeviceSet( + params: PreviewUpdateDeviceSetParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("deviceSetId", params.deviceSetId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("previews", "device-sets", params._pathParam(0)) + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { updateDeviceSetHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/PreviewService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/PreviewService.kt new file mode 100644 index 00000000..908e8bf8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/PreviewService.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.notifications + +import com.courier.core.ClientOptions +import com.courier.services.blocking.notifications.previews.RunService +import java.util.function.Consumer + +interface PreviewService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreviewService + + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + fun runs(): RunService + + /** A view of [PreviewService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): PreviewService.WithRawResponse + + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + fun runs(): RunService.WithRawResponse + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/PreviewServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/PreviewServiceImpl.kt new file mode 100644 index 00000000..16ae4b66 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/PreviewServiceImpl.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.notifications + +import com.courier.core.ClientOptions +import com.courier.services.blocking.notifications.previews.RunService +import com.courier.services.blocking.notifications.previews.RunServiceImpl +import java.util.function.Consumer + +class PreviewServiceImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewService { + + private val withRawResponse: PreviewService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + private val runs: RunService by lazy { RunServiceImpl(clientOptions) } + + override fun withRawResponse(): PreviewService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): PreviewService = + PreviewServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + /** + * Render a template's email content on real email clients and read back the screenshots, so you + * can check how it looks before you send it. + */ + override fun runs(): RunService = runs + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + PreviewService.WithRawResponse { + + private val runs: RunService.WithRawResponse by lazy { + RunServiceImpl.WithRawResponseImpl(clientOptions) + } + + override fun withOptions( + modifier: Consumer + ): PreviewService.WithRawResponse = + PreviewServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + /** + * Render a template's email content on real email clients and read back the screenshots, so + * you can check how it looks before you send it. + */ + override fun runs(): RunService.WithRawResponse = runs + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/previews/RunService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/previews/RunService.kt new file mode 100644 index 00000000..66fb387d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/previews/RunService.kt @@ -0,0 +1,246 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.notifications.previews + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.notifications.previews.runs.PreviewRun +import com.courier.models.notifications.previews.runs.PreviewRunDetail +import com.courier.models.notifications.previews.runs.PreviewRunListResponse +import com.courier.models.notifications.previews.runs.RunCreateParams +import com.courier.models.notifications.previews.runs.RunListParams +import com.courier.models.notifications.previews.runs.RunRetrieveParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +interface RunService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunService + + /** + * Render this template's email content on each of the requested devices. + * + * Returns as soon as the run exists and its render is queued — the screenshots are produced + * asynchronously. Poll `GET /notifications/{id}/previews/runs/{previewRunId}` until every + * result reaches a terminal status. + * + * Name the devices either with `device_set_id`, for a saved set, or with `device_ids`, for a + * one-off list. Exactly one of the two is required. Inline `device_ids` must be ids listed by + * `GET /previews/devices`; any other id is a 422, refused before the run exists or is billed. + * + * A template that does not exist is a 404. One that exists but cannot be previewed — not a + * Design Studio template, no email channel, or no such `template_version` — is a 422, also + * refused before the run exists or is billed. + * + * Preview runs are a metered add-on. A workspace without it, or with its billing suspended, + * receives a 402. + */ + fun create(id: String, params: RunCreateParams): PreviewRun = + create(id, params, RequestOptions.none()) + + /** @see create */ + fun create( + id: String, + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewRun = create(params.toBuilder().id(id).build(), requestOptions) + + /** @see create */ + fun create(params: RunCreateParams): PreviewRun = create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewRun + + /** + * Retrieve one of this template's preview runs together with its per-device results. + * + * A run is only readable under the template it previewed: under any other template it is a 404, + * the same as a run that does not exist. + * + * `thumbnail_url` and `screenshot_url` are short-lived signed URLs, re-signed on every read. + * Fetch them now rather than storing them. Both are null until Courier's own copy of the image + * exists, which is what `status: COMPLETED` on a result means. + */ + fun retrieve(previewRunId: String, params: RunRetrieveParams): PreviewRunDetail = + retrieve(previewRunId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewRunDetail = + retrieve(params.toBuilder().previewRunId(previewRunId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve(params: RunRetrieveParams): PreviewRunDetail = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewRunDetail + + /** + * List this template's preview runs, newest first. Cursor-paginated. + * + * A template that does not exist is a 404, the same as every other `/notifications/{id}` route. + */ + fun list(id: String): PreviewRunListResponse = list(id, RunListParams.none()) + + /** @see list */ + fun list( + id: String, + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewRunListResponse = list(params.toBuilder().id(id).build(), requestOptions) + + /** @see list */ + fun list(id: String, params: RunListParams = RunListParams.none()): PreviewRunListResponse = + list(id, params, RequestOptions.none()) + + /** @see list */ + fun list( + params: RunListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): PreviewRunListResponse + + /** @see list */ + fun list(params: RunListParams): PreviewRunListResponse = list(params, RequestOptions.none()) + + /** @see list */ + fun list(id: String, requestOptions: RequestOptions): PreviewRunListResponse = + list(id, RunListParams.none(), requestOptions) + + /** A view of [RunService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /notifications/{id}/previews/runs`, but is + * otherwise the same as [RunService.create]. + */ + @MustBeClosed + fun create(id: String, params: RunCreateParams): HttpResponseFor = + create(id, params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + id: String, + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = create(params.toBuilder().id(id).build(), requestOptions) + + /** @see create */ + @MustBeClosed + fun create(params: RunCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: RunCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /notifications/{id}/previews/runs/{previewRunId}`, + * but is otherwise the same as [RunService.retrieve]. + */ + @MustBeClosed + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + ): HttpResponseFor = retrieve(previewRunId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + previewRunId: String, + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().previewRunId(previewRunId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RunRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /notifications/{id}/previews/runs`, but is otherwise + * the same as [RunService.list]. + */ + @MustBeClosed + fun list(id: String): HttpResponseFor = + list(id, RunListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + id: String, + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + list(params.toBuilder().id(id).build(), requestOptions) + + /** @see list */ + @MustBeClosed + fun list( + id: String, + params: RunListParams = RunListParams.none(), + ): HttpResponseFor = list(id, params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: RunListParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list(params: RunListParams): HttpResponseFor = + list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = list(id, RunListParams.none(), requestOptions) + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/previews/RunServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/previews/RunServiceImpl.kt new file mode 100644 index 00000000..8388b3a8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/notifications/previews/RunServiceImpl.kt @@ -0,0 +1,171 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.notifications.previews + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.checkRequired +import com.courier.core.handlers.errorBodyHandler +import com.courier.core.handlers.errorHandler +import com.courier.core.handlers.jsonHandler +import com.courier.core.http.HttpMethod +import com.courier.core.http.HttpRequest +import com.courier.core.http.HttpResponse +import com.courier.core.http.HttpResponse.Handler +import com.courier.core.http.HttpResponseFor +import com.courier.core.http.json +import com.courier.core.http.parseable +import com.courier.core.prepare +import com.courier.models.notifications.previews.runs.PreviewRun +import com.courier.models.notifications.previews.runs.PreviewRunDetail +import com.courier.models.notifications.previews.runs.PreviewRunListResponse +import com.courier.models.notifications.previews.runs.RunCreateParams +import com.courier.models.notifications.previews.runs.RunListParams +import com.courier.models.notifications.previews.runs.RunRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** + * Render a template's email content on real email clients and read back the screenshots, so you can + * check how it looks before you send it. + */ +class RunServiceImpl internal constructor(private val clientOptions: ClientOptions) : RunService { + + private val withRawResponse: RunService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RunService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RunService = + RunServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create(params: RunCreateParams, requestOptions: RequestOptions): PreviewRun = + // post /notifications/{id}/previews/runs + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): PreviewRunDetail = + // get /notifications/{id}/previews/runs/{previewRunId} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): PreviewRunListResponse = + // get /notifications/{id}/previews/runs + withRawResponse().list(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RunService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RunService.WithRawResponse = + RunServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: RunCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "previews", "runs") + .body(json(clientOptions.jsonMapper, params._body())) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { createHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("previewRunId", params.previewRunId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments( + "notifications", + params._pathParam(0), + "previews", + "runs", + params._pathParam(1), + ) + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("notifications", params._pathParam(0), "previews", "runs") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/CreatePreviewRunRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/CreatePreviewRunRequestTest.kt new file mode 100644 index 00000000..ec3674c1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/CreatePreviewRunRequestTest.kt @@ -0,0 +1,65 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.JsonValue +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import kotlin.jvm.optionals.getOrNull +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CreatePreviewRunRequestTest { + + @Test + fun create() { + val createPreviewRunRequest = + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("string") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + + assertThat(createPreviewRunRequest.data()) + .contains( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + assertThat(createPreviewRunRequest.deviceIds().getOrNull()).containsExactly("string") + assertThat(createPreviewRunRequest.deviceSetId()).contains("device_set_id") + assertThat(createPreviewRunRequest.locale()).contains("locale") + assertThat(createPreviewRunRequest.templateVersion()).contains("draft") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val createPreviewRunRequest = + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("string") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + + val roundtrippedCreatePreviewRunRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(createPreviewRunRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCreatePreviewRunRequest).isEqualTo(createPreviewRunRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewResultTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewResultTest.kt new file mode 100644 index 00000000..9da2722e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewResultTest.kt @@ -0,0 +1,51 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewResultTest { + + @Test + fun create() { + val previewResult = + PreviewResult.builder() + .deviceId("device_id") + .screenshotUrl("screenshot_url") + .status(PreviewResultStatus.PENDING) + .thumbnailUrl("thumbnail_url") + .failureReason(PreviewResultFailureReason.DELIVERY_FAILED) + .build() + + assertThat(previewResult.deviceId()).isEqualTo("device_id") + assertThat(previewResult.screenshotUrl()).contains("screenshot_url") + assertThat(previewResult.status()).isEqualTo(PreviewResultStatus.PENDING) + assertThat(previewResult.thumbnailUrl()).contains("thumbnail_url") + assertThat(previewResult.failureReason()) + .contains(PreviewResultFailureReason.DELIVERY_FAILED) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val previewResult = + PreviewResult.builder() + .deviceId("device_id") + .screenshotUrl("screenshot_url") + .status(PreviewResultStatus.PENDING) + .thumbnailUrl("thumbnail_url") + .failureReason(PreviewResultFailureReason.DELIVERY_FAILED) + .build() + + val roundtrippedPreviewResult = + jsonMapper.readValue( + jsonMapper.writeValueAsString(previewResult), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreviewResult).isEqualTo(previewResult) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunDetailTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunDetailTest.kt new file mode 100644 index 00000000..9a3ea1df --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunDetailTest.kt @@ -0,0 +1,85 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewRunDetailTest { + + @Test + fun create() { + val previewRunDetail = + PreviewRunDetail.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .addResult( + PreviewResult.builder() + .deviceId("device_id") + .screenshotUrl("screenshot_url") + .status(PreviewResultStatus.PENDING) + .thumbnailUrl("thumbnail_url") + .failureReason(PreviewResultFailureReason.DELIVERY_FAILED) + .build() + ) + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + + assertThat(previewRunDetail.id()).isEqualTo("id") + assertThat(previewRunDetail.createdAt()).isEqualTo("created_at") + assertThat(previewRunDetail.deviceIds()).containsExactly("string") + assertThat(previewRunDetail.results()) + .containsExactly( + PreviewResult.builder() + .deviceId("device_id") + .screenshotUrl("screenshot_url") + .status(PreviewResultStatus.PENDING) + .thumbnailUrl("thumbnail_url") + .failureReason(PreviewResultFailureReason.DELIVERY_FAILED) + .build() + ) + assertThat(previewRunDetail.status()).isEqualTo(PreviewRunStatus.PENDING) + assertThat(previewRunDetail.templateId()).isEqualTo("template_id") + assertThat(previewRunDetail.failureReason()) + .contains(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + assertThat(previewRunDetail.templateVersion()).contains("template_version") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val previewRunDetail = + PreviewRunDetail.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .addResult( + PreviewResult.builder() + .deviceId("device_id") + .screenshotUrl("screenshot_url") + .status(PreviewResultStatus.PENDING) + .thumbnailUrl("thumbnail_url") + .failureReason(PreviewResultFailureReason.DELIVERY_FAILED) + .build() + ) + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + + val roundtrippedPreviewRunDetail = + jsonMapper.readValue( + jsonMapper.writeValueAsString(previewRunDetail), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreviewRunDetail).isEqualTo(previewRunDetail) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunListResponseTest.kt new file mode 100644 index 00000000..34b093fe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunListResponseTest.kt @@ -0,0 +1,74 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.jsonMapper +import com.courier.models.Paging +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewRunListResponseTest { + + @Test + fun create() { + val previewRunListResponse = + PreviewRunListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addResult( + PreviewRun.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + ) + .build() + + assertThat(previewRunListResponse.paging()) + .isEqualTo(Paging.builder().more(true).cursor("cursor").build()) + assertThat(previewRunListResponse.results()) + .containsExactly( + PreviewRun.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val previewRunListResponse = + PreviewRunListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addResult( + PreviewRun.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + ) + .build() + + val roundtrippedPreviewRunListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(previewRunListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreviewRunListResponse).isEqualTo(previewRunListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunTest.kt new file mode 100644 index 00000000..cf0f6110 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/PreviewRunTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewRunTest { + + @Test + fun create() { + val previewRun = + PreviewRun.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + + assertThat(previewRun.id()).isEqualTo("id") + assertThat(previewRun.createdAt()).isEqualTo("created_at") + assertThat(previewRun.deviceIds()).containsExactly("string") + assertThat(previewRun.status()).isEqualTo(PreviewRunStatus.PENDING) + assertThat(previewRun.templateId()).isEqualTo("template_id") + assertThat(previewRun.failureReason()) + .contains(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + assertThat(previewRun.templateVersion()).contains("template_version") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val previewRun = + PreviewRun.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .status(PreviewRunStatus.PENDING) + .templateId("template_id") + .failureReason(PreviewRunFailureReason.TEMPLATE_NOT_SUPPORTED) + .templateVersion("template_version") + .build() + + val roundtrippedPreviewRun = + jsonMapper.readValue( + jsonMapper.writeValueAsString(previewRun), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreviewRun).isEqualTo(previewRun) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunCreateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunCreateParamsTest.kt new file mode 100644 index 00000000..a1151d1e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunCreateParamsTest.kt @@ -0,0 +1,149 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.JsonValue +import com.courier.core.http.Headers +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunCreateParamsTest { + + @Test + fun create() { + RunCreateParams.builder() + .id("id") + .idempotencyKey("order-ORD-456-user-123") + .xIdempotencyExpiration("1785312000") + .createPreviewRunRequest( + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + RunCreateParams.builder() + .id("id") + .createPreviewRunRequest(CreatePreviewRunRequest.builder().build()) + .build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun headers() { + val params = + RunCreateParams.builder() + .id("id") + .idempotencyKey("order-ORD-456-user-123") + .xIdempotencyExpiration("1785312000") + .createPreviewRunRequest( + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + ) + .build() + + val headers = params._headers() + + assertThat(headers) + .isEqualTo( + Headers.builder() + .put("Idempotency-Key", "order-ORD-456-user-123") + .put("x-idempotency-expiration", "1785312000") + .build() + ) + } + + @Test + fun headersWithoutOptionalFields() { + val params = + RunCreateParams.builder() + .id("id") + .createPreviewRunRequest(CreatePreviewRunRequest.builder().build()) + .build() + + val headers = params._headers() + + assertThat(headers).isEqualTo(Headers.builder().build()) + } + + @Test + fun body() { + val params = + RunCreateParams.builder() + .id("id") + .idempotencyKey("order-ORD-456-user-123") + .xIdempotencyExpiration("1785312000") + .createPreviewRunRequest( + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + RunCreateParams.builder() + .id("id") + .createPreviewRunRequest(CreatePreviewRunRequest.builder().build()) + .build() + + val body = params._body() + + assertThat(body).isEqualTo(CreatePreviewRunRequest.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunListParamsTest.kt new file mode 100644 index 00000000..f4f6bf5f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunListParamsTest.kt @@ -0,0 +1,43 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListParamsTest { + + @Test + fun create() { + RunListParams.builder().id("id").cursor("cursor").limit(1L).build() + } + + @Test + fun pathParams() { + val params = RunListParams.builder().id("id").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = RunListParams.builder().id("id").cursor("cursor").limit(1L).build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo(QueryParams.builder().put("cursor", "cursor").put("limit", "1").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = RunListParams.builder().id("id").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunRetrieveParamsTest.kt new file mode 100644 index 00000000..acfe7949 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/notifications/previews/runs/RunRetrieveParamsTest.kt @@ -0,0 +1,24 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.notifications.previews.runs + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunRetrieveParamsTest { + + @Test + fun create() { + RunRetrieveParams.builder().id("id").previewRunId("previewRunId").build() + } + + @Test + fun pathParams() { + val params = RunRetrieveParams.builder().id("id").previewRunId("previewRunId").build() + + assertThat(params._pathParam(0)).isEqualTo("id") + assertThat(params._pathParam(1)).isEqualTo("previewRunId") + // out-of-bound path param + assertThat(params._pathParam(2)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/CreateDeviceSetRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/CreateDeviceSetRequestTest.kt new file mode 100644 index 00000000..a604d4cd --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/CreateDeviceSetRequestTest.kt @@ -0,0 +1,35 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class CreateDeviceSetRequestTest { + + @Test + fun create() { + val createDeviceSetRequest = + CreateDeviceSetRequest.builder().addDeviceId("string").name("name").build() + + assertThat(createDeviceSetRequest.deviceIds()).containsExactly("string") + assertThat(createDeviceSetRequest.name()).isEqualTo("name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val createDeviceSetRequest = + CreateDeviceSetRequest.builder().addDeviceId("string").name("name").build() + + val roundtrippedCreateDeviceSetRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(createDeviceSetRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCreateDeviceSetRequest).isEqualTo(createDeviceSetRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/DeviceSetListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/DeviceSetListResponseTest.kt new file mode 100644 index 00000000..bbbfb96a --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/DeviceSetListResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DeviceSetListResponseTest { + + @Test + fun create() { + val deviceSetListResponse = + DeviceSetListResponse.builder() + .addResult( + DeviceSet.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .name("name") + .updatedAt("updated_at") + .archivedAt("archived_at") + .build() + ) + .build() + + assertThat(deviceSetListResponse.results()) + .containsExactly( + DeviceSet.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .name("name") + .updatedAt("updated_at") + .archivedAt("archived_at") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val deviceSetListResponse = + DeviceSetListResponse.builder() + .addResult( + DeviceSet.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .name("name") + .updatedAt("updated_at") + .archivedAt("archived_at") + .build() + ) + .build() + + val roundtrippedDeviceSetListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(deviceSetListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDeviceSetListResponse).isEqualTo(deviceSetListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/DeviceSetTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/DeviceSetTest.kt new file mode 100644 index 00000000..b9ab22f1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/DeviceSetTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class DeviceSetTest { + + @Test + fun create() { + val deviceSet = + DeviceSet.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .name("name") + .updatedAt("updated_at") + .archivedAt("archived_at") + .build() + + assertThat(deviceSet.id()).isEqualTo("id") + assertThat(deviceSet.createdAt()).isEqualTo("created_at") + assertThat(deviceSet.deviceIds()).containsExactly("string") + assertThat(deviceSet.name()).isEqualTo("name") + assertThat(deviceSet.updatedAt()).isEqualTo("updated_at") + assertThat(deviceSet.archivedAt()).contains("archived_at") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val deviceSet = + DeviceSet.builder() + .id("id") + .createdAt("created_at") + .addDeviceId("string") + .name("name") + .updatedAt("updated_at") + .archivedAt("archived_at") + .build() + + val roundtrippedDeviceSet = + jsonMapper.readValue( + jsonMapper.writeValueAsString(deviceSet), + jacksonTypeRef(), + ) + + assertThat(roundtrippedDeviceSet).isEqualTo(deviceSet) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewArchiveDeviceSetParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewArchiveDeviceSetParamsTest.kt new file mode 100644 index 00000000..e32cdeea --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewArchiveDeviceSetParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewArchiveDeviceSetParamsTest { + + @Test + fun create() { + PreviewArchiveDeviceSetParams.builder().deviceSetId("deviceSetId").build() + } + + @Test + fun pathParams() { + val params = PreviewArchiveDeviceSetParams.builder().deviceSetId("deviceSetId").build() + + assertThat(params._pathParam(0)).isEqualTo("deviceSetId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewCreateDeviceSetParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewCreateDeviceSetParamsTest.kt new file mode 100644 index 00000000..7f5f8c26 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewCreateDeviceSetParamsTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewCreateDeviceSetParamsTest { + + @Test + fun create() { + PreviewCreateDeviceSetParams.builder() + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .name("Mobile") + .build() + ) + .build() + } + + @Test + fun body() { + val params = + PreviewCreateDeviceSetParams.builder() + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .name("Mobile") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .name("Mobile") + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewDeviceListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewDeviceListResponseTest.kt new file mode 100644 index 00000000..27fdfda3 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewDeviceListResponseTest.kt @@ -0,0 +1,75 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewDeviceListResponseTest { + + @Test + fun create() { + val previewDeviceListResponse = + PreviewDeviceListResponse.builder() + .addResult( + PreviewDevice.builder() + .id("pvd_2tecf6d6pybbvvnkdr0hwdpaxf") + .app("outlook_com") + .category(PreviewDevice.Category.WEBMAIL) + .name("Outlook.com (Firefox, Windows 10, dark mode)") + .os("windows") + .osVersion("10") + .platform("firefox") + .platformVersion("15_pro_max") + .theme(PreviewDevice.Theme.LIGHT) + .build() + ) + .build() + + assertThat(previewDeviceListResponse.results()) + .containsExactly( + PreviewDevice.builder() + .id("pvd_2tecf6d6pybbvvnkdr0hwdpaxf") + .app("outlook_com") + .category(PreviewDevice.Category.WEBMAIL) + .name("Outlook.com (Firefox, Windows 10, dark mode)") + .os("windows") + .osVersion("10") + .platform("firefox") + .platformVersion("15_pro_max") + .theme(PreviewDevice.Theme.LIGHT) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val previewDeviceListResponse = + PreviewDeviceListResponse.builder() + .addResult( + PreviewDevice.builder() + .id("pvd_2tecf6d6pybbvvnkdr0hwdpaxf") + .app("outlook_com") + .category(PreviewDevice.Category.WEBMAIL) + .name("Outlook.com (Firefox, Windows 10, dark mode)") + .os("windows") + .osVersion("10") + .platform("firefox") + .platformVersion("15_pro_max") + .theme(PreviewDevice.Theme.LIGHT) + .build() + ) + .build() + + val roundtrippedPreviewDeviceListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(previewDeviceListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreviewDeviceListResponse).isEqualTo(previewDeviceListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewDeviceTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewDeviceTest.kt new file mode 100644 index 00000000..be4cb47f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewDeviceTest.kt @@ -0,0 +1,62 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import com.courier.core.jsonMapper +import com.fasterxml.jackson.module.kotlin.jacksonTypeRef +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewDeviceTest { + + @Test + fun create() { + val previewDevice = + PreviewDevice.builder() + .id("pvd_2tecf6d6pybbvvnkdr0hwdpaxf") + .app("outlook_com") + .category(PreviewDevice.Category.WEBMAIL) + .name("Outlook.com (Firefox, Windows 10, dark mode)") + .os("windows") + .osVersion("10") + .platform("firefox") + .platformVersion("15_pro_max") + .theme(PreviewDevice.Theme.LIGHT) + .build() + + assertThat(previewDevice.id()).isEqualTo("pvd_2tecf6d6pybbvvnkdr0hwdpaxf") + assertThat(previewDevice.app()).isEqualTo("outlook_com") + assertThat(previewDevice.category()).isEqualTo(PreviewDevice.Category.WEBMAIL) + assertThat(previewDevice.name()).isEqualTo("Outlook.com (Firefox, Windows 10, dark mode)") + assertThat(previewDevice.os()).isEqualTo("windows") + assertThat(previewDevice.osVersion()).isEqualTo("10") + assertThat(previewDevice.platform()).contains("firefox") + assertThat(previewDevice.platformVersion()).contains("15_pro_max") + assertThat(previewDevice.theme()).isEqualTo(PreviewDevice.Theme.LIGHT) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val previewDevice = + PreviewDevice.builder() + .id("pvd_2tecf6d6pybbvvnkdr0hwdpaxf") + .app("outlook_com") + .category(PreviewDevice.Category.WEBMAIL) + .name("Outlook.com (Firefox, Windows 10, dark mode)") + .os("windows") + .osVersion("10") + .platform("firefox") + .platformVersion("15_pro_max") + .theme(PreviewDevice.Theme.LIGHT) + .build() + + val roundtrippedPreviewDevice = + jsonMapper.readValue( + jsonMapper.writeValueAsString(previewDevice), + jacksonTypeRef(), + ) + + assertThat(roundtrippedPreviewDevice).isEqualTo(previewDevice) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewListDeviceSetsParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewListDeviceSetsParamsTest.kt new file mode 100644 index 00000000..a4bebdd6 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewListDeviceSetsParamsTest.kt @@ -0,0 +1,13 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import org.junit.jupiter.api.Test + +internal class PreviewListDeviceSetsParamsTest { + + @Test + fun create() { + PreviewListDeviceSetsParams.builder().build() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewListDevicesParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewListDevicesParamsTest.kt new file mode 100644 index 00000000..fd5ceefe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewListDevicesParamsTest.kt @@ -0,0 +1,13 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import org.junit.jupiter.api.Test + +internal class PreviewListDevicesParamsTest { + + @Test + fun create() { + PreviewListDevicesParams.builder().build() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewRetrieveDeviceSetParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewRetrieveDeviceSetParamsTest.kt new file mode 100644 index 00000000..af126b91 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewRetrieveDeviceSetParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewRetrieveDeviceSetParamsTest { + + @Test + fun create() { + PreviewRetrieveDeviceSetParams.builder().deviceSetId("deviceSetId").build() + } + + @Test + fun pathParams() { + val params = PreviewRetrieveDeviceSetParams.builder().deviceSetId("deviceSetId").build() + + assertThat(params._pathParam(0)).isEqualTo("deviceSetId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewUpdateDeviceSetParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewUpdateDeviceSetParamsTest.kt new file mode 100644 index 00000000..27187c99 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/previews/PreviewUpdateDeviceSetParamsTest.kt @@ -0,0 +1,68 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.previews + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class PreviewUpdateDeviceSetParamsTest { + + @Test + fun create() { + PreviewUpdateDeviceSetParams.builder() + .deviceSetId("deviceSetId") + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .name("Mobile and desktop") + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + PreviewUpdateDeviceSetParams.builder() + .deviceSetId("deviceSetId") + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .name("Mobile and desktop") + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("deviceSetId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + PreviewUpdateDeviceSetParams.builder() + .deviceSetId("deviceSetId") + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .name("Mobile and desktop") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .name("Mobile and desktop") + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/PreviewServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/PreviewServiceAsyncTest.kt new file mode 100644 index 00000000..770abe9f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/PreviewServiceAsyncTest.kt @@ -0,0 +1,102 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.models.previews.CreateDeviceSetRequest +import com.courier.models.previews.PreviewUpdateDeviceSetParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class PreviewServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun archiveDeviceSet() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val previewServiceAsync = client.previews() + + val deviceSetFuture = previewServiceAsync.archiveDeviceSet("deviceSetId") + + val deviceSet = deviceSetFuture.get() + deviceSet.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun createDeviceSet() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val previewServiceAsync = client.previews() + + val deviceSetFuture = + previewServiceAsync.createDeviceSet( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .name("Mobile") + .build() + ) + + val deviceSet = deviceSetFuture.get() + deviceSet.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listDeviceSets() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val previewServiceAsync = client.previews() + + val deviceSetListResponseFuture = previewServiceAsync.listDeviceSets() + + val deviceSetListResponse = deviceSetListResponseFuture.get() + deviceSetListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listDevices() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val previewServiceAsync = client.previews() + + val previewDeviceListResponseFuture = previewServiceAsync.listDevices() + + val previewDeviceListResponse = previewDeviceListResponseFuture.get() + previewDeviceListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieveDeviceSet() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val previewServiceAsync = client.previews() + + val deviceSetFuture = previewServiceAsync.retrieveDeviceSet("deviceSetId") + + val deviceSet = deviceSetFuture.get() + deviceSet.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun updateDeviceSet() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val previewServiceAsync = client.previews() + + val deviceSetFuture = + previewServiceAsync.updateDeviceSet( + PreviewUpdateDeviceSetParams.builder() + .deviceSetId("deviceSetId") + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .name("Mobile and desktop") + .build() + ) + .build() + ) + + val deviceSet = deviceSetFuture.get() + deviceSet.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/notifications/previews/RunServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/notifications/previews/RunServiceAsyncTest.kt new file mode 100644 index 00000000..d316e1d1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/notifications/previews/RunServiceAsyncTest.kt @@ -0,0 +1,78 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.notifications.previews + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.core.JsonValue +import com.courier.models.notifications.previews.runs.CreatePreviewRunRequest +import com.courier.models.notifications.previews.runs.RunCreateParams +import com.courier.models.notifications.previews.runs.RunListParams +import com.courier.models.notifications.previews.runs.RunRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RunServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.notifications().previews().runs() + + val previewRunFuture = + runServiceAsync.create( + RunCreateParams.builder() + .id("id") + .idempotencyKey("order-ORD-456-user-123") + .xIdempotencyExpiration("1785312000") + .createPreviewRunRequest( + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + ) + .build() + ) + + val previewRun = previewRunFuture.get() + previewRun.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.notifications().previews().runs() + + val previewRunDetailFuture = + runServiceAsync.retrieve( + RunRetrieveParams.builder().id("id").previewRunId("previewRunId").build() + ) + + val previewRunDetail = previewRunDetailFuture.get() + previewRunDetail.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.notifications().previews().runs() + + val previewRunListResponseFuture = + runServiceAsync.list( + RunListParams.builder().id("id").cursor("cursor").limit(1L).build() + ) + + val previewRunListResponse = previewRunListResponseFuture.get() + previewRunListResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/PreviewServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/PreviewServiceTest.kt new file mode 100644 index 00000000..5011b5f5 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/PreviewServiceTest.kt @@ -0,0 +1,96 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.models.previews.CreateDeviceSetRequest +import com.courier.models.previews.PreviewUpdateDeviceSetParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class PreviewServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun archiveDeviceSet() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val previewService = client.previews() + + val deviceSet = previewService.archiveDeviceSet("deviceSetId") + + deviceSet.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun createDeviceSet() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val previewService = client.previews() + + val deviceSet = + previewService.createDeviceSet( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .name("Mobile") + .build() + ) + + deviceSet.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listDeviceSets() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val previewService = client.previews() + + val deviceSetListResponse = previewService.listDeviceSets() + + deviceSetListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listDevices() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val previewService = client.previews() + + val previewDeviceListResponse = previewService.listDevices() + + previewDeviceListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieveDeviceSet() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val previewService = client.previews() + + val deviceSet = previewService.retrieveDeviceSet("deviceSetId") + + deviceSet.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun updateDeviceSet() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val previewService = client.previews() + + val deviceSet = + previewService.updateDeviceSet( + PreviewUpdateDeviceSetParams.builder() + .deviceSetId("deviceSetId") + .createDeviceSetRequest( + CreateDeviceSetRequest.builder() + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .name("Mobile and desktop") + .build() + ) + .build() + ) + + deviceSet.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/notifications/previews/RunServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/notifications/previews/RunServiceTest.kt new file mode 100644 index 00000000..e7900c26 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/notifications/previews/RunServiceTest.kt @@ -0,0 +1,73 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.notifications.previews + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.core.JsonValue +import com.courier.models.notifications.previews.runs.CreatePreviewRunRequest +import com.courier.models.notifications.previews.runs.RunCreateParams +import com.courier.models.notifications.previews.runs.RunListParams +import com.courier.models.notifications.previews.runs.RunRetrieveParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RunServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.notifications().previews().runs() + + val previewRun = + runService.create( + RunCreateParams.builder() + .id("id") + .idempotencyKey("order-ORD-456-user-123") + .xIdempotencyExpiration("1785312000") + .createPreviewRunRequest( + CreatePreviewRunRequest.builder() + .data( + CreatePreviewRunRequest.Data.builder() + .putAdditionalProperty("foo", JsonValue.from("bar")) + .build() + ) + .addDeviceId("pvd_1w6dgafr3aaycvv9a8bm996pkc") + .addDeviceId("pvd_34qvmj6p4dbqaa5mpys1ekt9jx") + .deviceSetId("device_set_id") + .locale("locale") + .templateVersion("draft") + .build() + ) + .build() + ) + + previewRun.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.notifications().previews().runs() + + val previewRunDetail = + runService.retrieve( + RunRetrieveParams.builder().id("id").previewRunId("previewRunId").build() + ) + + previewRunDetail.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.notifications().previews().runs() + + val previewRunListResponse = + runService.list(RunListParams.builder().id("id").cursor("cursor").limit(1L).build()) + + previewRunListResponse.validate() + } +} diff --git a/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt b/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt index 7656c852..3b10c4a0 100644 --- a/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt +++ b/courier-java-proguard-test/src/test/kotlin/com/courier/proguard/ProGuardCompatibilityTest.kt @@ -58,6 +58,7 @@ internal class ProGuardCompatibilityTest { assertThat(client.automations()).isNotNull() assertThat(client.journeys()).isNotNull() assertThat(client.broadcasts()).isNotNull() + assertThat(client.previews()).isNotNull() assertThat(client.bulk()).isNotNull() assertThat(client.brands()).isNotNull() assertThat(client.digests()).isNotNull()