diff --git a/.release-please-manifest.json b/.release-please-manifest.json index 69e5aa2..0f2463a 100644 --- a/.release-please-manifest.json +++ b/.release-please-manifest.json @@ -1,3 +1,3 @@ { - ".": "4.23.0" + ".": "4.24.0" } \ No newline at end of file diff --git a/.stats.yml b/.stats.yml index cf69b29..29ea7c7 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 136 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier/courier-47bd7f89519b4aa68b039b9a03888b689fac9d6ee763d26be0b267bbb0b2ddaa.yml -openapi_spec_hash: 67ff63b23cbfb19beac58d6e471836d3 -config_hash: b30c4b3086cd9f3da06a63b256d8c189 +configured_endpoints: 147 +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/courier/courier-ca32540df5bca42c8113de4004e7751b74bb440e3d73267e7cbad84dd3c3e82a.yml +openapi_spec_hash: 5576c8cf8e5be1f250b5dd1eb6d30571 +config_hash: c6cefb51165221f01d442a42ac4a13b9 diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ff5e7..4dd13d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 4.24.0 (2026-07-29) + +Full Changelog: [v4.23.0...v4.24.0](https://github.com/trycourier/courier-java/compare/v4.23.0...v4.24.0) + +### Features + +* **broadcasts:** document Broadcasts CRUD REST API ([#170](https://github.com/trycourier/courier-java/issues/170)) ([a0c4ddc](https://github.com/trycourier/courier-java/commit/a0c4ddc2dd43551db2684ed6ed82f8dc4a682005)) + ## 4.23.0 (2026-07-29) Full Changelog: [v4.22.0...v4.23.0](https://github.com/trycourier/courier-java/compare/v4.22.0...v4.23.0) diff --git a/build.gradle.kts b/build.gradle.kts index a4f7fe4..b4c977c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ repositories { allprojects { group = "com.courier" - version = "4.23.0" // x-release-please-version + version = "4.24.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 67b8b24..f47f046 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 @@ -8,6 +8,7 @@ import com.courier.services.blocking.AuditEventService import com.courier.services.blocking.AuthService import com.courier.services.blocking.AutomationService import com.courier.services.blocking.BrandService +import com.courier.services.blocking.BroadcastService import com.courier.services.blocking.DigestService import com.courier.services.blocking.InboundService import com.courier.services.blocking.InboxService @@ -96,6 +97,8 @@ interface CourierClient { */ fun journeys(): JourneyService + fun broadcasts(): BroadcastService + /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ fun brands(): BrandService @@ -216,6 +219,8 @@ interface CourierClient { */ fun journeys(): JourneyService.WithRawResponse + fun broadcasts(): BroadcastService.WithRawResponse + /** * Manage the logos, colors, and layout that give the templates you send a consistent look. */ 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 059eeeb..b1fe4a0 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 @@ -8,6 +8,7 @@ import com.courier.services.async.AuditEventServiceAsync import com.courier.services.async.AuthServiceAsync import com.courier.services.async.AutomationServiceAsync import com.courier.services.async.BrandServiceAsync +import com.courier.services.async.BroadcastServiceAsync import com.courier.services.async.DigestServiceAsync import com.courier.services.async.InboundServiceAsync import com.courier.services.async.InboxServiceAsync @@ -96,6 +97,8 @@ interface CourierClientAsync { */ fun journeys(): JourneyServiceAsync + fun broadcasts(): BroadcastServiceAsync + /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ fun brands(): BrandServiceAsync @@ -220,6 +223,8 @@ interface CourierClientAsync { */ fun journeys(): JourneyServiceAsync.WithRawResponse + fun broadcasts(): BroadcastServiceAsync.WithRawResponse + /** * Manage the logos, colors, and layout that give the templates you send a consistent look. */ 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 5078f39..8b34654 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 @@ -14,6 +14,8 @@ import com.courier.services.async.AutomationServiceAsync import com.courier.services.async.AutomationServiceAsyncImpl import com.courier.services.async.BrandServiceAsync import com.courier.services.async.BrandServiceAsyncImpl +import com.courier.services.async.BroadcastServiceAsync +import com.courier.services.async.BroadcastServiceAsyncImpl import com.courier.services.async.DigestServiceAsync import com.courier.services.async.DigestServiceAsyncImpl import com.courier.services.async.InboundServiceAsync @@ -89,6 +91,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier JourneyServiceAsyncImpl(clientOptionsWithUserAgent) } + private val broadcasts: BroadcastServiceAsync by lazy { + BroadcastServiceAsyncImpl(clientOptionsWithUserAgent) + } + private val brands: BrandServiceAsync by lazy { BrandServiceAsyncImpl(clientOptionsWithUserAgent) } @@ -182,6 +188,8 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier */ override fun journeys(): JourneyServiceAsync = journeys + override fun broadcasts(): BroadcastServiceAsync = broadcasts + /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ override fun brands(): BrandServiceAsync = brands @@ -276,6 +284,10 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier JourneyServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val broadcasts: BroadcastServiceAsync.WithRawResponse by lazy { + BroadcastServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + private val brands: BrandServiceAsync.WithRawResponse by lazy { BrandServiceAsyncImpl.WithRawResponseImpl(clientOptions) } @@ -375,6 +387,8 @@ class CourierClientAsyncImpl(private val clientOptions: ClientOptions) : Courier */ override fun journeys(): JourneyServiceAsync.WithRawResponse = journeys + override fun broadcasts(): BroadcastServiceAsync.WithRawResponse = broadcasts + /** * Manage the logos, colors, and layout that give the templates you send a consistent look. */ 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 48fcf0b..1594a81 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 @@ -14,6 +14,8 @@ import com.courier.services.blocking.AutomationService import com.courier.services.blocking.AutomationServiceImpl import com.courier.services.blocking.BrandService import com.courier.services.blocking.BrandServiceImpl +import com.courier.services.blocking.BroadcastService +import com.courier.services.blocking.BroadcastServiceImpl import com.courier.services.blocking.DigestService import com.courier.services.blocking.DigestServiceImpl import com.courier.services.blocking.InboundService @@ -87,6 +89,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien private val journeys: JourneyService by lazy { JourneyServiceImpl(clientOptionsWithUserAgent) } + private val broadcasts: BroadcastService by lazy { + BroadcastServiceImpl(clientOptionsWithUserAgent) + } + private val brands: BrandService by lazy { BrandServiceImpl(clientOptionsWithUserAgent) } private val digests: DigestService by lazy { DigestServiceImpl(clientOptionsWithUserAgent) } @@ -164,6 +170,8 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien */ override fun journeys(): JourneyService = journeys + override fun broadcasts(): BroadcastService = broadcasts + /** Manage the logos, colors, and layout that give the templates you send a consistent look. */ override fun brands(): BrandService = brands @@ -258,6 +266,10 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien JourneyServiceImpl.WithRawResponseImpl(clientOptions) } + private val broadcasts: BroadcastService.WithRawResponse by lazy { + BroadcastServiceImpl.WithRawResponseImpl(clientOptions) + } + private val brands: BrandService.WithRawResponse by lazy { BrandServiceImpl.WithRawResponseImpl(clientOptions) } @@ -357,6 +369,8 @@ class CourierClientImpl(private val clientOptions: ClientOptions) : CourierClien */ override fun journeys(): JourneyService.WithRawResponse = journeys + override fun broadcasts(): BroadcastService.WithRawResponse = broadcasts + /** * Manage the logos, colors, and layout that give the templates you send a consistent look. */ diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/Broadcast.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/Broadcast.kt new file mode 100644 index 0000000..d1ec55e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/Broadcast.kt @@ -0,0 +1,902 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** + * A broadcast — a single-channel message delivered to a known set of recipients (a list or + * audience). + */ +class Broadcast +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val id: JsonField, + private val channel: JsonField, + private val createdAt: JsonField, + private val createdBy: JsonField, + private val name: JsonField, + private val status: JsonField, + private val updatedAt: JsonField, + private val updatedBy: JsonField, + private val archivedAt: JsonField, + private val archivedBy: JsonField, + private val schedule: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("channel") @ExcludeMissing channel: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("created_by") @ExcludeMissing createdBy: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + @JsonProperty("updated_by") @ExcludeMissing updatedBy: JsonField = JsonMissing.of(), + @JsonProperty("archived_at") + @ExcludeMissing + archivedAt: JsonField = JsonMissing.of(), + @JsonProperty("archived_by") + @ExcludeMissing + archivedBy: JsonField = JsonMissing.of(), + @JsonProperty("schedule") + @ExcludeMissing + schedule: JsonField = JsonMissing.of(), + ) : this( + id, + channel, + createdAt, + createdBy, + name, + status, + updatedAt, + updatedBy, + archivedAt, + archivedBy, + schedule, + mutableMapOf(), + ) + + /** + * The broadcast ID (bst_ prefix). + * + * @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 broadcast's delivery channel. + * + * @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 channel(): Channel = channel.getRequired("channel") + + /** + * ISO 8601 timestamp when the broadcast 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") + + /** + * Actor that created the broadcast. + * + * @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 createdBy(): String = createdBy.getRequired("created_by") + + /** + * 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") + + /** + * Lifecycle status of the broadcast. + * + * @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(): Status = status.getRequired("status") + + /** + * ISO 8601 timestamp of the last update. + * + * @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") + + /** + * Actor that last updated the broadcast. + * + * @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 updatedBy(): String = updatedBy.getRequired("updated_by") + + /** + * ISO 8601 timestamp when the broadcast was archived, if archived. + * + * @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") + + /** + * Actor that archived the broadcast, if archived. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun archivedBy(): Optional = archivedBy.getOptional("archived_by") + + /** + * The delivery schedule and recipient targeting for a broadcast. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun schedule(): Optional = schedule.getOptional("schedule") + + /** + * 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 [channel]. + * + * Unlike [channel], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channel") @ExcludeMissing fun _channel(): JsonField = channel + + /** + * 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 [createdBy]. + * + * Unlike [createdBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("created_by") @ExcludeMissing fun _createdBy(): JsonField = createdBy + + /** + * 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 [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 [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 [updatedBy]. + * + * Unlike [updatedBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_by") @ExcludeMissing fun _updatedBy(): JsonField = updatedBy + + /** + * 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 + + /** + * Returns the raw JSON value of [archivedBy]. + * + * Unlike [archivedBy], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("archived_by") @ExcludeMissing fun _archivedBy(): JsonField = archivedBy + + /** + * Returns the raw JSON value of [schedule]. + * + * Unlike [schedule], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("schedule") + @ExcludeMissing + fun _schedule(): JsonField = schedule + + @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 [Broadcast]. + * + * The following fields are required: + * ```java + * .id() + * .channel() + * .createdAt() + * .createdBy() + * .name() + * .status() + * .updatedAt() + * .updatedBy() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [Broadcast]. */ + class Builder internal constructor() { + + private var id: JsonField? = null + private var channel: JsonField? = null + private var createdAt: JsonField? = null + private var createdBy: JsonField? = null + private var name: JsonField? = null + private var status: JsonField? = null + private var updatedAt: JsonField? = null + private var updatedBy: JsonField? = null + private var archivedAt: JsonField = JsonMissing.of() + private var archivedBy: JsonField = JsonMissing.of() + private var schedule: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(broadcast: Broadcast) = apply { + id = broadcast.id + channel = broadcast.channel + createdAt = broadcast.createdAt + createdBy = broadcast.createdBy + name = broadcast.name + status = broadcast.status + updatedAt = broadcast.updatedAt + updatedBy = broadcast.updatedBy + archivedAt = broadcast.archivedAt + archivedBy = broadcast.archivedBy + schedule = broadcast.schedule + additionalProperties = broadcast.additionalProperties.toMutableMap() + } + + /** The broadcast ID (bst_ prefix). */ + 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 broadcast's delivery channel. */ + fun channel(channel: Channel) = channel(JsonField.of(channel)) + + /** + * Sets [Builder.channel] to an arbitrary JSON value. + * + * You should usually call [Builder.channel] with a well-typed [Channel] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun channel(channel: JsonField) = apply { this.channel = channel } + + /** ISO 8601 timestamp when the broadcast 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 } + + /** Actor that created the broadcast. */ + fun createdBy(createdBy: String) = createdBy(JsonField.of(createdBy)) + + /** + * Sets [Builder.createdBy] to an arbitrary JSON value. + * + * You should usually call [Builder.createdBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdBy(createdBy: JsonField) = apply { this.createdBy = createdBy } + + /** 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 } + + /** Lifecycle status of the broadcast. */ + fun status(status: Status) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [Status] 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 } + + /** ISO 8601 timestamp of the last update. */ + 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 } + + /** Actor that last updated the broadcast. */ + fun updatedBy(updatedBy: String) = updatedBy(JsonField.of(updatedBy)) + + /** + * Sets [Builder.updatedBy] to an arbitrary JSON value. + * + * You should usually call [Builder.updatedBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun updatedBy(updatedBy: JsonField) = apply { this.updatedBy = updatedBy } + + /** ISO 8601 timestamp when the broadcast was archived, if archived. */ + fun archivedAt(archivedAt: String?) = archivedAt(JsonField.ofNullable(archivedAt)) + + /** Alias for calling [Builder.archivedAt] with `archivedAt.orElse(null)`. */ + fun archivedAt(archivedAt: Optional) = archivedAt(archivedAt.getOrNull()) + + /** + * 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 } + + /** Actor that archived the broadcast, if archived. */ + fun archivedBy(archivedBy: String?) = archivedBy(JsonField.ofNullable(archivedBy)) + + /** Alias for calling [Builder.archivedBy] with `archivedBy.orElse(null)`. */ + fun archivedBy(archivedBy: Optional) = archivedBy(archivedBy.getOrNull()) + + /** + * Sets [Builder.archivedBy] to an arbitrary JSON value. + * + * You should usually call [Builder.archivedBy] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun archivedBy(archivedBy: JsonField) = apply { this.archivedBy = archivedBy } + + /** The delivery schedule and recipient targeting for a broadcast. */ + fun schedule(schedule: BroadcastSchedule?) = schedule(JsonField.ofNullable(schedule)) + + /** Alias for calling [Builder.schedule] with `schedule.orElse(null)`. */ + fun schedule(schedule: Optional) = schedule(schedule.getOrNull()) + + /** + * Sets [Builder.schedule] to an arbitrary JSON value. + * + * You should usually call [Builder.schedule] with a well-typed [BroadcastSchedule] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun schedule(schedule: JsonField) = apply { this.schedule = schedule } + + 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 [Broadcast]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .id() + * .channel() + * .createdAt() + * .createdBy() + * .name() + * .status() + * .updatedAt() + * .updatedBy() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): Broadcast = + Broadcast( + checkRequired("id", id), + checkRequired("channel", channel), + checkRequired("createdAt", createdAt), + checkRequired("createdBy", createdBy), + checkRequired("name", name), + checkRequired("status", status), + checkRequired("updatedAt", updatedAt), + checkRequired("updatedBy", updatedBy), + archivedAt, + archivedBy, + schedule, + 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(): Broadcast = apply { + if (validated) { + return@apply + } + + id() + channel().validate() + createdAt() + createdBy() + name() + status().validate() + updatedAt() + updatedBy() + archivedAt() + archivedBy() + schedule().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 (id.asKnown().isPresent) 1 else 0) + + (channel.asKnown().getOrNull()?.validity() ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (createdBy.asKnown().isPresent) 1 else 0) + + (if (name.asKnown().isPresent) 1 else 0) + + (status.asKnown().getOrNull()?.validity() ?: 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + (if (updatedBy.asKnown().isPresent) 1 else 0) + + (if (archivedAt.asKnown().isPresent) 1 else 0) + + (if (archivedBy.asKnown().isPresent) 1 else 0) + + (schedule.asKnown().getOrNull()?.validity() ?: 0) + + /** The broadcast's delivery channel. */ + class Channel @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 EMAIL = of("email") + + @JvmField val SMS = of("sms") + + @JvmField val PUSH = of("push") + + @JvmField val INBOX = of("inbox") + + @JvmField val SLACK = of("slack") + + @JvmField val MSTEAMS = of("msteams") + + @JvmStatic fun of(value: String) = Channel(JsonField.of(value)) + } + + /** An enum containing [Channel]'s known values. */ + enum class Known { + EMAIL, + SMS, + PUSH, + INBOX, + SLACK, + MSTEAMS, + } + + /** + * An enum containing [Channel]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Channel] 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 { + EMAIL, + SMS, + PUSH, + INBOX, + SLACK, + MSTEAMS, + /** An enum member indicating that [Channel] 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) { + EMAIL -> Value.EMAIL + SMS -> Value.SMS + PUSH -> Value.PUSH + INBOX -> Value.INBOX + SLACK -> Value.SLACK + MSTEAMS -> Value.MSTEAMS + 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) { + EMAIL -> Known.EMAIL + SMS -> Known.SMS + PUSH -> Known.PUSH + INBOX -> Known.INBOX + SLACK -> Known.SLACK + MSTEAMS -> Known.MSTEAMS + else -> throw CourierInvalidDataException("Unknown Channel: $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(): Channel = 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 Channel && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + /** Lifecycle status of the broadcast. */ + class Status @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 DRAFT = of("draft") + + @JvmField val SCHEDULED = of("scheduled") + + @JvmField val SENDING = of("sending") + + @JvmField val SENT = of("sent") + + @JvmStatic fun of(value: String) = Status(JsonField.of(value)) + } + + /** An enum containing [Status]'s known values. */ + enum class Known { + DRAFT, + SCHEDULED, + SENDING, + SENT, + } + + /** + * An enum containing [Status]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Status] 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 { + DRAFT, + SCHEDULED, + SENDING, + SENT, + /** An enum member indicating that [Status] 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) { + DRAFT -> Value.DRAFT + SCHEDULED -> Value.SCHEDULED + SENDING -> Value.SENDING + SENT -> Value.SENT + 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) { + DRAFT -> Known.DRAFT + SCHEDULED -> Known.SCHEDULED + SENDING -> Known.SENDING + SENT -> Known.SENT + else -> throw CourierInvalidDataException("Unknown Status: $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(): Status = 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 Status && 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 Broadcast && + id == other.id && + channel == other.channel && + createdAt == other.createdAt && + createdBy == other.createdBy && + name == other.name && + status == other.status && + updatedAt == other.updatedAt && + updatedBy == other.updatedBy && + archivedAt == other.archivedAt && + archivedBy == other.archivedBy && + schedule == other.schedule && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash( + id, + channel, + createdAt, + createdBy, + name, + status, + updatedAt, + updatedBy, + archivedAt, + archivedBy, + schedule, + additionalProperties, + ) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "Broadcast{id=$id, channel=$channel, createdAt=$createdAt, createdBy=$createdBy, name=$name, status=$status, updatedAt=$updatedAt, updatedBy=$updatedBy, archivedAt=$archivedAt, archivedBy=$archivedBy, schedule=$schedule, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastArchiveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastArchiveParams.kt new file mode 100644 index 0000000..cf894ec --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastArchiveParams.kt @@ -0,0 +1,238 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 broadcast. This is a soft delete — the archived broadcast is returned and no longer + * appears in list results. + */ +class BroadcastArchiveParams +private constructor( + private val broadcastId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** 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(): BroadcastArchiveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [BroadcastArchiveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastArchiveParams]. */ + class Builder internal constructor() { + + private var broadcastId: 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(broadcastArchiveParams: BroadcastArchiveParams) = apply { + broadcastId = broadcastArchiveParams.broadcastId + additionalHeaders = broadcastArchiveParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastArchiveParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + broadcastArchiveParams.additionalBodyProperties.toMutableMap() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.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 [BroadcastArchiveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BroadcastArchiveParams = + BroadcastArchiveParams( + broadcastId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastArchiveParams && + broadcastId == other.broadcastId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + broadcastId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "BroadcastArchiveParams{broadcastId=$broadcastId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastCancelParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastCancelParams.kt new file mode 100644 index 0000000..21cbbfc --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastCancelParams.kt @@ -0,0 +1,237 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** + * Cancel a broadcast's pending schedule, returning it to the draft state. Only valid for a + * scheduled broadcast. + */ +class BroadcastCancelParams +private constructor( + private val broadcastId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** 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(): BroadcastCancelParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [BroadcastCancelParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastCancelParams]. */ + class Builder internal constructor() { + + private var broadcastId: 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(broadcastCancelParams: BroadcastCancelParams) = apply { + broadcastId = broadcastCancelParams.broadcastId + additionalHeaders = broadcastCancelParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastCancelParams.additionalQueryParams.toBuilder() + additionalBodyProperties = broadcastCancelParams.additionalBodyProperties.toMutableMap() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.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 [BroadcastCancelParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BroadcastCancelParams = + BroadcastCancelParams( + broadcastId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastCancelParams && + broadcastId == other.broadcastId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + broadcastId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "BroadcastCancelParams{broadcastId=$broadcastId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastCreateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastCreateParams.kt new file mode 100644 index 0000000..46c2fcd --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastCreateParams.kt @@ -0,0 +1,209 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 broadcast. Provisions a private notification template for the broadcast and returns the + * new broadcast in the draft state. Exactly one channel is required. + */ +class BroadcastCreateParams +private constructor( + private val createBroadcastRequest: CreateBroadcastRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** Request body for creating a broadcast. */ + fun createBroadcastRequest(): CreateBroadcastRequest = createBroadcastRequest + + fun _additionalBodyProperties(): Map = + createBroadcastRequest._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 [BroadcastCreateParams]. + * + * The following fields are required: + * ```java + * .createBroadcastRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastCreateParams]. */ + class Builder internal constructor() { + + private var createBroadcastRequest: CreateBroadcastRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastCreateParams: BroadcastCreateParams) = apply { + createBroadcastRequest = broadcastCreateParams.createBroadcastRequest + additionalHeaders = broadcastCreateParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastCreateParams.additionalQueryParams.toBuilder() + } + + /** Request body for creating a broadcast. */ + fun createBroadcastRequest(createBroadcastRequest: CreateBroadcastRequest) = apply { + this.createBroadcastRequest = createBroadcastRequest + } + + 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 [BroadcastCreateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .createBroadcastRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BroadcastCreateParams = + BroadcastCreateParams( + checkRequired("createBroadcastRequest", createBroadcastRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): CreateBroadcastRequest = createBroadcastRequest + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BroadcastCreateParams && + createBroadcastRequest == other.createBroadcastRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(createBroadcastRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "BroadcastCreateParams{createBroadcastRequest=$createBroadcastRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastDuplicateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastDuplicateParams.kt new file mode 100644 index 0000000..a89287e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastDuplicateParams.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** Duplicate a broadcast (and its template) into a new draft named "{source name} (copy)". */ +class BroadcastDuplicateParams +private constructor( + private val broadcastId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, + private val additionalBodyProperties: Map, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** 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(): BroadcastDuplicateParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [BroadcastDuplicateParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastDuplicateParams]. */ + class Builder internal constructor() { + + private var broadcastId: 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(broadcastDuplicateParams: BroadcastDuplicateParams) = apply { + broadcastId = broadcastDuplicateParams.broadcastId + additionalHeaders = broadcastDuplicateParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastDuplicateParams.additionalQueryParams.toBuilder() + additionalBodyProperties = + broadcastDuplicateParams.additionalBodyProperties.toMutableMap() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.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 [BroadcastDuplicateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BroadcastDuplicateParams = + BroadcastDuplicateParams( + broadcastId, + additionalHeaders.build(), + additionalQueryParams.build(), + additionalBodyProperties.toImmutable(), + ) + } + + fun _body(): Optional> = + Optional.ofNullable(additionalBodyProperties.ifEmpty { null }) + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastDuplicateParams && + broadcastId == other.broadcastId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams && + additionalBodyProperties == other.additionalBodyProperties + } + + override fun hashCode(): Int = + Objects.hash( + broadcastId, + additionalHeaders, + additionalQueryParams, + additionalBodyProperties, + ) + + override fun toString() = + "BroadcastDuplicateParams{broadcastId=$broadcastId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams, additionalBodyProperties=$additionalBodyProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastListParams.kt new file mode 100644 index 0000000..7ee367e --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastListParams.kt @@ -0,0 +1,218 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 broadcasts in your workspace. Cursor-paginated; returns broadcasts newest-first. */ +class BroadcastListParams +private constructor( + private val cursor: String?, + private val limit: Long?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** 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(): BroadcastListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [BroadcastListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastListParams]. */ + class Builder internal constructor() { + + 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(broadcastListParams: BroadcastListParams) = apply { + cursor = broadcastListParams.cursor + limit = broadcastListParams.limit + additionalHeaders = broadcastListParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastListParams.additionalQueryParams.toBuilder() + } + + /** 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 [BroadcastListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BroadcastListParams = + BroadcastListParams( + cursor, + limit, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + 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 BroadcastListParams && + cursor == other.cursor && + limit == other.limit && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(cursor, limit, additionalHeaders, additionalQueryParams) + + override fun toString() = + "BroadcastListParams{cursor=$cursor, limit=$limit, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastListResponse.kt new file mode 100644 index 0000000..634deab --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastListResponse.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 broadcasts. */ +class BroadcastListResponse +@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 [BroadcastListResponse]. + * + * The following fields are required: + * ```java + * .paging() + * .results() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastListResponse]. */ + class Builder internal constructor() { + + private var paging: JsonField? = null + private var results: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(broadcastListResponse: BroadcastListResponse) = apply { + paging = broadcastListResponse.paging + results = broadcastListResponse.results.map { it.toMutableList() } + additionalProperties = broadcastListResponse.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 [Broadcast] to [results]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addResult(result: Broadcast) = 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 [BroadcastListResponse]. + * + * 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(): BroadcastListResponse = + BroadcastListResponse( + 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(): BroadcastListResponse = 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 BroadcastListResponse && + 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() = + "BroadcastListResponse{paging=$paging, results=$results, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastPutContentParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastPutContentParams.kt new file mode 100644 index 0000000..4ab3a89 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastPutContentParams.kt @@ -0,0 +1,237 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 com.courier.models.notifications.NotificationContentPutRequest +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Author the broadcast's content by replacing the draft elemental content of its private + * notification template. The draft is published automatically when the broadcast is sent or + * scheduled. + */ +class BroadcastPutContentParams +private constructor( + private val broadcastId: String?, + private val notificationContentPutRequest: NotificationContentPutRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** Request body for replacing the elemental content of a notification template. */ + fun notificationContentPutRequest(): NotificationContentPutRequest = + notificationContentPutRequest + + fun _additionalBodyProperties(): Map = + notificationContentPutRequest._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 [BroadcastPutContentParams]. + * + * The following fields are required: + * ```java + * .notificationContentPutRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastPutContentParams]. */ + class Builder internal constructor() { + + private var broadcastId: String? = null + private var notificationContentPutRequest: NotificationContentPutRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastPutContentParams: BroadcastPutContentParams) = apply { + broadcastId = broadcastPutContentParams.broadcastId + notificationContentPutRequest = broadcastPutContentParams.notificationContentPutRequest + additionalHeaders = broadcastPutContentParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastPutContentParams.additionalQueryParams.toBuilder() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.getOrNull()) + + /** Request body for replacing the elemental content of a notification template. */ + fun notificationContentPutRequest( + notificationContentPutRequest: NotificationContentPutRequest + ) = apply { this.notificationContentPutRequest = notificationContentPutRequest } + + 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 [BroadcastPutContentParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .notificationContentPutRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BroadcastPutContentParams = + BroadcastPutContentParams( + broadcastId, + checkRequired("notificationContentPutRequest", notificationContentPutRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): NotificationContentPutRequest = notificationContentPutRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastPutContentParams && + broadcastId == other.broadcastId && + notificationContentPutRequest == other.notificationContentPutRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + broadcastId, + notificationContentPutRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "BroadcastPutContentParams{broadcastId=$broadcastId, notificationContentPutRequest=$notificationContentPutRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastRetrieveContentParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastRetrieveContentParams.kt new file mode 100644 index 0000000..0e8a72c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastRetrieveContentParams.kt @@ -0,0 +1,221 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 the broadcast's content — the elemental content of its private notification template. + * Defaults to the working draft, since broadcast content is authored as a draft until the broadcast + * is sent. + */ +class BroadcastRetrieveContentParams +private constructor( + private val broadcastId: String?, + private val version: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** Accepts `draft`, `published`, or a version string (e.g. `v001`). Defaults to `draft`. */ + fun version(): Optional = Optional.ofNullable(version) + + /** 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(): BroadcastRetrieveContentParams = builder().build() + + /** + * Returns a mutable builder for constructing an instance of + * [BroadcastRetrieveContentParams]. + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastRetrieveContentParams]. */ + class Builder internal constructor() { + + private var broadcastId: String? = null + private var version: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastRetrieveContentParams: BroadcastRetrieveContentParams) = apply { + broadcastId = broadcastRetrieveContentParams.broadcastId + version = broadcastRetrieveContentParams.version + additionalHeaders = broadcastRetrieveContentParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastRetrieveContentParams.additionalQueryParams.toBuilder() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.getOrNull()) + + /** Accepts `draft`, `published`, or a version string (e.g. `v001`). Defaults to `draft`. */ + fun version(version: String?) = apply { this.version = version } + + /** Alias for calling [Builder.version] with `version.orElse(null)`. */ + fun version(version: Optional) = version(version.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 [BroadcastRetrieveContentParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BroadcastRetrieveContentParams = + BroadcastRetrieveContentParams( + broadcastId, + version, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + version?.let { put("version", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is BroadcastRetrieveContentParams && + broadcastId == other.broadcastId && + version == other.version && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(broadcastId, version, additionalHeaders, additionalQueryParams) + + override fun toString() = + "BroadcastRetrieveContentParams{broadcastId=$broadcastId, version=$version, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastRetrieveParams.kt new file mode 100644 index 0000000..230a2dc --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastRetrieveParams.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 broadcast by ID. Archived broadcasts return 404. */ +class BroadcastRetrieveParams +private constructor( + private val broadcastId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** 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(): BroadcastRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [BroadcastRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastRetrieveParams]. */ + class Builder internal constructor() { + + private var broadcastId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastRetrieveParams: BroadcastRetrieveParams) = apply { + broadcastId = broadcastRetrieveParams.broadcastId + additionalHeaders = broadcastRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastRetrieveParams.additionalQueryParams.toBuilder() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.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 [BroadcastRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): BroadcastRetrieveParams = + BroadcastRetrieveParams( + broadcastId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastRetrieveParams && + broadcastId == other.broadcastId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(broadcastId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "BroadcastRetrieveParams{broadcastId=$broadcastId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastSchedule.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastSchedule.kt new file mode 100644 index 0000000..f773b9f --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastSchedule.kt @@ -0,0 +1,458 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** The delivery schedule and recipient targeting for a broadcast. */ +class BroadcastSchedule +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val recipientId: JsonField, + private val recipientType: JsonField, + private val scheduledTo: JsonField, + private val timezone: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("recipient_id") + @ExcludeMissing + recipientId: JsonField = JsonMissing.of(), + @JsonProperty("recipient_type") + @ExcludeMissing + recipientType: JsonField = JsonMissing.of(), + @JsonProperty("scheduled_to") + @ExcludeMissing + scheduledTo: JsonField = JsonMissing.of(), + @JsonProperty("timezone") @ExcludeMissing timezone: JsonField = JsonMissing.of(), + ) : this(recipientId, recipientType, scheduledTo, timezone, mutableMapOf()) + + /** + * ID of the target list or audience. + * + * @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 recipientId(): String = recipientId.getRequired("recipient_id") + + /** + * Whether the broadcast targets a list or an audience. + * + * @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 recipientType(): RecipientType = recipientType.getRequired("recipient_type") + + /** + * Wall-clock timestamp of the scheduled send, no timezone offset (e.g. "2026-07-21T20:00:00"). + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun scheduledTo(): Optional = scheduledTo.getOptional("scheduled_to") + + /** + * IANA timezone for the scheduled send (e.g. America/New_York). + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun timezone(): Optional = timezone.getOptional("timezone") + + /** + * Returns the raw JSON value of [recipientId]. + * + * Unlike [recipientId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipient_id") + @ExcludeMissing + fun _recipientId(): JsonField = recipientId + + /** + * Returns the raw JSON value of [recipientType]. + * + * Unlike [recipientType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipient_type") + @ExcludeMissing + fun _recipientType(): JsonField = recipientType + + /** + * Returns the raw JSON value of [scheduledTo]. + * + * Unlike [scheduledTo], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scheduled_to") + @ExcludeMissing + fun _scheduledTo(): JsonField = scheduledTo + + /** + * Returns the raw JSON value of [timezone]. + * + * Unlike [timezone], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("timezone") @ExcludeMissing fun _timezone(): JsonField = timezone + + @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 [BroadcastSchedule]. + * + * The following fields are required: + * ```java + * .recipientId() + * .recipientType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastSchedule]. */ + class Builder internal constructor() { + + private var recipientId: JsonField? = null + private var recipientType: JsonField? = null + private var scheduledTo: JsonField = JsonMissing.of() + private var timezone: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(broadcastSchedule: BroadcastSchedule) = apply { + recipientId = broadcastSchedule.recipientId + recipientType = broadcastSchedule.recipientType + scheduledTo = broadcastSchedule.scheduledTo + timezone = broadcastSchedule.timezone + additionalProperties = broadcastSchedule.additionalProperties.toMutableMap() + } + + /** ID of the target list or audience. */ + fun recipientId(recipientId: String) = recipientId(JsonField.of(recipientId)) + + /** + * Sets [Builder.recipientId] to an arbitrary JSON value. + * + * You should usually call [Builder.recipientId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun recipientId(recipientId: JsonField) = apply { this.recipientId = recipientId } + + /** Whether the broadcast targets a list or an audience. */ + fun recipientType(recipientType: RecipientType) = recipientType(JsonField.of(recipientType)) + + /** + * Sets [Builder.recipientType] to an arbitrary JSON value. + * + * You should usually call [Builder.recipientType] with a well-typed [RecipientType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipientType(recipientType: JsonField) = apply { + this.recipientType = recipientType + } + + /** + * Wall-clock timestamp of the scheduled send, no timezone offset (e.g. + * "2026-07-21T20:00:00"). + */ + fun scheduledTo(scheduledTo: String?) = scheduledTo(JsonField.ofNullable(scheduledTo)) + + /** Alias for calling [Builder.scheduledTo] with `scheduledTo.orElse(null)`. */ + fun scheduledTo(scheduledTo: Optional) = scheduledTo(scheduledTo.getOrNull()) + + /** + * Sets [Builder.scheduledTo] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduledTo] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun scheduledTo(scheduledTo: JsonField) = apply { this.scheduledTo = scheduledTo } + + /** IANA timezone for the scheduled send (e.g. America/New_York). */ + fun timezone(timezone: String?) = timezone(JsonField.ofNullable(timezone)) + + /** Alias for calling [Builder.timezone] with `timezone.orElse(null)`. */ + fun timezone(timezone: Optional) = timezone(timezone.getOrNull()) + + /** + * Sets [Builder.timezone] to an arbitrary JSON value. + * + * You should usually call [Builder.timezone] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun timezone(timezone: JsonField) = apply { this.timezone = timezone } + + 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 [BroadcastSchedule]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipientId() + * .recipientType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BroadcastSchedule = + BroadcastSchedule( + checkRequired("recipientId", recipientId), + checkRequired("recipientType", recipientType), + scheduledTo, + timezone, + 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(): BroadcastSchedule = apply { + if (validated) { + return@apply + } + + recipientId() + recipientType().validate() + scheduledTo() + timezone() + 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 (recipientId.asKnown().isPresent) 1 else 0) + + (recipientType.asKnown().getOrNull()?.validity() ?: 0) + + (if (scheduledTo.asKnown().isPresent) 1 else 0) + + (if (timezone.asKnown().isPresent) 1 else 0) + + /** Whether the broadcast targets a list or an audience. */ + class RecipientType @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 LIST = of("list") + + @JvmField val AUDIENCE = of("audience") + + @JvmStatic fun of(value: String) = RecipientType(JsonField.of(value)) + } + + /** An enum containing [RecipientType]'s known values. */ + enum class Known { + LIST, + AUDIENCE, + } + + /** + * An enum containing [RecipientType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RecipientType] 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 { + LIST, + AUDIENCE, + /** + * An enum member indicating that [RecipientType] 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) { + LIST -> Value.LIST + AUDIENCE -> Value.AUDIENCE + 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) { + LIST -> Known.LIST + AUDIENCE -> Known.AUDIENCE + else -> throw CourierInvalidDataException("Unknown RecipientType: $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(): RecipientType = 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 RecipientType && 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 BroadcastSchedule && + recipientId == other.recipientId && + recipientType == other.recipientType && + scheduledTo == other.scheduledTo && + timezone == other.timezone && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipientId, recipientType, scheduledTo, timezone, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "BroadcastSchedule{recipientId=$recipientId, recipientType=$recipientType, scheduledTo=$scheduledTo, timezone=$timezone, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastScheduleParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastScheduleParams.kt new file mode 100644 index 0000000..379a042 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastScheduleParams.kt @@ -0,0 +1,235 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** + * Schedule a broadcast for a future send to a list or audience. Publishes the broadcast template + * first. Not allowed once the broadcast is sending or sent. For an immediate send use POST + * /broadcasts/{broadcastId}/send. + */ +class BroadcastScheduleParams +private constructor( + private val broadcastId: String?, + private val scheduleBroadcastRequest: ScheduleBroadcastRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** Request body for scheduling a broadcast for a future send. */ + fun scheduleBroadcastRequest(): ScheduleBroadcastRequest = scheduleBroadcastRequest + + fun _additionalBodyProperties(): Map = + scheduleBroadcastRequest._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 [BroadcastScheduleParams]. + * + * The following fields are required: + * ```java + * .scheduleBroadcastRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastScheduleParams]. */ + class Builder internal constructor() { + + private var broadcastId: String? = null + private var scheduleBroadcastRequest: ScheduleBroadcastRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastScheduleParams: BroadcastScheduleParams) = apply { + broadcastId = broadcastScheduleParams.broadcastId + scheduleBroadcastRequest = broadcastScheduleParams.scheduleBroadcastRequest + additionalHeaders = broadcastScheduleParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastScheduleParams.additionalQueryParams.toBuilder() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.getOrNull()) + + /** Request body for scheduling a broadcast for a future send. */ + fun scheduleBroadcastRequest(scheduleBroadcastRequest: ScheduleBroadcastRequest) = apply { + this.scheduleBroadcastRequest = scheduleBroadcastRequest + } + + 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 [BroadcastScheduleParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .scheduleBroadcastRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BroadcastScheduleParams = + BroadcastScheduleParams( + broadcastId, + checkRequired("scheduleBroadcastRequest", scheduleBroadcastRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): ScheduleBroadcastRequest = scheduleBroadcastRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastScheduleParams && + broadcastId == other.broadcastId && + scheduleBroadcastRequest == other.scheduleBroadcastRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + broadcastId, + scheduleBroadcastRequest, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "BroadcastScheduleParams{broadcastId=$broadcastId, scheduleBroadcastRequest=$scheduleBroadcastRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastSendParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastSendParams.kt new file mode 100644 index 0000000..b3d5345 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastSendParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** + * Send a broadcast immediately to a list or audience. Publishes the broadcast template first. Not + * allowed once the broadcast is sending or sent. + */ +class BroadcastSendParams +private constructor( + private val broadcastId: String?, + private val sendBroadcastRequest: SendBroadcastRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** Request body for sending a broadcast immediately. */ + fun sendBroadcastRequest(): SendBroadcastRequest = sendBroadcastRequest + + fun _additionalBodyProperties(): Map = + sendBroadcastRequest._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 [BroadcastSendParams]. + * + * The following fields are required: + * ```java + * .sendBroadcastRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastSendParams]. */ + class Builder internal constructor() { + + private var broadcastId: String? = null + private var sendBroadcastRequest: SendBroadcastRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastSendParams: BroadcastSendParams) = apply { + broadcastId = broadcastSendParams.broadcastId + sendBroadcastRequest = broadcastSendParams.sendBroadcastRequest + additionalHeaders = broadcastSendParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastSendParams.additionalQueryParams.toBuilder() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.getOrNull()) + + /** Request body for sending a broadcast immediately. */ + fun sendBroadcastRequest(sendBroadcastRequest: SendBroadcastRequest) = apply { + this.sendBroadcastRequest = sendBroadcastRequest + } + + 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 [BroadcastSendParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .sendBroadcastRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BroadcastSendParams = + BroadcastSendParams( + broadcastId, + checkRequired("sendBroadcastRequest", sendBroadcastRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): SendBroadcastRequest = sendBroadcastRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastSendParams && + broadcastId == other.broadcastId && + sendBroadcastRequest == other.sendBroadcastRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(broadcastId, sendBroadcastRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "BroadcastSendParams{broadcastId=$broadcastId, sendBroadcastRequest=$sendBroadcastRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastUpdateParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastUpdateParams.kt new file mode 100644 index 0000000..0062784 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/BroadcastUpdateParams.kt @@ -0,0 +1,229 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** + * Update a broadcast's name. Content is edited via the broadcast's notification template, not this + * endpoint. + */ +class BroadcastUpdateParams +private constructor( + private val broadcastId: String?, + private val updateBroadcastRequest: UpdateBroadcastRequest, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun broadcastId(): Optional = Optional.ofNullable(broadcastId) + + /** Request body for updating a broadcast. Only the name is mutable. */ + fun updateBroadcastRequest(): UpdateBroadcastRequest = updateBroadcastRequest + + fun _additionalBodyProperties(): Map = + updateBroadcastRequest._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 [BroadcastUpdateParams]. + * + * The following fields are required: + * ```java + * .updateBroadcastRequest() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [BroadcastUpdateParams]. */ + class Builder internal constructor() { + + private var broadcastId: String? = null + private var updateBroadcastRequest: UpdateBroadcastRequest? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(broadcastUpdateParams: BroadcastUpdateParams) = apply { + broadcastId = broadcastUpdateParams.broadcastId + updateBroadcastRequest = broadcastUpdateParams.updateBroadcastRequest + additionalHeaders = broadcastUpdateParams.additionalHeaders.toBuilder() + additionalQueryParams = broadcastUpdateParams.additionalQueryParams.toBuilder() + } + + fun broadcastId(broadcastId: String?) = apply { this.broadcastId = broadcastId } + + /** Alias for calling [Builder.broadcastId] with `broadcastId.orElse(null)`. */ + fun broadcastId(broadcastId: Optional) = broadcastId(broadcastId.getOrNull()) + + /** Request body for updating a broadcast. Only the name is mutable. */ + fun updateBroadcastRequest(updateBroadcastRequest: UpdateBroadcastRequest) = apply { + this.updateBroadcastRequest = updateBroadcastRequest + } + + 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 [BroadcastUpdateParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .updateBroadcastRequest() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): BroadcastUpdateParams = + BroadcastUpdateParams( + broadcastId, + checkRequired("updateBroadcastRequest", updateBroadcastRequest), + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + fun _body(): UpdateBroadcastRequest = updateBroadcastRequest + + fun _pathParam(index: Int): String = + when (index) { + 0 -> broadcastId ?: "" + 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 BroadcastUpdateParams && + broadcastId == other.broadcastId && + updateBroadcastRequest == other.updateBroadcastRequest && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash(broadcastId, updateBroadcastRequest, additionalHeaders, additionalQueryParams) + + override fun toString() = + "BroadcastUpdateParams{broadcastId=$broadcastId, updateBroadcastRequest=$updateBroadcastRequest, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/CreateBroadcastRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/CreateBroadcastRequest.kt new file mode 100644 index 0000000..903594c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/CreateBroadcastRequest.kt @@ -0,0 +1,380 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 kotlin.jvm.optionals.getOrNull + +/** Request body for creating a broadcast. */ +class CreateBroadcastRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val channel: JsonField, + private val name: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("channel") @ExcludeMissing channel: JsonField = JsonMissing.of(), + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of(), + ) : this(channel, name, mutableMapOf()) + + /** + * The single delivery channel for this broadcast. + * + * @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 channel(): Channel = channel.getRequired("channel") + + /** + * 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 [channel]. + * + * Unlike [channel], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("channel") @ExcludeMissing fun _channel(): JsonField = channel + + /** + * 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 [CreateBroadcastRequest]. + * + * The following fields are required: + * ```java + * .channel() + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [CreateBroadcastRequest]. */ + class Builder internal constructor() { + + private var channel: JsonField? = null + private var name: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(createBroadcastRequest: CreateBroadcastRequest) = apply { + channel = createBroadcastRequest.channel + name = createBroadcastRequest.name + additionalProperties = createBroadcastRequest.additionalProperties.toMutableMap() + } + + /** The single delivery channel for this broadcast. */ + fun channel(channel: Channel) = channel(JsonField.of(channel)) + + /** + * Sets [Builder.channel] to an arbitrary JSON value. + * + * You should usually call [Builder.channel] with a well-typed [Channel] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun channel(channel: JsonField) = apply { this.channel = channel } + + /** 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 [CreateBroadcastRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .channel() + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): CreateBroadcastRequest = + CreateBroadcastRequest( + checkRequired("channel", channel), + 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(): CreateBroadcastRequest = apply { + if (validated) { + return@apply + } + + channel().validate() + 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 = + (channel.asKnown().getOrNull()?.validity() ?: 0) + (if (name.asKnown().isPresent) 1 else 0) + + /** The single delivery channel for this broadcast. */ + class Channel @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 EMAIL = of("email") + + @JvmField val SMS = of("sms") + + @JvmField val PUSH = of("push") + + @JvmField val INBOX = of("inbox") + + @JvmField val SLACK = of("slack") + + @JvmField val MSTEAMS = of("msteams") + + @JvmStatic fun of(value: String) = Channel(JsonField.of(value)) + } + + /** An enum containing [Channel]'s known values. */ + enum class Known { + EMAIL, + SMS, + PUSH, + INBOX, + SLACK, + MSTEAMS, + } + + /** + * An enum containing [Channel]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Channel] 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 { + EMAIL, + SMS, + PUSH, + INBOX, + SLACK, + MSTEAMS, + /** An enum member indicating that [Channel] 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) { + EMAIL -> Value.EMAIL + SMS -> Value.SMS + PUSH -> Value.PUSH + INBOX -> Value.INBOX + SLACK -> Value.SLACK + MSTEAMS -> Value.MSTEAMS + 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) { + EMAIL -> Known.EMAIL + SMS -> Known.SMS + PUSH -> Known.PUSH + INBOX -> Known.INBOX + SLACK -> Known.SLACK + MSTEAMS -> Known.MSTEAMS + else -> throw CourierInvalidDataException("Unknown Channel: $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(): Channel = 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 Channel && 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 CreateBroadcastRequest && + channel == other.channel && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(channel, name, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "CreateBroadcastRequest{channel=$channel, name=$name, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/ScheduleBroadcastRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/ScheduleBroadcastRequest.kt new file mode 100644 index 0000000..4f9ab48 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/ScheduleBroadcastRequest.kt @@ -0,0 +1,455 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** Request body for scheduling a broadcast for a future send. */ +class ScheduleBroadcastRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val recipientId: JsonField, + private val recipientType: JsonField, + private val scheduledTo: JsonField, + private val timezone: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("recipient_id") + @ExcludeMissing + recipientId: JsonField = JsonMissing.of(), + @JsonProperty("recipient_type") + @ExcludeMissing + recipientType: JsonField = JsonMissing.of(), + @JsonProperty("scheduled_to") + @ExcludeMissing + scheduledTo: JsonField = JsonMissing.of(), + @JsonProperty("timezone") @ExcludeMissing timezone: JsonField = JsonMissing.of(), + ) : this(recipientId, recipientType, scheduledTo, timezone, mutableMapOf()) + + /** + * ID of the target list or audience. + * + * @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 recipientId(): String = recipientId.getRequired("recipient_id") + + /** + * Whether the broadcast targets a list or an audience. + * + * @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 recipientType(): RecipientType = recipientType.getRequired("recipient_type") + + /** + * Wall-clock timestamp of the future send, no timezone offset (e.g. "2026-07-21T20:00:00"). The + * zone is given by `timezone`. + * + * @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 scheduledTo(): String = scheduledTo.getRequired("scheduled_to") + + /** + * IANA timezone for the scheduled send (e.g. America/New_York). + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun timezone(): Optional = timezone.getOptional("timezone") + + /** + * Returns the raw JSON value of [recipientId]. + * + * Unlike [recipientId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipient_id") + @ExcludeMissing + fun _recipientId(): JsonField = recipientId + + /** + * Returns the raw JSON value of [recipientType]. + * + * Unlike [recipientType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipient_type") + @ExcludeMissing + fun _recipientType(): JsonField = recipientType + + /** + * Returns the raw JSON value of [scheduledTo]. + * + * Unlike [scheduledTo], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("scheduled_to") + @ExcludeMissing + fun _scheduledTo(): JsonField = scheduledTo + + /** + * Returns the raw JSON value of [timezone]. + * + * Unlike [timezone], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("timezone") @ExcludeMissing fun _timezone(): JsonField = timezone + + @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 [ScheduleBroadcastRequest]. + * + * The following fields are required: + * ```java + * .recipientId() + * .recipientType() + * .scheduledTo() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [ScheduleBroadcastRequest]. */ + class Builder internal constructor() { + + private var recipientId: JsonField? = null + private var recipientType: JsonField? = null + private var scheduledTo: JsonField? = null + private var timezone: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(scheduleBroadcastRequest: ScheduleBroadcastRequest) = apply { + recipientId = scheduleBroadcastRequest.recipientId + recipientType = scheduleBroadcastRequest.recipientType + scheduledTo = scheduleBroadcastRequest.scheduledTo + timezone = scheduleBroadcastRequest.timezone + additionalProperties = scheduleBroadcastRequest.additionalProperties.toMutableMap() + } + + /** ID of the target list or audience. */ + fun recipientId(recipientId: String) = recipientId(JsonField.of(recipientId)) + + /** + * Sets [Builder.recipientId] to an arbitrary JSON value. + * + * You should usually call [Builder.recipientId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun recipientId(recipientId: JsonField) = apply { this.recipientId = recipientId } + + /** Whether the broadcast targets a list or an audience. */ + fun recipientType(recipientType: RecipientType) = recipientType(JsonField.of(recipientType)) + + /** + * Sets [Builder.recipientType] to an arbitrary JSON value. + * + * You should usually call [Builder.recipientType] with a well-typed [RecipientType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipientType(recipientType: JsonField) = apply { + this.recipientType = recipientType + } + + /** + * Wall-clock timestamp of the future send, no timezone offset (e.g. "2026-07-21T20:00:00"). + * The zone is given by `timezone`. + */ + fun scheduledTo(scheduledTo: String) = scheduledTo(JsonField.of(scheduledTo)) + + /** + * Sets [Builder.scheduledTo] to an arbitrary JSON value. + * + * You should usually call [Builder.scheduledTo] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun scheduledTo(scheduledTo: JsonField) = apply { this.scheduledTo = scheduledTo } + + /** IANA timezone for the scheduled send (e.g. America/New_York). */ + fun timezone(timezone: String) = timezone(JsonField.of(timezone)) + + /** + * Sets [Builder.timezone] to an arbitrary JSON value. + * + * You should usually call [Builder.timezone] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun timezone(timezone: JsonField) = apply { this.timezone = timezone } + + 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 [ScheduleBroadcastRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipientId() + * .recipientType() + * .scheduledTo() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): ScheduleBroadcastRequest = + ScheduleBroadcastRequest( + checkRequired("recipientId", recipientId), + checkRequired("recipientType", recipientType), + checkRequired("scheduledTo", scheduledTo), + timezone, + 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(): ScheduleBroadcastRequest = apply { + if (validated) { + return@apply + } + + recipientId() + recipientType().validate() + scheduledTo() + timezone() + 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 (recipientId.asKnown().isPresent) 1 else 0) + + (recipientType.asKnown().getOrNull()?.validity() ?: 0) + + (if (scheduledTo.asKnown().isPresent) 1 else 0) + + (if (timezone.asKnown().isPresent) 1 else 0) + + /** Whether the broadcast targets a list or an audience. */ + class RecipientType @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 LIST = of("list") + + @JvmField val AUDIENCE = of("audience") + + @JvmStatic fun of(value: String) = RecipientType(JsonField.of(value)) + } + + /** An enum containing [RecipientType]'s known values. */ + enum class Known { + LIST, + AUDIENCE, + } + + /** + * An enum containing [RecipientType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RecipientType] 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 { + LIST, + AUDIENCE, + /** + * An enum member indicating that [RecipientType] 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) { + LIST -> Value.LIST + AUDIENCE -> Value.AUDIENCE + 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) { + LIST -> Known.LIST + AUDIENCE -> Known.AUDIENCE + else -> throw CourierInvalidDataException("Unknown RecipientType: $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(): RecipientType = 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 RecipientType && 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 ScheduleBroadcastRequest && + recipientId == other.recipientId && + recipientType == other.recipientType && + scheduledTo == other.scheduledTo && + timezone == other.timezone && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipientId, recipientType, scheduledTo, timezone, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "ScheduleBroadcastRequest{recipientId=$recipientId, recipientType=$recipientType, scheduledTo=$scheduledTo, timezone=$timezone, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/SendBroadcastRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/SendBroadcastRequest.kt new file mode 100644 index 0000000..b0be642 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/SendBroadcastRequest.kt @@ -0,0 +1,375 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 kotlin.jvm.optionals.getOrNull + +/** Request body for sending a broadcast immediately. */ +class SendBroadcastRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val recipientId: JsonField, + private val recipientType: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("recipient_id") + @ExcludeMissing + recipientId: JsonField = JsonMissing.of(), + @JsonProperty("recipient_type") + @ExcludeMissing + recipientType: JsonField = JsonMissing.of(), + ) : this(recipientId, recipientType, mutableMapOf()) + + /** + * ID of the target list or audience. + * + * @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 recipientId(): String = recipientId.getRequired("recipient_id") + + /** + * Whether the broadcast targets a list or an audience. + * + * @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 recipientType(): RecipientType = recipientType.getRequired("recipient_type") + + /** + * Returns the raw JSON value of [recipientId]. + * + * Unlike [recipientId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipient_id") + @ExcludeMissing + fun _recipientId(): JsonField = recipientId + + /** + * Returns the raw JSON value of [recipientType]. + * + * Unlike [recipientType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("recipient_type") + @ExcludeMissing + fun _recipientType(): JsonField = recipientType + + @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 [SendBroadcastRequest]. + * + * The following fields are required: + * ```java + * .recipientId() + * .recipientType() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [SendBroadcastRequest]. */ + class Builder internal constructor() { + + private var recipientId: JsonField? = null + private var recipientType: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(sendBroadcastRequest: SendBroadcastRequest) = apply { + recipientId = sendBroadcastRequest.recipientId + recipientType = sendBroadcastRequest.recipientType + additionalProperties = sendBroadcastRequest.additionalProperties.toMutableMap() + } + + /** ID of the target list or audience. */ + fun recipientId(recipientId: String) = recipientId(JsonField.of(recipientId)) + + /** + * Sets [Builder.recipientId] to an arbitrary JSON value. + * + * You should usually call [Builder.recipientId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun recipientId(recipientId: JsonField) = apply { this.recipientId = recipientId } + + /** Whether the broadcast targets a list or an audience. */ + fun recipientType(recipientType: RecipientType) = recipientType(JsonField.of(recipientType)) + + /** + * Sets [Builder.recipientType] to an arbitrary JSON value. + * + * You should usually call [Builder.recipientType] with a well-typed [RecipientType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun recipientType(recipientType: JsonField) = apply { + this.recipientType = recipientType + } + + 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 [SendBroadcastRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .recipientId() + * .recipientType() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): SendBroadcastRequest = + SendBroadcastRequest( + checkRequired("recipientId", recipientId), + checkRequired("recipientType", recipientType), + 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(): SendBroadcastRequest = apply { + if (validated) { + return@apply + } + + recipientId() + recipientType().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 (recipientId.asKnown().isPresent) 1 else 0) + + (recipientType.asKnown().getOrNull()?.validity() ?: 0) + + /** Whether the broadcast targets a list or an audience. */ + class RecipientType @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 LIST = of("list") + + @JvmField val AUDIENCE = of("audience") + + @JvmStatic fun of(value: String) = RecipientType(JsonField.of(value)) + } + + /** An enum containing [RecipientType]'s known values. */ + enum class Known { + LIST, + AUDIENCE, + } + + /** + * An enum containing [RecipientType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [RecipientType] 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 { + LIST, + AUDIENCE, + /** + * An enum member indicating that [RecipientType] 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) { + LIST -> Value.LIST + AUDIENCE -> Value.AUDIENCE + 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) { + LIST -> Known.LIST + AUDIENCE -> Known.AUDIENCE + else -> throw CourierInvalidDataException("Unknown RecipientType: $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(): RecipientType = 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 RecipientType && 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 SendBroadcastRequest && + recipientId == other.recipientId && + recipientType == other.recipientType && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(recipientId, recipientType, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "SendBroadcastRequest{recipientId=$recipientId, recipientType=$recipientType, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/UpdateBroadcastRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/UpdateBroadcastRequest.kt new file mode 100644 index 0000000..ae370cf --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/broadcasts/UpdateBroadcastRequest.kt @@ -0,0 +1,179 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 + +/** Request body for updating a broadcast. Only the name is mutable. */ +class UpdateBroadcastRequest +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val name: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("name") @ExcludeMissing name: JsonField = JsonMissing.of() + ) : this(name, mutableMapOf()) + + /** + * New 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 [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 [UpdateBroadcastRequest]. + * + * The following fields are required: + * ```java + * .name() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [UpdateBroadcastRequest]. */ + class Builder internal constructor() { + + private var name: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(updateBroadcastRequest: UpdateBroadcastRequest) = apply { + name = updateBroadcastRequest.name + additionalProperties = updateBroadcastRequest.additionalProperties.toMutableMap() + } + + /** New 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 [UpdateBroadcastRequest]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .name() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): UpdateBroadcastRequest = + UpdateBroadcastRequest(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(): UpdateBroadcastRequest = apply { + if (validated) { + return@apply + } + + 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 = (if (name.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is UpdateBroadcastRequest && + name == other.name && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(name, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "UpdateBroadcastRequest{name=$name, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/BroadcastServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/BroadcastServiceAsync.kt new file mode 100644 index 0000000..3f32205 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/BroadcastServiceAsync.kt @@ -0,0 +1,763 @@ +// 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.broadcasts.Broadcast +import com.courier.models.broadcasts.BroadcastArchiveParams +import com.courier.models.broadcasts.BroadcastCancelParams +import com.courier.models.broadcasts.BroadcastCreateParams +import com.courier.models.broadcasts.BroadcastDuplicateParams +import com.courier.models.broadcasts.BroadcastListParams +import com.courier.models.broadcasts.BroadcastListResponse +import com.courier.models.broadcasts.BroadcastPutContentParams +import com.courier.models.broadcasts.BroadcastRetrieveContentParams +import com.courier.models.broadcasts.BroadcastRetrieveParams +import com.courier.models.broadcasts.BroadcastScheduleParams +import com.courier.models.broadcasts.BroadcastSendParams +import com.courier.models.broadcasts.BroadcastUpdateParams +import com.courier.models.broadcasts.CreateBroadcastRequest +import com.courier.models.notifications.NotificationContentGetResponse +import com.courier.models.notifications.NotificationContentMutationResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +interface BroadcastServiceAsync { + + /** + * 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): BroadcastServiceAsync + + /** + * Create a broadcast. Provisions a private notification template for the broadcast and returns + * the new broadcast in the draft state. Exactly one channel is required. + */ + fun create(params: BroadcastCreateParams): CompletableFuture = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see create */ + fun create( + createBroadcastRequest: CreateBroadcastRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + create( + BroadcastCreateParams.builder().createBroadcastRequest(createBroadcastRequest).build(), + requestOptions, + ) + + /** @see create */ + fun create(createBroadcastRequest: CreateBroadcastRequest): CompletableFuture = + create(createBroadcastRequest, RequestOptions.none()) + + /** Retrieve a broadcast by ID. Archived broadcasts return 404. */ + fun retrieve(broadcastId: String): CompletableFuture = + retrieve(broadcastId, BroadcastRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + ): CompletableFuture = retrieve(broadcastId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: BroadcastRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: BroadcastRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(broadcastId, BroadcastRetrieveParams.none(), requestOptions) + + /** + * Update a broadcast's name. Content is edited via the broadcast's notification template, not + * this endpoint. + */ + fun update(broadcastId: String, params: BroadcastUpdateParams): CompletableFuture = + update(broadcastId, params, RequestOptions.none()) + + /** @see update */ + fun update( + broadcastId: String, + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + update(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see update */ + fun update(params: BroadcastUpdateParams): CompletableFuture = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** List broadcasts in your workspace. Cursor-paginated; returns broadcasts newest-first. */ + fun list(): CompletableFuture = list(BroadcastListParams.none()) + + /** @see list */ + fun list( + params: BroadcastListParams = BroadcastListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: BroadcastListParams = BroadcastListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(BroadcastListParams.none(), requestOptions) + + /** + * Archive a broadcast. This is a soft delete — the archived broadcast is returned and no longer + * appears in list results. + */ + fun archive(broadcastId: String): CompletableFuture = + archive(broadcastId, BroadcastArchiveParams.none()) + + /** @see archive */ + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + archive(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see archive */ + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + ): CompletableFuture = archive(broadcastId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see archive */ + fun archive(params: BroadcastArchiveParams): CompletableFuture = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(broadcastId: String, requestOptions: RequestOptions): CompletableFuture = + archive(broadcastId, BroadcastArchiveParams.none(), requestOptions) + + /** + * Cancel a broadcast's pending schedule, returning it to the draft state. Only valid for a + * scheduled broadcast. + */ + fun cancel(broadcastId: String): CompletableFuture = + cancel(broadcastId, BroadcastCancelParams.none()) + + /** @see cancel */ + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + cancel(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see cancel */ + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + ): CompletableFuture = cancel(broadcastId, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see cancel */ + fun cancel(params: BroadcastCancelParams): CompletableFuture = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel(broadcastId: String, requestOptions: RequestOptions): CompletableFuture = + cancel(broadcastId, BroadcastCancelParams.none(), requestOptions) + + /** Duplicate a broadcast (and its template) into a new draft named "{source name} (copy)". */ + fun duplicate(broadcastId: String): CompletableFuture = + duplicate(broadcastId, BroadcastDuplicateParams.none()) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + duplicate(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + ): CompletableFuture = duplicate(broadcastId, params, RequestOptions.none()) + + /** @see duplicate */ + fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see duplicate */ + fun duplicate(params: BroadcastDuplicateParams): CompletableFuture = + duplicate(params, RequestOptions.none()) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + duplicate(broadcastId, BroadcastDuplicateParams.none(), requestOptions) + + /** + * Author the broadcast's content by replacing the draft elemental content of its private + * notification template. The draft is published automatically when the broadcast is sent or + * scheduled. + */ + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + ): CompletableFuture = + putContent(broadcastId, params, RequestOptions.none()) + + /** @see putContent */ + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + putContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see putContent */ + fun putContent( + params: BroadcastPutContentParams + ): CompletableFuture = + putContent(params, RequestOptions.none()) + + /** @see putContent */ + fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Retrieve the broadcast's content — the elemental content of its private notification + * template. Defaults to the working draft, since broadcast content is authored as a draft until + * the broadcast is sent. + */ + fun retrieveContent(broadcastId: String): CompletableFuture = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none()) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieveContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + ): CompletableFuture = + retrieveContent(broadcastId, params, RequestOptions.none()) + + /** @see retrieveContent */ + fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieveContent */ + fun retrieveContent( + params: BroadcastRetrieveContentParams + ): CompletableFuture = + retrieveContent(params, RequestOptions.none()) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none(), requestOptions) + + /** + * Schedule a broadcast for a future send to a list or audience. Publishes the broadcast + * template first. Not allowed once the broadcast is sending or sent. For an immediate send use + * POST /broadcasts/{broadcastId}/send. + */ + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + ): CompletableFuture = schedule(broadcastId, params, RequestOptions.none()) + + /** @see schedule */ + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + schedule(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see schedule */ + fun schedule(params: BroadcastScheduleParams): CompletableFuture = + schedule(params, RequestOptions.none()) + + /** @see schedule */ + fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * Send a broadcast immediately to a list or audience. Publishes the broadcast template first. + * Not allowed once the broadcast is sending or sent. + */ + fun send(broadcastId: String, params: BroadcastSendParams): CompletableFuture = + send(broadcastId, params, RequestOptions.none()) + + /** @see send */ + fun send( + broadcastId: String, + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + send(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see send */ + fun send(params: BroadcastSendParams): CompletableFuture = + send(params, RequestOptions.none()) + + /** @see send */ + fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** + * A view of [BroadcastServiceAsync] 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 + ): BroadcastServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `post /broadcasts`, but is otherwise the same as + * [BroadcastServiceAsync.create]. + */ + fun create(params: BroadcastCreateParams): CompletableFuture> = + create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see create */ + fun create( + createBroadcastRequest: CreateBroadcastRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + create( + BroadcastCreateParams.builder() + .createBroadcastRequest(createBroadcastRequest) + .build(), + requestOptions, + ) + + /** @see create */ + fun create( + createBroadcastRequest: CreateBroadcastRequest + ): CompletableFuture> = + create(createBroadcastRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /broadcasts/{broadcastId}`, but is otherwise the + * same as [BroadcastServiceAsync.retrieve]. + */ + fun retrieve(broadcastId: String): CompletableFuture> = + retrieve(broadcastId, BroadcastRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + ): CompletableFuture> = + retrieve(broadcastId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: BroadcastRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: BroadcastRetrieveParams + ): CompletableFuture> = retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(broadcastId, BroadcastRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /broadcasts/{broadcastId}`, but is otherwise the + * same as [BroadcastServiceAsync.update]. + */ + fun update( + broadcastId: String, + params: BroadcastUpdateParams, + ): CompletableFuture> = + update(broadcastId, params, RequestOptions.none()) + + /** @see update */ + fun update( + broadcastId: String, + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + update(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see update */ + fun update(params: BroadcastUpdateParams): CompletableFuture> = + update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /broadcasts`, but is otherwise the same as + * [BroadcastServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(BroadcastListParams.none()) + + /** @see list */ + fun list( + params: BroadcastListParams = BroadcastListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: BroadcastListParams = BroadcastListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(BroadcastListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /broadcasts/{broadcastId}`, but is otherwise the + * same as [BroadcastServiceAsync.archive]. + */ + fun archive(broadcastId: String): CompletableFuture> = + archive(broadcastId, BroadcastArchiveParams.none()) + + /** @see archive */ + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + archive(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see archive */ + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + ): CompletableFuture> = + archive(broadcastId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see archive */ + fun archive(params: BroadcastArchiveParams): CompletableFuture> = + archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + archive(broadcastId, BroadcastArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/cancel`, but is otherwise + * the same as [BroadcastServiceAsync.cancel]. + */ + fun cancel(broadcastId: String): CompletableFuture> = + cancel(broadcastId, BroadcastCancelParams.none()) + + /** @see cancel */ + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + cancel(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see cancel */ + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + ): CompletableFuture> = + cancel(broadcastId, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see cancel */ + fun cancel(params: BroadcastCancelParams): CompletableFuture> = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + cancel(broadcastId, BroadcastCancelParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/duplicate`, but is + * otherwise the same as [BroadcastServiceAsync.duplicate]. + */ + fun duplicate(broadcastId: String): CompletableFuture> = + duplicate(broadcastId, BroadcastDuplicateParams.none()) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + duplicate(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + ): CompletableFuture> = + duplicate(broadcastId, params, RequestOptions.none()) + + /** @see duplicate */ + fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see duplicate */ + fun duplicate( + params: BroadcastDuplicateParams + ): CompletableFuture> = duplicate(params, RequestOptions.none()) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + duplicate(broadcastId, BroadcastDuplicateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /broadcasts/{broadcastId}/content`, but is otherwise + * the same as [BroadcastServiceAsync.putContent]. + */ + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + ): CompletableFuture> = + putContent(broadcastId, params, RequestOptions.none()) + + /** @see putContent */ + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + putContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see putContent */ + fun putContent( + params: BroadcastPutContentParams + ): CompletableFuture> = + putContent(params, RequestOptions.none()) + + /** @see putContent */ + fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `get /broadcasts/{broadcastId}/content`, but is otherwise + * the same as [BroadcastServiceAsync.retrieveContent]. + */ + fun retrieveContent( + broadcastId: String + ): CompletableFuture> = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none()) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieveContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + ): CompletableFuture> = + retrieveContent(broadcastId, params, RequestOptions.none()) + + /** @see retrieveContent */ + fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieveContent */ + fun retrieveContent( + params: BroadcastRetrieveContentParams + ): CompletableFuture> = + retrieveContent(params, RequestOptions.none()) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/schedule`, but is + * otherwise the same as [BroadcastServiceAsync.schedule]. + */ + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + ): CompletableFuture> = + schedule(broadcastId, params, RequestOptions.none()) + + /** @see schedule */ + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + schedule(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see schedule */ + fun schedule( + params: BroadcastScheduleParams + ): CompletableFuture> = schedule(params, RequestOptions.none()) + + /** @see schedule */ + fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/send`, but is otherwise + * the same as [BroadcastServiceAsync.send]. + */ + fun send( + broadcastId: String, + params: BroadcastSendParams, + ): CompletableFuture> = + send(broadcastId, params, RequestOptions.none()) + + /** @see send */ + fun send( + broadcastId: String, + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + send(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see send */ + fun send(params: BroadcastSendParams): CompletableFuture> = + send(params, RequestOptions.none()) + + /** @see send */ + fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/BroadcastServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/BroadcastServiceAsyncImpl.kt new file mode 100644 index 0000000..0b58529 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/BroadcastServiceAsyncImpl.kt @@ -0,0 +1,505 @@ +// 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.broadcasts.Broadcast +import com.courier.models.broadcasts.BroadcastArchiveParams +import com.courier.models.broadcasts.BroadcastCancelParams +import com.courier.models.broadcasts.BroadcastCreateParams +import com.courier.models.broadcasts.BroadcastDuplicateParams +import com.courier.models.broadcasts.BroadcastListParams +import com.courier.models.broadcasts.BroadcastListResponse +import com.courier.models.broadcasts.BroadcastPutContentParams +import com.courier.models.broadcasts.BroadcastRetrieveContentParams +import com.courier.models.broadcasts.BroadcastRetrieveParams +import com.courier.models.broadcasts.BroadcastScheduleParams +import com.courier.models.broadcasts.BroadcastSendParams +import com.courier.models.broadcasts.BroadcastUpdateParams +import com.courier.models.notifications.NotificationContentGetResponse +import com.courier.models.notifications.NotificationContentMutationResponse +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class BroadcastServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + BroadcastServiceAsync { + + private val withRawResponse: BroadcastServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): BroadcastServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): BroadcastServiceAsync = + BroadcastServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /broadcasts + withRawResponse().create(params, requestOptions).thenApply { it.parse() } + + override fun retrieve( + params: BroadcastRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /broadcasts/{broadcastId} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /broadcasts/{broadcastId} + withRawResponse().update(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: BroadcastListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /broadcasts + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // delete /broadcasts/{broadcastId} + withRawResponse().archive(params, requestOptions).thenApply { it.parse() } + + override fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /broadcasts/{broadcastId}/cancel + withRawResponse().cancel(params, requestOptions).thenApply { it.parse() } + + override fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /broadcasts/{broadcastId}/duplicate + withRawResponse().duplicate(params, requestOptions).thenApply { it.parse() } + + override fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // put /broadcasts/{broadcastId}/content + withRawResponse().putContent(params, requestOptions).thenApply { it.parse() } + + override fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /broadcasts/{broadcastId}/content + withRawResponse().retrieveContent(params, requestOptions).thenApply { it.parse() } + + override fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /broadcasts/{broadcastId}/schedule + withRawResponse().schedule(params, requestOptions).thenApply { it.parse() } + + override fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // post /broadcasts/{broadcastId}/send + withRawResponse().send(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + BroadcastServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): BroadcastServiceAsync.WithRawResponse = + BroadcastServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts") + .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: BroadcastRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", 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 { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", 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 { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: BroadcastListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts") + .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() + } + } + } + } + } + + private val archiveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", 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 { archiveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val cancelHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "cancel") + .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 { cancelHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val duplicateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "duplicate") + .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 { duplicateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val putContentHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "content") + .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 { putContentHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val retrieveContentHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "content") + .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 { retrieveContentHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val scheduleHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "schedule") + .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 { scheduleHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val sendHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "send") + .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 { sendHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/BroadcastService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/BroadcastService.kt new file mode 100644 index 0000000..5473b72 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/BroadcastService.kt @@ -0,0 +1,763 @@ +// 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.broadcasts.Broadcast +import com.courier.models.broadcasts.BroadcastArchiveParams +import com.courier.models.broadcasts.BroadcastCancelParams +import com.courier.models.broadcasts.BroadcastCreateParams +import com.courier.models.broadcasts.BroadcastDuplicateParams +import com.courier.models.broadcasts.BroadcastListParams +import com.courier.models.broadcasts.BroadcastListResponse +import com.courier.models.broadcasts.BroadcastPutContentParams +import com.courier.models.broadcasts.BroadcastRetrieveContentParams +import com.courier.models.broadcasts.BroadcastRetrieveParams +import com.courier.models.broadcasts.BroadcastScheduleParams +import com.courier.models.broadcasts.BroadcastSendParams +import com.courier.models.broadcasts.BroadcastUpdateParams +import com.courier.models.broadcasts.CreateBroadcastRequest +import com.courier.models.notifications.NotificationContentGetResponse +import com.courier.models.notifications.NotificationContentMutationResponse +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +interface BroadcastService { + + /** + * 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): BroadcastService + + /** + * Create a broadcast. Provisions a private notification template for the broadcast and returns + * the new broadcast in the draft state. Exactly one channel is required. + */ + fun create(params: BroadcastCreateParams): Broadcast = create(params, RequestOptions.none()) + + /** @see create */ + fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** @see create */ + fun create( + createBroadcastRequest: CreateBroadcastRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = + create( + BroadcastCreateParams.builder().createBroadcastRequest(createBroadcastRequest).build(), + requestOptions, + ) + + /** @see create */ + fun create(createBroadcastRequest: CreateBroadcastRequest): Broadcast = + create(createBroadcastRequest, RequestOptions.none()) + + /** Retrieve a broadcast by ID. Archived broadcasts return 404. */ + fun retrieve(broadcastId: String): Broadcast = + retrieve(broadcastId, BroadcastRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = retrieve(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + ): Broadcast = retrieve(broadcastId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: BroadcastRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** @see retrieve */ + fun retrieve(params: BroadcastRetrieveParams): Broadcast = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(broadcastId: String, requestOptions: RequestOptions): Broadcast = + retrieve(broadcastId, BroadcastRetrieveParams.none(), requestOptions) + + /** + * Update a broadcast's name. Content is edited via the broadcast's notification template, not + * this endpoint. + */ + fun update(broadcastId: String, params: BroadcastUpdateParams): Broadcast = + update(broadcastId, params, RequestOptions.none()) + + /** @see update */ + fun update( + broadcastId: String, + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = update(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see update */ + fun update(params: BroadcastUpdateParams): Broadcast = update(params, RequestOptions.none()) + + /** @see update */ + fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** List broadcasts in your workspace. Cursor-paginated; returns broadcasts newest-first. */ + fun list(): BroadcastListResponse = list(BroadcastListParams.none()) + + /** @see list */ + fun list( + params: BroadcastListParams = BroadcastListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): BroadcastListResponse + + /** @see list */ + fun list(params: BroadcastListParams = BroadcastListParams.none()): BroadcastListResponse = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): BroadcastListResponse = + list(BroadcastListParams.none(), requestOptions) + + /** + * Archive a broadcast. This is a soft delete — the archived broadcast is returned and no longer + * appears in list results. + */ + fun archive(broadcastId: String): Broadcast = + archive(broadcastId, BroadcastArchiveParams.none()) + + /** @see archive */ + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = archive(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see archive */ + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + ): Broadcast = archive(broadcastId, params, RequestOptions.none()) + + /** @see archive */ + fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** @see archive */ + fun archive(params: BroadcastArchiveParams): Broadcast = archive(params, RequestOptions.none()) + + /** @see archive */ + fun archive(broadcastId: String, requestOptions: RequestOptions): Broadcast = + archive(broadcastId, BroadcastArchiveParams.none(), requestOptions) + + /** + * Cancel a broadcast's pending schedule, returning it to the draft state. Only valid for a + * scheduled broadcast. + */ + fun cancel(broadcastId: String): Broadcast = cancel(broadcastId, BroadcastCancelParams.none()) + + /** @see cancel */ + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = cancel(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see cancel */ + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + ): Broadcast = cancel(broadcastId, params, RequestOptions.none()) + + /** @see cancel */ + fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** @see cancel */ + fun cancel(params: BroadcastCancelParams): Broadcast = cancel(params, RequestOptions.none()) + + /** @see cancel */ + fun cancel(broadcastId: String, requestOptions: RequestOptions): Broadcast = + cancel(broadcastId, BroadcastCancelParams.none(), requestOptions) + + /** Duplicate a broadcast (and its template) into a new draft named "{source name} (copy)". */ + fun duplicate(broadcastId: String): Broadcast = + duplicate(broadcastId, BroadcastDuplicateParams.none()) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = duplicate(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see duplicate */ + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + ): Broadcast = duplicate(broadcastId, params, RequestOptions.none()) + + /** @see duplicate */ + fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** @see duplicate */ + fun duplicate(params: BroadcastDuplicateParams): Broadcast = + duplicate(params, RequestOptions.none()) + + /** @see duplicate */ + fun duplicate(broadcastId: String, requestOptions: RequestOptions): Broadcast = + duplicate(broadcastId, BroadcastDuplicateParams.none(), requestOptions) + + /** + * Author the broadcast's content by replacing the draft elemental content of its private + * notification template. The draft is published automatically when the broadcast is sent or + * scheduled. + */ + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + ): NotificationContentMutationResponse = putContent(broadcastId, params, RequestOptions.none()) + + /** @see putContent */ + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationContentMutationResponse = + putContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see putContent */ + fun putContent(params: BroadcastPutContentParams): NotificationContentMutationResponse = + putContent(params, RequestOptions.none()) + + /** @see putContent */ + fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationContentMutationResponse + + /** + * Retrieve the broadcast's content — the elemental content of its private notification + * template. Defaults to the working draft, since broadcast content is authored as a draft until + * the broadcast is sent. + */ + fun retrieveContent(broadcastId: String): NotificationContentGetResponse = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none()) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationContentGetResponse = + retrieveContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + ): NotificationContentGetResponse = retrieveContent(broadcastId, params, RequestOptions.none()) + + /** @see retrieveContent */ + fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): NotificationContentGetResponse + + /** @see retrieveContent */ + fun retrieveContent(params: BroadcastRetrieveContentParams): NotificationContentGetResponse = + retrieveContent(params, RequestOptions.none()) + + /** @see retrieveContent */ + fun retrieveContent( + broadcastId: String, + requestOptions: RequestOptions, + ): NotificationContentGetResponse = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none(), requestOptions) + + /** + * Schedule a broadcast for a future send to a list or audience. Publishes the broadcast + * template first. Not allowed once the broadcast is sending or sent. For an immediate send use + * POST /broadcasts/{broadcastId}/send. + */ + fun schedule(broadcastId: String, params: BroadcastScheduleParams): Broadcast = + schedule(broadcastId, params, RequestOptions.none()) + + /** @see schedule */ + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = schedule(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see schedule */ + fun schedule(params: BroadcastScheduleParams): Broadcast = + schedule(params, RequestOptions.none()) + + /** @see schedule */ + fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** + * Send a broadcast immediately to a list or audience. Publishes the broadcast template first. + * Not allowed once the broadcast is sending or sent. + */ + fun send(broadcastId: String, params: BroadcastSendParams): Broadcast = + send(broadcastId, params, RequestOptions.none()) + + /** @see send */ + fun send( + broadcastId: String, + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast = send(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see send */ + fun send(params: BroadcastSendParams): Broadcast = send(params, RequestOptions.none()) + + /** @see send */ + fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): Broadcast + + /** A view of [BroadcastService] 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): BroadcastService.WithRawResponse + + /** + * Returns a raw HTTP response for `post /broadcasts`, but is otherwise the same as + * [BroadcastService.create]. + */ + @MustBeClosed + fun create(params: BroadcastCreateParams): HttpResponseFor = + create(params, RequestOptions.none()) + + /** @see create */ + @MustBeClosed + fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see create */ + @MustBeClosed + fun create( + createBroadcastRequest: CreateBroadcastRequest, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + create( + BroadcastCreateParams.builder() + .createBroadcastRequest(createBroadcastRequest) + .build(), + requestOptions, + ) + + /** @see create */ + @MustBeClosed + fun create(createBroadcastRequest: CreateBroadcastRequest): HttpResponseFor = + create(createBroadcastRequest, RequestOptions.none()) + + /** + * Returns a raw HTTP response for `get /broadcasts/{broadcastId}`, but is otherwise the + * same as [BroadcastService.retrieve]. + */ + @MustBeClosed + fun retrieve(broadcastId: String): HttpResponseFor = + retrieve(broadcastId, BroadcastRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + broadcastId: String, + params: BroadcastRetrieveParams = BroadcastRetrieveParams.none(), + ): HttpResponseFor = retrieve(broadcastId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: BroadcastRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: BroadcastRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + broadcastId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(broadcastId, BroadcastRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /broadcasts/{broadcastId}`, but is otherwise the + * same as [BroadcastService.update]. + */ + @MustBeClosed + fun update(broadcastId: String, params: BroadcastUpdateParams): HttpResponseFor = + update(broadcastId, params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + broadcastId: String, + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + update(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see update */ + @MustBeClosed + fun update(params: BroadcastUpdateParams): HttpResponseFor = + update(params, RequestOptions.none()) + + /** @see update */ + @MustBeClosed + fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /broadcasts`, but is otherwise the same as + * [BroadcastService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = list(BroadcastListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: BroadcastListParams = BroadcastListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: BroadcastListParams = BroadcastListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(BroadcastListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `delete /broadcasts/{broadcastId}`, but is otherwise the + * same as [BroadcastService.archive]. + */ + @MustBeClosed + fun archive(broadcastId: String): HttpResponseFor = + archive(broadcastId, BroadcastArchiveParams.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + archive(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see archive */ + @MustBeClosed + fun archive( + broadcastId: String, + params: BroadcastArchiveParams = BroadcastArchiveParams.none(), + ): HttpResponseFor = archive(broadcastId, params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see archive */ + @MustBeClosed + fun archive(params: BroadcastArchiveParams): HttpResponseFor = + archive(params, RequestOptions.none()) + + /** @see archive */ + @MustBeClosed + fun archive( + broadcastId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + archive(broadcastId, BroadcastArchiveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/cancel`, but is otherwise + * the same as [BroadcastService.cancel]. + */ + @MustBeClosed + fun cancel(broadcastId: String): HttpResponseFor = + cancel(broadcastId, BroadcastCancelParams.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + cancel(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see cancel */ + @MustBeClosed + fun cancel( + broadcastId: String, + params: BroadcastCancelParams = BroadcastCancelParams.none(), + ): HttpResponseFor = cancel(broadcastId, params, RequestOptions.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see cancel */ + @MustBeClosed + fun cancel(params: BroadcastCancelParams): HttpResponseFor = + cancel(params, RequestOptions.none()) + + /** @see cancel */ + @MustBeClosed + fun cancel( + broadcastId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + cancel(broadcastId, BroadcastCancelParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/duplicate`, but is + * otherwise the same as [BroadcastService.duplicate]. + */ + @MustBeClosed + fun duplicate(broadcastId: String): HttpResponseFor = + duplicate(broadcastId, BroadcastDuplicateParams.none()) + + /** @see duplicate */ + @MustBeClosed + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + duplicate(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see duplicate */ + @MustBeClosed + fun duplicate( + broadcastId: String, + params: BroadcastDuplicateParams = BroadcastDuplicateParams.none(), + ): HttpResponseFor = duplicate(broadcastId, params, RequestOptions.none()) + + /** @see duplicate */ + @MustBeClosed + fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see duplicate */ + @MustBeClosed + fun duplicate(params: BroadcastDuplicateParams): HttpResponseFor = + duplicate(params, RequestOptions.none()) + + /** @see duplicate */ + @MustBeClosed + fun duplicate( + broadcastId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + duplicate(broadcastId, BroadcastDuplicateParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `put /broadcasts/{broadcastId}/content`, but is otherwise + * the same as [BroadcastService.putContent]. + */ + @MustBeClosed + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + ): HttpResponseFor = + putContent(broadcastId, params, RequestOptions.none()) + + /** @see putContent */ + @MustBeClosed + fun putContent( + broadcastId: String, + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + putContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see putContent */ + @MustBeClosed + fun putContent( + params: BroadcastPutContentParams + ): HttpResponseFor = + putContent(params, RequestOptions.none()) + + /** @see putContent */ + @MustBeClosed + fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `get /broadcasts/{broadcastId}/content`, but is otherwise + * the same as [BroadcastService.retrieveContent]. + */ + @MustBeClosed + fun retrieveContent(broadcastId: String): HttpResponseFor = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none()) + + /** @see retrieveContent */ + @MustBeClosed + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieveContent(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see retrieveContent */ + @MustBeClosed + fun retrieveContent( + broadcastId: String, + params: BroadcastRetrieveContentParams = BroadcastRetrieveContentParams.none(), + ): HttpResponseFor = + retrieveContent(broadcastId, params, RequestOptions.none()) + + /** @see retrieveContent */ + @MustBeClosed + fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieveContent */ + @MustBeClosed + fun retrieveContent( + params: BroadcastRetrieveContentParams + ): HttpResponseFor = + retrieveContent(params, RequestOptions.none()) + + /** @see retrieveContent */ + @MustBeClosed + fun retrieveContent( + broadcastId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieveContent(broadcastId, BroadcastRetrieveContentParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/schedule`, but is + * otherwise the same as [BroadcastService.schedule]. + */ + @MustBeClosed + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + ): HttpResponseFor = schedule(broadcastId, params, RequestOptions.none()) + + /** @see schedule */ + @MustBeClosed + fun schedule( + broadcastId: String, + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + schedule(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see schedule */ + @MustBeClosed + fun schedule(params: BroadcastScheduleParams): HttpResponseFor = + schedule(params, RequestOptions.none()) + + /** @see schedule */ + @MustBeClosed + fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** + * Returns a raw HTTP response for `post /broadcasts/{broadcastId}/send`, but is otherwise + * the same as [BroadcastService.send]. + */ + @MustBeClosed + fun send(broadcastId: String, params: BroadcastSendParams): HttpResponseFor = + send(broadcastId, params, RequestOptions.none()) + + /** @see send */ + @MustBeClosed + fun send( + broadcastId: String, + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + send(params.toBuilder().broadcastId(broadcastId).build(), requestOptions) + + /** @see send */ + @MustBeClosed + fun send(params: BroadcastSendParams): HttpResponseFor = + send(params, RequestOptions.none()) + + /** @see send */ + @MustBeClosed + fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/BroadcastServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/BroadcastServiceImpl.kt new file mode 100644 index 0000000..a083327 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/BroadcastServiceImpl.kt @@ -0,0 +1,459 @@ +// 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.broadcasts.Broadcast +import com.courier.models.broadcasts.BroadcastArchiveParams +import com.courier.models.broadcasts.BroadcastCancelParams +import com.courier.models.broadcasts.BroadcastCreateParams +import com.courier.models.broadcasts.BroadcastDuplicateParams +import com.courier.models.broadcasts.BroadcastListParams +import com.courier.models.broadcasts.BroadcastListResponse +import com.courier.models.broadcasts.BroadcastPutContentParams +import com.courier.models.broadcasts.BroadcastRetrieveContentParams +import com.courier.models.broadcasts.BroadcastRetrieveParams +import com.courier.models.broadcasts.BroadcastScheduleParams +import com.courier.models.broadcasts.BroadcastSendParams +import com.courier.models.broadcasts.BroadcastUpdateParams +import com.courier.models.notifications.NotificationContentGetResponse +import com.courier.models.notifications.NotificationContentMutationResponse +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +class BroadcastServiceImpl internal constructor(private val clientOptions: ClientOptions) : + BroadcastService { + + private val withRawResponse: BroadcastService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): BroadcastService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): BroadcastService = + BroadcastServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun create(params: BroadcastCreateParams, requestOptions: RequestOptions): Broadcast = + // post /broadcasts + withRawResponse().create(params, requestOptions).parse() + + override fun retrieve( + params: BroadcastRetrieveParams, + requestOptions: RequestOptions, + ): Broadcast = + // get /broadcasts/{broadcastId} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun update(params: BroadcastUpdateParams, requestOptions: RequestOptions): Broadcast = + // put /broadcasts/{broadcastId} + withRawResponse().update(params, requestOptions).parse() + + override fun list( + params: BroadcastListParams, + requestOptions: RequestOptions, + ): BroadcastListResponse = + // get /broadcasts + withRawResponse().list(params, requestOptions).parse() + + override fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions, + ): Broadcast = + // delete /broadcasts/{broadcastId} + withRawResponse().archive(params, requestOptions).parse() + + override fun cancel(params: BroadcastCancelParams, requestOptions: RequestOptions): Broadcast = + // post /broadcasts/{broadcastId}/cancel + withRawResponse().cancel(params, requestOptions).parse() + + override fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions, + ): Broadcast = + // post /broadcasts/{broadcastId}/duplicate + withRawResponse().duplicate(params, requestOptions).parse() + + override fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions, + ): NotificationContentMutationResponse = + // put /broadcasts/{broadcastId}/content + withRawResponse().putContent(params, requestOptions).parse() + + override fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions, + ): NotificationContentGetResponse = + // get /broadcasts/{broadcastId}/content + withRawResponse().retrieveContent(params, requestOptions).parse() + + override fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions, + ): Broadcast = + // post /broadcasts/{broadcastId}/schedule + withRawResponse().schedule(params, requestOptions).parse() + + override fun send(params: BroadcastSendParams, requestOptions: RequestOptions): Broadcast = + // post /broadcasts/{broadcastId}/send + withRawResponse().send(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + BroadcastService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): BroadcastService.WithRawResponse = + BroadcastServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val createHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun create( + params: BroadcastCreateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts") + .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: BroadcastRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", 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 { retrieveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val updateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun update( + params: BroadcastUpdateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", 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 { updateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: BroadcastListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts") + .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() + } + } + } + } + + private val archiveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun archive( + params: BroadcastArchiveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.DELETE) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", 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 { archiveHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val cancelHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun cancel( + params: BroadcastCancelParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "cancel") + .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 { cancelHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val duplicateHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun duplicate( + params: BroadcastDuplicateParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "duplicate") + .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 { duplicateHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val putContentHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun putContent( + params: BroadcastPutContentParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.PUT) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "content") + .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 { putContentHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val retrieveContentHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieveContent( + params: BroadcastRetrieveContentParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "content") + .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 { retrieveContentHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val scheduleHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun schedule( + params: BroadcastScheduleParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "schedule") + .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 { scheduleHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val sendHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun send( + params: BroadcastSendParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("broadcastId", params.broadcastId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.POST) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("broadcasts", params._pathParam(0), "send") + .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 { sendHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastArchiveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastArchiveParamsTest.kt new file mode 100644 index 0000000..c134d08 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastArchiveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastArchiveParamsTest { + + @Test + fun create() { + BroadcastArchiveParams.builder().broadcastId("broadcastId").build() + } + + @Test + fun pathParams() { + val params = BroadcastArchiveParams.builder().broadcastId("broadcastId").build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastCancelParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastCancelParamsTest.kt new file mode 100644 index 0000000..1e48cfb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastCancelParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastCancelParamsTest { + + @Test + fun create() { + BroadcastCancelParams.builder().broadcastId("broadcastId").build() + } + + @Test + fun pathParams() { + val params = BroadcastCancelParams.builder().broadcastId("broadcastId").build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastCreateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastCreateParamsTest.kt new file mode 100644 index 0000000..75a75bb --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastCreateParamsTest.kt @@ -0,0 +1,44 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastCreateParamsTest { + + @Test + fun create() { + BroadcastCreateParams.builder() + .createBroadcastRequest( + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("Spring Sale Announcement") + .build() + ) + .build() + } + + @Test + fun body() { + val params = + BroadcastCreateParams.builder() + .createBroadcastRequest( + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("Spring Sale Announcement") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("Spring Sale Announcement") + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastDuplicateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastDuplicateParamsTest.kt new file mode 100644 index 0000000..edad098 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastDuplicateParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastDuplicateParamsTest { + + @Test + fun create() { + BroadcastDuplicateParams.builder().broadcastId("broadcastId").build() + } + + @Test + fun pathParams() { + val params = BroadcastDuplicateParams.builder().broadcastId("broadcastId").build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastListParamsTest.kt new file mode 100644 index 0000000..acb06fe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastListParamsTest.kt @@ -0,0 +1,34 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastListParamsTest { + + @Test + fun create() { + BroadcastListParams.builder().cursor("cursor").limit(1L).build() + } + + @Test + fun queryParams() { + val params = BroadcastListParams.builder().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 = BroadcastListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastListResponseTest.kt new file mode 100644 index 0000000..cfc2b2a --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastListResponseTest.kt @@ -0,0 +1,107 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 BroadcastListResponseTest { + + @Test + fun create() { + val broadcastListResponse = + BroadcastListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addResult( + Broadcast.builder() + .id("id") + .channel(Broadcast.Channel.EMAIL) + .createdAt("created_at") + .createdBy("created_by") + .name("name") + .status(Broadcast.Status.DRAFT) + .updatedAt("updated_at") + .updatedBy("updated_by") + .archivedAt("archived_at") + .archivedBy("archived_by") + .schedule( + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + ) + .build() + ) + .build() + + assertThat(broadcastListResponse.paging()) + .isEqualTo(Paging.builder().more(true).cursor("cursor").build()) + assertThat(broadcastListResponse.results()) + .containsExactly( + Broadcast.builder() + .id("id") + .channel(Broadcast.Channel.EMAIL) + .createdAt("created_at") + .createdBy("created_by") + .name("name") + .status(Broadcast.Status.DRAFT) + .updatedAt("updated_at") + .updatedBy("updated_by") + .archivedAt("archived_at") + .archivedBy("archived_by") + .schedule( + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + ) + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val broadcastListResponse = + BroadcastListResponse.builder() + .paging(Paging.builder().more(true).cursor("cursor").build()) + .addResult( + Broadcast.builder() + .id("id") + .channel(Broadcast.Channel.EMAIL) + .createdAt("created_at") + .createdBy("created_by") + .name("name") + .status(Broadcast.Status.DRAFT) + .updatedAt("updated_at") + .updatedBy("updated_by") + .archivedAt("archived_at") + .archivedBy("archived_by") + .schedule( + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + ) + .build() + ) + .build() + + val roundtrippedBroadcastListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(broadcastListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBroadcastListResponse).isEqualTo(broadcastListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastPutContentParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastPutContentParamsTest.kt new file mode 100644 index 0000000..1a678b9 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastPutContentParamsTest.kt @@ -0,0 +1,170 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import com.courier.models.ElementalMetaNodeWithType +import com.courier.models.ElementalTextNodeWithType +import com.courier.models.notifications.NotificationContentPutRequest +import com.courier.models.notifications.NotificationTemplateState +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastPutContentParamsTest { + + @Test + fun create() { + BroadcastPutContentParams.builder() + .broadcastId("broadcastId") + .notificationContentPutRequest( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement( + ElementalMetaNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalMetaNodeWithType.Type.META) + .build() + ) + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("2022-01-01") + .build() + ) + .state(NotificationTemplateState.DRAFT) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + BroadcastPutContentParams.builder() + .broadcastId("broadcastId") + .notificationContentPutRequest( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .addElement(ElementalTextNodeWithType.builder().build()) + .build() + ) + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + BroadcastPutContentParams.builder() + .broadcastId("broadcastId") + .notificationContentPutRequest( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement( + ElementalMetaNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalMetaNodeWithType.Type.META) + .build() + ) + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("2022-01-01") + .build() + ) + .state(NotificationTemplateState.DRAFT) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement( + ElementalMetaNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalMetaNodeWithType.Type.META) + .build() + ) + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("2022-01-01") + .build() + ) + .state(NotificationTemplateState.DRAFT) + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + BroadcastPutContentParams.builder() + .broadcastId("broadcastId") + .notificationContentPutRequest( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .addElement(ElementalTextNodeWithType.builder().build()) + .build() + ) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement(ElementalTextNodeWithType.builder().build()) + .addElement(ElementalTextNodeWithType.builder().build()) + .build() + ) + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastRetrieveContentParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastRetrieveContentParamsTest.kt new file mode 100644 index 0000000..6de7f05 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastRetrieveContentParamsTest.kt @@ -0,0 +1,49 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastRetrieveContentParamsTest { + + @Test + fun create() { + BroadcastRetrieveContentParams.builder() + .broadcastId("broadcastId") + .version("version") + .build() + } + + @Test + fun pathParams() { + val params = BroadcastRetrieveContentParams.builder().broadcastId("broadcastId").build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun queryParams() { + val params = + BroadcastRetrieveContentParams.builder() + .broadcastId("broadcastId") + .version("version") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().put("version", "version").build()) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = BroadcastRetrieveContentParams.builder().broadcastId("broadcastId").build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastRetrieveParamsTest.kt new file mode 100644 index 0000000..d8b7369 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastRetrieveParamsTest { + + @Test + fun create() { + BroadcastRetrieveParams.builder().broadcastId("broadcastId").build() + } + + @Test + fun pathParams() { + val params = BroadcastRetrieveParams.builder().broadcastId("broadcastId").build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastScheduleParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastScheduleParamsTest.kt new file mode 100644 index 0000000..7b8701e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastScheduleParamsTest.kt @@ -0,0 +1,97 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastScheduleParamsTest { + + @Test + fun create() { + BroadcastScheduleParams.builder() + .broadcastId("broadcastId") + .scheduleBroadcastRequest( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .timezone("America/New_York") + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + BroadcastScheduleParams.builder() + .broadcastId("broadcastId") + .scheduleBroadcastRequest( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + BroadcastScheduleParams.builder() + .broadcastId("broadcastId") + .scheduleBroadcastRequest( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .timezone("America/New_York") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .timezone("America/New_York") + .build() + ) + } + + @Test + fun bodyWithoutOptionalFields() { + val params = + BroadcastScheduleParams.builder() + .broadcastId("broadcastId") + .scheduleBroadcastRequest( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastScheduleTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastScheduleTest.kt new file mode 100644 index 0000000..b49231d --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastScheduleTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 BroadcastScheduleTest { + + @Test + fun create() { + val broadcastSchedule = + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + + assertThat(broadcastSchedule.recipientId()).isEqualTo("recipient_id") + assertThat(broadcastSchedule.recipientType()) + .isEqualTo(BroadcastSchedule.RecipientType.LIST) + assertThat(broadcastSchedule.scheduledTo()).contains("scheduled_to") + assertThat(broadcastSchedule.timezone()).contains("timezone") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val broadcastSchedule = + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + + val roundtrippedBroadcastSchedule = + jsonMapper.readValue( + jsonMapper.writeValueAsString(broadcastSchedule), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBroadcastSchedule).isEqualTo(broadcastSchedule) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastSendParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastSendParamsTest.kt new file mode 100644 index 0000000..4bd1c56 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastSendParamsTest.kt @@ -0,0 +1,64 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastSendParamsTest { + + @Test + fun create() { + BroadcastSendParams.builder() + .broadcastId("broadcastId") + .sendBroadcastRequest( + SendBroadcastRequest.builder() + .recipientId("cool-customers") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + BroadcastSendParams.builder() + .broadcastId("broadcastId") + .sendBroadcastRequest( + SendBroadcastRequest.builder() + .recipientId("cool-customers") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + BroadcastSendParams.builder() + .broadcastId("broadcastId") + .sendBroadcastRequest( + SendBroadcastRequest.builder() + .recipientId("cool-customers") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + SendBroadcastRequest.builder() + .recipientId("cool-customers") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastTest.kt new file mode 100644 index 0000000..9fbe281 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastTest.kt @@ -0,0 +1,90 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 BroadcastTest { + + @Test + fun create() { + val broadcast = + Broadcast.builder() + .id("id") + .channel(Broadcast.Channel.EMAIL) + .createdAt("created_at") + .createdBy("created_by") + .name("name") + .status(Broadcast.Status.DRAFT) + .updatedAt("updated_at") + .updatedBy("updated_by") + .archivedAt("archived_at") + .archivedBy("archived_by") + .schedule( + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + ) + .build() + + assertThat(broadcast.id()).isEqualTo("id") + assertThat(broadcast.channel()).isEqualTo(Broadcast.Channel.EMAIL) + assertThat(broadcast.createdAt()).isEqualTo("created_at") + assertThat(broadcast.createdBy()).isEqualTo("created_by") + assertThat(broadcast.name()).isEqualTo("name") + assertThat(broadcast.status()).isEqualTo(Broadcast.Status.DRAFT) + assertThat(broadcast.updatedAt()).isEqualTo("updated_at") + assertThat(broadcast.updatedBy()).isEqualTo("updated_by") + assertThat(broadcast.archivedAt()).contains("archived_at") + assertThat(broadcast.archivedBy()).contains("archived_by") + assertThat(broadcast.schedule()) + .contains( + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val broadcast = + Broadcast.builder() + .id("id") + .channel(Broadcast.Channel.EMAIL) + .createdAt("created_at") + .createdBy("created_by") + .name("name") + .status(Broadcast.Status.DRAFT) + .updatedAt("updated_at") + .updatedBy("updated_by") + .archivedAt("archived_at") + .archivedBy("archived_by") + .schedule( + BroadcastSchedule.builder() + .recipientId("recipient_id") + .recipientType(BroadcastSchedule.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + ) + .build() + + val roundtrippedBroadcast = + jsonMapper.readValue( + jsonMapper.writeValueAsString(broadcast), + jacksonTypeRef(), + ) + + assertThat(roundtrippedBroadcast).isEqualTo(broadcast) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastUpdateParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastUpdateParamsTest.kt new file mode 100644 index 0000000..3bde7da --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/BroadcastUpdateParamsTest.kt @@ -0,0 +1,52 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class BroadcastUpdateParamsTest { + + @Test + fun create() { + BroadcastUpdateParams.builder() + .broadcastId("broadcastId") + .updateBroadcastRequest( + UpdateBroadcastRequest.builder().name("Spring Sale Announcement (v2)").build() + ) + .build() + } + + @Test + fun pathParams() { + val params = + BroadcastUpdateParams.builder() + .broadcastId("broadcastId") + .updateBroadcastRequest( + UpdateBroadcastRequest.builder().name("Spring Sale Announcement (v2)").build() + ) + .build() + + assertThat(params._pathParam(0)).isEqualTo("broadcastId") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } + + @Test + fun body() { + val params = + BroadcastUpdateParams.builder() + .broadcastId("broadcastId") + .updateBroadcastRequest( + UpdateBroadcastRequest.builder().name("Spring Sale Announcement (v2)").build() + ) + .build() + + val body = params._body() + + assertThat(body) + .isEqualTo( + UpdateBroadcastRequest.builder().name("Spring Sale Announcement (v2)").build() + ) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/CreateBroadcastRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/CreateBroadcastRequestTest.kt new file mode 100644 index 0000000..d4875ff --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/CreateBroadcastRequestTest.kt @@ -0,0 +1,41 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 CreateBroadcastRequestTest { + + @Test + fun create() { + val createBroadcastRequest = + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("name") + .build() + + assertThat(createBroadcastRequest.channel()).isEqualTo(CreateBroadcastRequest.Channel.EMAIL) + assertThat(createBroadcastRequest.name()).isEqualTo("name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val createBroadcastRequest = + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("name") + .build() + + val roundtrippedCreateBroadcastRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(createBroadcastRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedCreateBroadcastRequest).isEqualTo(createBroadcastRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/ScheduleBroadcastRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/ScheduleBroadcastRequestTest.kt new file mode 100644 index 0000000..550eec6 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/ScheduleBroadcastRequestTest.kt @@ -0,0 +1,48 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 ScheduleBroadcastRequestTest { + + @Test + fun create() { + val scheduleBroadcastRequest = + ScheduleBroadcastRequest.builder() + .recipientId("recipient_id") + .recipientType(ScheduleBroadcastRequest.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + + assertThat(scheduleBroadcastRequest.recipientId()).isEqualTo("recipient_id") + assertThat(scheduleBroadcastRequest.recipientType()) + .isEqualTo(ScheduleBroadcastRequest.RecipientType.LIST) + assertThat(scheduleBroadcastRequest.scheduledTo()).isEqualTo("scheduled_to") + assertThat(scheduleBroadcastRequest.timezone()).contains("timezone") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val scheduleBroadcastRequest = + ScheduleBroadcastRequest.builder() + .recipientId("recipient_id") + .recipientType(ScheduleBroadcastRequest.RecipientType.LIST) + .scheduledTo("scheduled_to") + .timezone("timezone") + .build() + + val roundtrippedScheduleBroadcastRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(scheduleBroadcastRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedScheduleBroadcastRequest).isEqualTo(scheduleBroadcastRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/SendBroadcastRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/SendBroadcastRequestTest.kt new file mode 100644 index 0000000..d2364a2 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/SendBroadcastRequestTest.kt @@ -0,0 +1,42 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 SendBroadcastRequestTest { + + @Test + fun create() { + val sendBroadcastRequest = + SendBroadcastRequest.builder() + .recipientId("recipient_id") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + + assertThat(sendBroadcastRequest.recipientId()).isEqualTo("recipient_id") + assertThat(sendBroadcastRequest.recipientType()) + .isEqualTo(SendBroadcastRequest.RecipientType.LIST) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val sendBroadcastRequest = + SendBroadcastRequest.builder() + .recipientId("recipient_id") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + + val roundtrippedSendBroadcastRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(sendBroadcastRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedSendBroadcastRequest).isEqualTo(sendBroadcastRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/UpdateBroadcastRequestTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/UpdateBroadcastRequestTest.kt new file mode 100644 index 0000000..a88666d --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/broadcasts/UpdateBroadcastRequestTest.kt @@ -0,0 +1,32 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.broadcasts + +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 UpdateBroadcastRequestTest { + + @Test + fun create() { + val updateBroadcastRequest = UpdateBroadcastRequest.builder().name("name").build() + + assertThat(updateBroadcastRequest.name()).isEqualTo("name") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val updateBroadcastRequest = UpdateBroadcastRequest.builder().name("name").build() + + val roundtrippedUpdateBroadcastRequest = + jsonMapper.readValue( + jsonMapper.writeValueAsString(updateBroadcastRequest), + jacksonTypeRef(), + ) + + assertThat(roundtrippedUpdateBroadcastRequest).isEqualTo(updateBroadcastRequest) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/BroadcastServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/BroadcastServiceAsyncTest.kt new file mode 100644 index 0000000..ab61745 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/BroadcastServiceAsyncTest.kt @@ -0,0 +1,238 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.models.ElementalMetaNodeWithType +import com.courier.models.ElementalTextNodeWithType +import com.courier.models.broadcasts.BroadcastListParams +import com.courier.models.broadcasts.BroadcastPutContentParams +import com.courier.models.broadcasts.BroadcastRetrieveContentParams +import com.courier.models.broadcasts.BroadcastScheduleParams +import com.courier.models.broadcasts.BroadcastSendParams +import com.courier.models.broadcasts.BroadcastUpdateParams +import com.courier.models.broadcasts.CreateBroadcastRequest +import com.courier.models.broadcasts.ScheduleBroadcastRequest +import com.courier.models.broadcasts.SendBroadcastRequest +import com.courier.models.broadcasts.UpdateBroadcastRequest +import com.courier.models.notifications.NotificationContentPutRequest +import com.courier.models.notifications.NotificationTemplateState +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class BroadcastServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = + broadcastServiceAsync.create( + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("Spring Sale Announcement") + .build() + ) + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = broadcastServiceAsync.retrieve("broadcastId") + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun update() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = + broadcastServiceAsync.update( + BroadcastUpdateParams.builder() + .broadcastId("broadcastId") + .updateBroadcastRequest( + UpdateBroadcastRequest.builder() + .name("Spring Sale Announcement (v2)") + .build() + ) + .build() + ) + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastListResponseFuture = + broadcastServiceAsync.list( + BroadcastListParams.builder().cursor("cursor").limit(1L).build() + ) + + val broadcastListResponse = broadcastListResponseFuture.get() + broadcastListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = broadcastServiceAsync.archive("broadcastId") + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun cancel() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = broadcastServiceAsync.cancel("broadcastId") + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun duplicate() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = broadcastServiceAsync.duplicate("broadcastId") + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun putContent() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val notificationContentMutationResponseFuture = + broadcastServiceAsync.putContent( + BroadcastPutContentParams.builder() + .broadcastId("broadcastId") + .notificationContentPutRequest( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement( + ElementalMetaNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalMetaNodeWithType.Type.META) + .build() + ) + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("2022-01-01") + .build() + ) + .state(NotificationTemplateState.DRAFT) + .build() + ) + .build() + ) + + val notificationContentMutationResponse = notificationContentMutationResponseFuture.get() + notificationContentMutationResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieveContent() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val notificationContentGetResponseFuture = + broadcastServiceAsync.retrieveContent( + BroadcastRetrieveContentParams.builder() + .broadcastId("broadcastId") + .version("version") + .build() + ) + + val notificationContentGetResponse = notificationContentGetResponseFuture.get() + notificationContentGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun schedule() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = + broadcastServiceAsync.schedule( + BroadcastScheduleParams.builder() + .broadcastId("broadcastId") + .scheduleBroadcastRequest( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .timezone("America/New_York") + .build() + ) + .build() + ) + + val broadcast = broadcastFuture.get() + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun send() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val broadcastServiceAsync = client.broadcasts() + + val broadcastFuture = + broadcastServiceAsync.send( + BroadcastSendParams.builder() + .broadcastId("broadcastId") + .sendBroadcastRequest( + SendBroadcastRequest.builder() + .recipientId("cool-customers") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + ) + .build() + ) + + val broadcast = broadcastFuture.get() + broadcast.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/BroadcastServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/BroadcastServiceTest.kt new file mode 100644 index 0000000..3031049 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/BroadcastServiceTest.kt @@ -0,0 +1,225 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.models.ElementalMetaNodeWithType +import com.courier.models.ElementalTextNodeWithType +import com.courier.models.broadcasts.BroadcastListParams +import com.courier.models.broadcasts.BroadcastPutContentParams +import com.courier.models.broadcasts.BroadcastRetrieveContentParams +import com.courier.models.broadcasts.BroadcastScheduleParams +import com.courier.models.broadcasts.BroadcastSendParams +import com.courier.models.broadcasts.BroadcastUpdateParams +import com.courier.models.broadcasts.CreateBroadcastRequest +import com.courier.models.broadcasts.ScheduleBroadcastRequest +import com.courier.models.broadcasts.SendBroadcastRequest +import com.courier.models.broadcasts.UpdateBroadcastRequest +import com.courier.models.notifications.NotificationContentPutRequest +import com.courier.models.notifications.NotificationTemplateState +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class BroadcastServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun create() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = + broadcastService.create( + CreateBroadcastRequest.builder() + .channel(CreateBroadcastRequest.Channel.EMAIL) + .name("Spring Sale Announcement") + .build() + ) + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = broadcastService.retrieve("broadcastId") + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun update() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = + broadcastService.update( + BroadcastUpdateParams.builder() + .broadcastId("broadcastId") + .updateBroadcastRequest( + UpdateBroadcastRequest.builder() + .name("Spring Sale Announcement (v2)") + .build() + ) + .build() + ) + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcastListResponse = + broadcastService.list(BroadcastListParams.builder().cursor("cursor").limit(1L).build()) + + broadcastListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun archive() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = broadcastService.archive("broadcastId") + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun cancel() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = broadcastService.cancel("broadcastId") + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun duplicate() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = broadcastService.duplicate("broadcastId") + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun putContent() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val notificationContentMutationResponse = + broadcastService.putContent( + BroadcastPutContentParams.builder() + .broadcastId("broadcastId") + .notificationContentPutRequest( + NotificationContentPutRequest.builder() + .content( + NotificationContentPutRequest.Content.builder() + .addElement( + ElementalMetaNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalMetaNodeWithType.Type.META) + .build() + ) + .addElement( + ElementalTextNodeWithType.builder() + .addChannel("string") + .if_("if") + .loop("loop") + .ref("ref") + .type(ElementalTextNodeWithType.Type.TEXT) + .build() + ) + .version("2022-01-01") + .build() + ) + .state(NotificationTemplateState.DRAFT) + .build() + ) + .build() + ) + + notificationContentMutationResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun retrieveContent() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val notificationContentGetResponse = + broadcastService.retrieveContent( + BroadcastRetrieveContentParams.builder() + .broadcastId("broadcastId") + .version("version") + .build() + ) + + notificationContentGetResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun schedule() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = + broadcastService.schedule( + BroadcastScheduleParams.builder() + .broadcastId("broadcastId") + .scheduleBroadcastRequest( + ScheduleBroadcastRequest.builder() + .recipientId("aud_01kx4h2jdafq8bk9amzvy6hbv0") + .recipientType(ScheduleBroadcastRequest.RecipientType.AUDIENCE) + .scheduledTo("2026-08-01T15:00:00") + .timezone("America/New_York") + .build() + ) + .build() + ) + + broadcast.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun send() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val broadcastService = client.broadcasts() + + val broadcast = + broadcastService.send( + BroadcastSendParams.builder() + .broadcastId("broadcastId") + .sendBroadcastRequest( + SendBroadcastRequest.builder() + .recipientId("cool-customers") + .recipientType(SendBroadcastRequest.RecipientType.LIST) + .build() + ) + .build() + ) + + broadcast.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 99c0af4..083e50c 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 @@ -57,6 +57,7 @@ internal class ProGuardCompatibilityTest { assertThat(client.auth()).isNotNull() assertThat(client.automations()).isNotNull() assertThat(client.journeys()).isNotNull() + assertThat(client.broadcasts()).isNotNull() assertThat(client.brands()).isNotNull() assertThat(client.digests()).isNotNull() assertThat(client.inbound()).isNotNull()