diff --git a/.stats.yml b/.stats.yml index 9f97df3f..79805432 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1 +1 @@ -configured_endpoints: 149 +configured_endpoints: 154 diff --git a/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunListItem.kt b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunListItem.kt new file mode 100644 index 00000000..f226cd5c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunListItem.kt @@ -0,0 +1,357 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** An Automation run as it appears in a list response. */ +class AutomationRunListItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val runId: JsonField, + private val source: JsonField>, + private val createdAt: JsonField, + private val status: JsonField, + private val templateId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("run_id") @ExcludeMissing runId: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("template_id") + @ExcludeMissing + templateId: JsonField = JsonMissing.of(), + ) : this(runId, source, createdAt, status, templateId, mutableMapOf()) + + /** + * A unique identifier representing the run. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun runId(): String = runId.getRequired("run_id") + + /** + * Internal provenance strings describing what started the run, e.g. `invoke/` or + * `segment/page/Pricing Page`. Diagnostic only — the format is unstable and should not be + * parsed. + * + * @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 source(): List = source.getRequired("source") + + /** + * When the run started, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * The state of the run: `PROCESSING`, `PROCESSED`, `WAITING`, `CANCELED`, `ERROR`, `THROTTLED`, + * or `NOT PROCESSED`. Not an enum — new values have been added before. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun status(): Optional = status.getOptional("status") + + /** + * The id of the Automation Template this run belongs to. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun templateId(): Optional = templateId.getOptional("template_id") + + /** + * Returns the raw JSON value of [runId]. + * + * Unlike [runId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("run_id") @ExcludeMissing fun _runId(): JsonField = runId + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField> = source + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [templateId]. + * + * Unlike [templateId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_id") @ExcludeMissing fun _templateId(): JsonField = templateId + + @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 [AutomationRunListItem]. + * + * The following fields are required: + * ```java + * .runId() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AutomationRunListItem]. */ + class Builder internal constructor() { + + private var runId: JsonField? = null + private var source: JsonField>? = null + private var createdAt: JsonField = JsonMissing.of() + private var status: JsonField = JsonMissing.of() + private var templateId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(automationRunListItem: AutomationRunListItem) = apply { + runId = automationRunListItem.runId + source = automationRunListItem.source.map { it.toMutableList() } + createdAt = automationRunListItem.createdAt + status = automationRunListItem.status + templateId = automationRunListItem.templateId + additionalProperties = automationRunListItem.additionalProperties.toMutableMap() + } + + /** A unique identifier representing the run. */ + fun runId(runId: String) = runId(JsonField.of(runId)) + + /** + * Sets [Builder.runId] to an arbitrary JSON value. + * + * You should usually call [Builder.runId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun runId(runId: JsonField) = apply { this.runId = runId } + + /** + * Internal provenance strings describing what started the run, e.g. `invoke/` + * or `segment/page/Pricing Page`. Diagnostic only — the format is unstable and should not + * be parsed. + */ + fun source(source: List) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun source(source: JsonField>) = apply { + this.source = source.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.source]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: String) = apply { + this.source = + (this.source ?: JsonField.of(mutableListOf())).also { + checkKnown("source", it).add(source) + } + } + + /** When the run started, as an ISO 8601 timestamp. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** + * The state of the run: `PROCESSING`, `PROCESSED`, `WAITING`, `CANCELED`, `ERROR`, + * `THROTTLED`, or `NOT PROCESSED`. Not an enum — new values have been added before. + */ + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The id of the Automation Template this run belongs to. */ + fun templateId(templateId: String) = templateId(JsonField.of(templateId)) + + /** + * Sets [Builder.templateId] to an arbitrary JSON value. + * + * You should usually call [Builder.templateId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun templateId(templateId: JsonField) = apply { this.templateId = templateId } + + 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 [AutomationRunListItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .runId() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AutomationRunListItem = + AutomationRunListItem( + checkRequired("runId", runId), + checkRequired("source", source).map { it.toImmutable() }, + createdAt, + status, + templateId, + 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(): AutomationRunListItem = apply { + if (validated) { + return@apply + } + + runId() + source() + createdAt() + status() + templateId() + 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 (runId.asKnown().isPresent) 1 else 0) + + (source.asKnown().getOrNull()?.size ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (templateId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AutomationRunListItem && + runId == other.runId && + source == other.source && + createdAt == other.createdAt && + status == other.status && + templateId == other.templateId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(runId, source, createdAt, status, templateId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutomationRunListItem{runId=$runId, source=$source, createdAt=$createdAt, status=$status, templateId=$templateId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunListResponse.kt new file mode 100644 index 00000000..2f2c5df8 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunListResponse.kt @@ -0,0 +1,236 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A page of Automation runs. */ +class AutomationRunListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val runs: JsonField>, + private val nextCursor: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("runs") + @ExcludeMissing + runs: JsonField> = JsonMissing.of(), + @JsonProperty("next_cursor") + @ExcludeMissing + nextCursor: JsonField = JsonMissing.of(), + ) : this(runs, nextCursor, 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 runs(): List = runs.getRequired("runs") + + /** + * Pass back as `cursor` to fetch the next page. Absent on the last page. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextCursor(): Optional = nextCursor.getOptional("next_cursor") + + /** + * Returns the raw JSON value of [runs]. + * + * Unlike [runs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("runs") @ExcludeMissing fun _runs(): JsonField> = runs + + /** + * Returns the raw JSON value of [nextCursor]. + * + * Unlike [nextCursor], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_cursor") @ExcludeMissing fun _nextCursor(): JsonField = nextCursor + + @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 [AutomationRunListResponse]. + * + * The following fields are required: + * ```java + * .runs() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AutomationRunListResponse]. */ + class Builder internal constructor() { + + private var runs: JsonField>? = null + private var nextCursor: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(automationRunListResponse: AutomationRunListResponse) = apply { + runs = automationRunListResponse.runs.map { it.toMutableList() } + nextCursor = automationRunListResponse.nextCursor + additionalProperties = automationRunListResponse.additionalProperties.toMutableMap() + } + + fun runs(runs: List) = runs(JsonField.of(runs)) + + /** + * Sets [Builder.runs] to an arbitrary JSON value. + * + * You should usually call [Builder.runs] with a well-typed `List` + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun runs(runs: JsonField>) = apply { + this.runs = runs.map { it.toMutableList() } + } + + /** + * Adds a single [AutomationRunListItem] to [runs]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRun(run: AutomationRunListItem) = apply { + runs = (runs ?: JsonField.of(mutableListOf())).also { checkKnown("runs", it).add(run) } + } + + /** Pass back as `cursor` to fetch the next page. Absent on the last page. */ + fun nextCursor(nextCursor: String) = nextCursor(JsonField.of(nextCursor)) + + /** + * Sets [Builder.nextCursor] to an arbitrary JSON value. + * + * You should usually call [Builder.nextCursor] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextCursor(nextCursor: JsonField) = apply { this.nextCursor = nextCursor } + + 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 [AutomationRunListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .runs() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AutomationRunListResponse = + AutomationRunListResponse( + checkRequired("runs", runs).map { it.toImmutable() }, + nextCursor, + 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(): AutomationRunListResponse = apply { + if (validated) { + return@apply + } + + runs().forEach { it.validate() } + nextCursor() + 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 = + (runs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextCursor.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AutomationRunListResponse && + runs == other.runs && + nextCursor == other.nextCursor && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(runs, nextCursor, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutomationRunListResponse{runs=$runs, nextCursor=$nextCursor, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunStep.kt b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunStep.kt new file mode 100644 index 00000000..b65dda1a --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunStep.kt @@ -0,0 +1,372 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +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 + +/** One executed step of an Automation run. */ +class AutomationRunStep +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val action: JsonField, + private val status: JsonField, + private val createdAt: JsonField, + private val messageId: JsonField, + private val stepId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("action") @ExcludeMissing action: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("message_id") @ExcludeMissing messageId: JsonField = JsonMissing.of(), + @JsonProperty("step_id") @ExcludeMissing stepId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this(action, status, createdAt, messageId, stepId, updatedAt, mutableMapOf()) + + /** + * The kind of step that ran, e.g. `send`, `delay`, or `update-profile`. + * + * @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 action(): String = action.getRequired("action") + + /** + * The state of the step: the seven run statuses, plus `SKIPPED` and `COMPUTING`. Not an enum — + * new values have been added before. + * + * @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(): String = status.getRequired("status") + + /** + * When the step started, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * The message this step produced, present on send steps. Pass it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one id + * for the request, not one per recipient. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun messageId(): Optional = messageId.getOptional("message_id") + + /** + * A unique identifier representing the step. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun stepId(): Optional = stepId.getOptional("step_id") + + /** + * When the step last changed state, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [action]. + * + * Unlike [action], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action + + /** + * 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 [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 [messageId]. + * + * Unlike [messageId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("message_id") @ExcludeMissing fun _messageId(): JsonField = messageId + + /** + * Returns the raw JSON value of [stepId]. + * + * Unlike [stepId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("step_id") @ExcludeMissing fun _stepId(): JsonField = stepId + + /** + * 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 + + @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 [AutomationRunStep]. + * + * The following fields are required: + * ```java + * .action() + * .status() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AutomationRunStep]. */ + class Builder internal constructor() { + + private var action: JsonField? = null + private var status: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var messageId: JsonField = JsonMissing.of() + private var stepId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(automationRunStep: AutomationRunStep) = apply { + action = automationRunStep.action + status = automationRunStep.status + createdAt = automationRunStep.createdAt + messageId = automationRunStep.messageId + stepId = automationRunStep.stepId + updatedAt = automationRunStep.updatedAt + additionalProperties = automationRunStep.additionalProperties.toMutableMap() + } + + /** The kind of step that ran, e.g. `send`, `delay`, or `update-profile`. */ + fun action(action: String) = action(JsonField.of(action)) + + /** + * Sets [Builder.action] to an arbitrary JSON value. + * + * You should usually call [Builder.action] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun action(action: JsonField) = apply { this.action = action } + + /** + * The state of the step: the seven run statuses, plus `SKIPPED` and `COMPUTING`. Not an + * enum — new values have been added before. + */ + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] 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 } + + /** When the step started, as an ISO 8601 timestamp. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** + * The message this step produced, present on send steps. Pass it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one + * id for the request, not one per recipient. + */ + fun messageId(messageId: String) = messageId(JsonField.of(messageId)) + + /** + * Sets [Builder.messageId] to an arbitrary JSON value. + * + * You should usually call [Builder.messageId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun messageId(messageId: JsonField) = apply { this.messageId = messageId } + + /** A unique identifier representing the step. */ + fun stepId(stepId: String) = stepId(JsonField.of(stepId)) + + /** + * Sets [Builder.stepId] to an arbitrary JSON value. + * + * You should usually call [Builder.stepId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun stepId(stepId: JsonField) = apply { this.stepId = stepId } + + /** When the step last changed state, as an ISO 8601 timestamp. */ + 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 } + + 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 [AutomationRunStep]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .action() + * .status() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AutomationRunStep = + AutomationRunStep( + checkRequired("action", action), + checkRequired("status", status), + createdAt, + messageId, + stepId, + updatedAt, + 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(): AutomationRunStep = apply { + if (validated) { + return@apply + } + + action() + status() + createdAt() + messageId() + stepId() + updatedAt() + 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 (action.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (messageId.asKnown().isPresent) 1 else 0) + + (if (stepId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AutomationRunStep && + action == other.action && + status == other.status && + createdAt == other.createdAt && + messageId == other.messageId && + stepId == other.stepId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(action, status, createdAt, messageId, stepId, updatedAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutomationRunStep{action=$action, status=$status, createdAt=$createdAt, messageId=$messageId, stepId=$stepId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunStepsResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunStepsResponse.kt new file mode 100644 index 00000000..55dd1bb7 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/automations/AutomationRunStepsResponse.kt @@ -0,0 +1,199 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Every step of an Automation run. Not paginated. */ +class AutomationRunStepsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val steps: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("steps") + @ExcludeMissing + steps: JsonField> = JsonMissing.of() + ) : this(steps, 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 steps(): List = steps.getRequired("steps") + + /** + * Returns the raw JSON value of [steps]. + * + * Unlike [steps], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("steps") @ExcludeMissing fun _steps(): JsonField> = steps + + @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 [AutomationRunStepsResponse]. + * + * The following fields are required: + * ```java + * .steps() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [AutomationRunStepsResponse]. */ + class Builder internal constructor() { + + private var steps: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(automationRunStepsResponse: AutomationRunStepsResponse) = apply { + steps = automationRunStepsResponse.steps.map { it.toMutableList() } + additionalProperties = automationRunStepsResponse.additionalProperties.toMutableMap() + } + + fun steps(steps: List) = steps(JsonField.of(steps)) + + /** + * Sets [Builder.steps] to an arbitrary JSON value. + * + * You should usually call [Builder.steps] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun steps(steps: JsonField>) = apply { + this.steps = steps.map { it.toMutableList() } + } + + /** + * Adds a single [AutomationRunStep] to [steps]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStep(step: AutomationRunStep) = apply { + steps = + (steps ?: JsonField.of(mutableListOf())).also { checkKnown("steps", it).add(step) } + } + + 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 [AutomationRunStepsResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .steps() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): AutomationRunStepsResponse = + AutomationRunStepsResponse( + checkRequired("steps", steps).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(): AutomationRunStepsResponse = apply { + if (validated) { + return@apply + } + + steps().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 = + (steps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is AutomationRunStepsResponse && + steps == other.steps && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(steps, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "AutomationRunStepsResponse{steps=$steps, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/automations/runs/RunListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/automations/runs/RunListParams.kt new file mode 100644 index 00000000..f6c872c5 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/automations/runs/RunListParams.kt @@ -0,0 +1,302 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations.runs + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * List runs of the workspace's v2 Automations, newest first, filtered by status, Template, or date + * range and paged by cursor. Journey (v3) runs are listed by `GET /journeys/runs` instead — the two + * surfaces never return each other's runs. Runs are retained for 95 days. + */ +class RunListParams +private constructor( + private val cursor: String?, + private val endDate: String?, + private val limit: String?, + private val startDate: String?, + private val status: String?, + private val templateId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * A cursor token for pagination. Use the `next_cursor` from the previous response to fetch the + * next page of results. Treat it as opaque. + */ + fun cursor(): Optional = Optional.ofNullable(cursor) + + /** An inclusive upper bound on `created_at`, in the same format as `start_date`. */ + fun endDate(): Optional = Optional.ofNullable(endDate) + + /** + * The number of runs to return per page, between `1` and `50`. Defaults to `20`. Values outside + * the range are clamped, and a non-numeric value falls back to `20`. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * An inclusive lower bound on `created_at`, as an ISO 8601 date or timestamp (e.g. `2026-08-18` + * or `2026-08-18T20:06:36.259Z`). Any other format returns `400`. + */ + fun startDate(): Optional = Optional.ofNullable(startDate) + + /** A comma-separated list of run statuses to filter on, e.g. `PROCESSED,ERROR`. */ + fun status(): Optional = Optional.ofNullable(status) + + /** A comma-separated list of Automation Template ids to filter on. */ + fun templateId(): Optional = Optional.ofNullable(templateId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): RunListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RunListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListParams]. */ + class Builder internal constructor() { + + private var cursor: String? = null + private var endDate: String? = null + private var limit: String? = null + private var startDate: String? = null + private var status: String? = null + private var templateId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runListParams: RunListParams) = apply { + cursor = runListParams.cursor + endDate = runListParams.endDate + limit = runListParams.limit + startDate = runListParams.startDate + status = runListParams.status + templateId = runListParams.templateId + additionalHeaders = runListParams.additionalHeaders.toBuilder() + additionalQueryParams = runListParams.additionalQueryParams.toBuilder() + } + + /** + * A cursor token for pagination. Use the `next_cursor` from the previous response to fetch + * the next page of results. Treat it as opaque. + */ + fun cursor(cursor: String?) = apply { this.cursor = cursor } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** An inclusive upper bound on `created_at`, in the same format as `start_date`. */ + fun endDate(endDate: String?) = apply { this.endDate = endDate } + + /** Alias for calling [Builder.endDate] with `endDate.orElse(null)`. */ + fun endDate(endDate: Optional) = endDate(endDate.getOrNull()) + + /** + * The number of runs to return per page, between `1` and `50`. Defaults to `20`. Values + * outside the range are clamped, and a non-numeric value falls back to `20`. + */ + fun limit(limit: String?) = apply { this.limit = limit } + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * An inclusive lower bound on `created_at`, as an ISO 8601 date or timestamp (e.g. + * `2026-08-18` or `2026-08-18T20:06:36.259Z`). Any other format returns `400`. + */ + fun startDate(startDate: String?) = apply { this.startDate = startDate } + + /** Alias for calling [Builder.startDate] with `startDate.orElse(null)`. */ + fun startDate(startDate: Optional) = startDate(startDate.getOrNull()) + + /** A comma-separated list of run statuses to filter on, e.g. `PROCESSED,ERROR`. */ + fun status(status: String?) = apply { this.status = status } + + /** Alias for calling [Builder.status] with `status.orElse(null)`. */ + fun status(status: Optional) = status(status.getOrNull()) + + /** A comma-separated list of Automation Template ids to filter on. */ + fun templateId(templateId: String?) = apply { this.templateId = templateId } + + /** Alias for calling [Builder.templateId] with `templateId.orElse(null)`. */ + fun templateId(templateId: Optional) = templateId(templateId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RunListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RunListParams = + RunListParams( + cursor, + endDate, + limit, + startDate, + status, + templateId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + cursor?.let { put("cursor", it) } + endDate?.let { put("end_date", it) } + limit?.let { put("limit", it) } + startDate?.let { put("start_date", it) } + status?.let { put("status", it) } + templateId?.let { put("template_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RunListParams && + cursor == other.cursor && + endDate == other.endDate && + limit == other.limit && + startDate == other.startDate && + status == other.status && + templateId == other.templateId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + cursor, + endDate, + limit, + startDate, + status, + templateId, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "RunListParams{cursor=$cursor, endDate=$endDate, limit=$limit, startDate=$startDate, status=$status, templateId=$templateId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/automations/runs/RunListStepsParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/automations/runs/RunListStepsParams.kt new file mode 100644 index 00000000..77241028 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/automations/runs/RunListStepsParams.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations.runs + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * List the per-step state of one Automation run, in full — this endpoint is not paginated. + * `message_id` is present on send steps that produced a message; follow it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one + * `message_id` for the request, not one per recipient. + */ +class RunListStepsParams +private constructor( + private val id: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun id(): Optional = Optional.ofNullable(id) + + /** 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(): RunListStepsParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RunListStepsParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListStepsParams]. */ + class Builder internal constructor() { + + private var id: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runListStepsParams: RunListStepsParams) = apply { + id = runListStepsParams.id + additionalHeaders = runListStepsParams.additionalHeaders.toBuilder() + additionalQueryParams = runListStepsParams.additionalQueryParams.toBuilder() + } + + fun id(id: String?) = apply { this.id = id } + + /** Alias for calling [Builder.id] with `id.orElse(null)`. */ + fun id(id: Optional) = id(id.getOrNull()) + + fun 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 [RunListStepsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RunListStepsParams = + RunListStepsParams(id, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> id ?: "" + 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 RunListStepsParams && + id == other.id && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(id, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RunListStepsParams{id=$id, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/CreateJourneyRequest.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/CreateJourneyRequest.kt index 8badf43a..211f4a22 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/journeys/CreateJourneyRequest.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/CreateJourneyRequest.kt @@ -179,6 +179,14 @@ private constructor( fun addNode(segmentTrigger: JourneySegmentTriggerNode) = addNode(JourneyNode.ofSegmentTrigger(segmentTrigger)) + /** Alias for calling [addNode] with `JourneyNode.ofAudienceTrigger(audienceTrigger)`. */ + fun addNode(audienceTrigger: JourneyAudienceTriggerNode) = + addNode(JourneyNode.ofAudienceTrigger(audienceTrigger)) + + /** Alias for calling [addNode] with `JourneyNode.ofWebhookTrigger(webhookTrigger)`. */ + fun addNode(webhookTrigger: JourneyWebhookTriggerNode) = + addNode(JourneyNode.ofWebhookTrigger(webhookTrigger)) + /** Alias for calling [addNode] with `JourneyNode.ofSend(send)`. */ fun addNode(send: JourneySendNode) = addNode(JourneyNode.ofSend(send)) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyAudienceTriggerNode.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyAudienceTriggerNode.kt new file mode 100644 index 00000000..6f0212e3 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyAudienceTriggerNode.kt @@ -0,0 +1,628 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 + +/** + * Trigger fired when a user newly matches an Audience. Leaving and re-joining the Audience + * re-enters the Journey. Membership is new-members-only: users already in the Audience when the + * Journey is published do not enter. Unlike the v2 Automations audience trigger, there is no member + * scope, event type, or frequency mode to configure, and `audience_id` must name one Audience — + * wildcards are not supported. + */ +class JourneyAudienceTriggerNode +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val audienceId: JsonField, + private val triggerType: JsonField, + private val type: JsonField, + private val id: JsonField, + private val conditions: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("audience_id") + @ExcludeMissing + audienceId: JsonField = JsonMissing.of(), + @JsonProperty("trigger_type") + @ExcludeMissing + triggerType: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("conditions") + @ExcludeMissing + conditions: JsonField = JsonMissing.of(), + ) : this(audienceId, triggerType, type, id, conditions, mutableMapOf()) + + /** + * The Audience to watch. Must name a single Audience; wildcards are not supported. + * + * @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 audienceId(): String = audienceId.getRequired("audience_id") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun triggerType(): TriggerType = triggerType.getRequired("trigger_type") + + /** + * @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 type(): Type = type.getRequired("type") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun id(): Optional = id.getOptional("id") + + /** + * Condition spec for a journey node. Accepts a single condition atom, an AND/OR group, or an + * AND/OR nested group. Omit the `conditions` property entirely to express "no conditions". + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conditions(): Optional = conditions.getOptional("conditions") + + /** + * Returns the raw JSON value of [audienceId]. + * + * Unlike [audienceId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("audience_id") @ExcludeMissing fun _audienceId(): JsonField = audienceId + + /** + * Returns the raw JSON value of [triggerType]. + * + * Unlike [triggerType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("trigger_type") + @ExcludeMissing + fun _triggerType(): JsonField = triggerType + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * 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 [conditions]. + * + * Unlike [conditions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("conditions") + @ExcludeMissing + fun _conditions(): JsonField = conditions + + @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 [JourneyAudienceTriggerNode]. + * + * The following fields are required: + * ```java + * .audienceId() + * .triggerType() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyAudienceTriggerNode]. */ + class Builder internal constructor() { + + private var audienceId: JsonField? = null + private var triggerType: JsonField? = null + private var type: JsonField? = null + private var id: JsonField = JsonMissing.of() + private var conditions: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyAudienceTriggerNode: JourneyAudienceTriggerNode) = apply { + audienceId = journeyAudienceTriggerNode.audienceId + triggerType = journeyAudienceTriggerNode.triggerType + type = journeyAudienceTriggerNode.type + id = journeyAudienceTriggerNode.id + conditions = journeyAudienceTriggerNode.conditions + additionalProperties = journeyAudienceTriggerNode.additionalProperties.toMutableMap() + } + + /** The Audience to watch. Must name a single Audience; wildcards are not supported. */ + fun audienceId(audienceId: String) = audienceId(JsonField.of(audienceId)) + + /** + * Sets [Builder.audienceId] to an arbitrary JSON value. + * + * You should usually call [Builder.audienceId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun audienceId(audienceId: JsonField) = apply { this.audienceId = audienceId } + + fun triggerType(triggerType: TriggerType) = triggerType(JsonField.of(triggerType)) + + /** + * Sets [Builder.triggerType] to an arbitrary JSON value. + * + * You should usually call [Builder.triggerType] with a well-typed [TriggerType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun triggerType(triggerType: JsonField) = apply { + this.triggerType = triggerType + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + 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 } + + /** + * Condition spec for a journey node. Accepts a single condition atom, an AND/OR group, or + * an AND/OR nested group. Omit the `conditions` property entirely to express "no + * conditions". + */ + fun conditions(conditions: JourneyConditionsField) = conditions(JsonField.of(conditions)) + + /** + * Sets [Builder.conditions] to an arbitrary JSON value. + * + * You should usually call [Builder.conditions] with a well-typed [JourneyConditionsField] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conditions(conditions: JsonField) = apply { + this.conditions = conditions + } + + /** + * Alias for calling [conditions] with + * `JourneyConditionsField.ofConditionAtom(conditionAtom)`. + */ + fun conditionsOfConditionAtom(conditionAtom: List) = + conditions(JourneyConditionsField.ofConditionAtom(conditionAtom)) + + /** + * Alias for calling [conditions] with + * `JourneyConditionsField.ofConditionGroup(conditionGroup)`. + */ + fun conditions(conditionGroup: JourneyConditionGroup) = + conditions(JourneyConditionsField.ofConditionGroup(conditionGroup)) + + /** + * Alias for calling [conditions] with + * `JourneyConditionsField.ofConditionNestedGroup(conditionNestedGroup)`. + */ + fun conditions(conditionNestedGroup: JourneyConditionNestedGroup) = + conditions(JourneyConditionsField.ofConditionNestedGroup(conditionNestedGroup)) + + 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 [JourneyAudienceTriggerNode]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .audienceId() + * .triggerType() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyAudienceTriggerNode = + JourneyAudienceTriggerNode( + checkRequired("audienceId", audienceId), + checkRequired("triggerType", triggerType), + checkRequired("type", type), + id, + conditions, + 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(): JourneyAudienceTriggerNode = apply { + if (validated) { + return@apply + } + + audienceId() + triggerType().validate() + type().validate() + id() + conditions().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 (audienceId.asKnown().isPresent) 1 else 0) + + (triggerType.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (id.asKnown().isPresent) 1 else 0) + + (conditions.asKnown().getOrNull()?.validity() ?: 0) + + class TriggerType @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 AUDIENCE = of("audience") + + @JvmStatic fun of(value: String) = TriggerType(JsonField.of(value)) + } + + /** An enum containing [TriggerType]'s known values. */ + enum class Known { + AUDIENCE + } + + /** + * An enum containing [TriggerType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [TriggerType] 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 { + AUDIENCE, + /** + * An enum member indicating that [TriggerType] 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) { + 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) { + AUDIENCE -> Known.AUDIENCE + else -> throw CourierInvalidDataException("Unknown TriggerType: $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(): TriggerType = 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 TriggerType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @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 TRIGGER = of("trigger") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TRIGGER + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] 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 { + TRIGGER, + /** An enum member indicating that [Type] 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) { + TRIGGER -> Value.TRIGGER + 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) { + TRIGGER -> Known.TRIGGER + else -> throw CourierInvalidDataException("Unknown Type: $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(): Type = 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 Type && 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 JourneyAudienceTriggerNode && + audienceId == other.audienceId && + triggerType == other.triggerType && + type == other.type && + id == other.id && + conditions == other.conditions && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(audienceId, triggerType, type, id, conditions, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyAudienceTriggerNode{audienceId=$audienceId, triggerType=$triggerType, type=$type, id=$id, conditions=$conditions, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyNode.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyNode.kt index 218470fb..5c5db478 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyNode.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyNode.kt @@ -42,6 +42,8 @@ class JourneyNode private constructor( private val apiInvokeTrigger: JourneyApiInvokeTriggerNode? = null, private val segmentTrigger: JourneySegmentTriggerNode? = null, + private val audienceTrigger: JourneyAudienceTriggerNode? = null, + private val webhookTrigger: JourneyWebhookTriggerNode? = null, private val send: JourneySendNode? = null, private val delayDuration: JourneyDelayDurationNode? = null, private val delayUntil: JourneyDelayUntilNode? = null, @@ -64,9 +66,30 @@ private constructor( fun apiInvokeTrigger(): Optional = Optional.ofNullable(apiInvokeTrigger) - /** Trigger fired by a segment event (`identify`, `group`, or `track`). */ + /** + * Trigger fired by a segment event (`identify`, `group`, `track`, or `page`). A trigger with no + * `event_id` fires on any event of its type — the only shape `identify` and `group` can take, + * and the one that catches a stock `analytics.page()` call. + */ fun segmentTrigger(): Optional = Optional.ofNullable(segmentTrigger) + /** + * Trigger fired when a user newly matches an Audience. Leaving and re-joining the Audience + * re-enters the Journey. Membership is new-members-only: users already in the Audience when the + * Journey is published do not enter. Unlike the v2 Automations audience trigger, there is no + * member scope, event type, or frequency mode to configure, and `audience_id` must name one + * Audience — wildcards are not supported. + */ + fun audienceTrigger(): Optional = + Optional.ofNullable(audienceTrigger) + + /** + * Trigger fired when an external system POSTs to the webhook URL minted for `event_source`. + * Narrow it to one event with `event_id`, or omit `event_id` to accept every event delivered to + * the URL. + */ + fun webhookTrigger(): Optional = Optional.ofNullable(webhookTrigger) + /** * Send to the recipient. A send node sources its content from EXACTLY ONE of `message.template` * (a single notification template) or `experiment` (an A/B split across weighted template @@ -139,6 +162,10 @@ private constructor( fun isSegmentTrigger(): Boolean = segmentTrigger != null + fun isAudienceTrigger(): Boolean = audienceTrigger != null + + fun isWebhookTrigger(): Boolean = webhookTrigger != null + fun isSend(): Boolean = send != null fun isDelayDuration(): Boolean = delayDuration != null @@ -170,9 +197,30 @@ private constructor( fun asApiInvokeTrigger(): JourneyApiInvokeTriggerNode = apiInvokeTrigger.getOrThrow("apiInvokeTrigger") - /** Trigger fired by a segment event (`identify`, `group`, or `track`). */ + /** + * Trigger fired by a segment event (`identify`, `group`, `track`, or `page`). A trigger with no + * `event_id` fires on any event of its type — the only shape `identify` and `group` can take, + * and the one that catches a stock `analytics.page()` call. + */ fun asSegmentTrigger(): JourneySegmentTriggerNode = segmentTrigger.getOrThrow("segmentTrigger") + /** + * Trigger fired when a user newly matches an Audience. Leaving and re-joining the Audience + * re-enters the Journey. Membership is new-members-only: users already in the Audience when the + * Journey is published do not enter. Unlike the v2 Automations audience trigger, there is no + * member scope, event type, or frequency mode to configure, and `audience_id` must name one + * Audience — wildcards are not supported. + */ + fun asAudienceTrigger(): JourneyAudienceTriggerNode = + audienceTrigger.getOrThrow("audienceTrigger") + + /** + * Trigger fired when an external system POSTs to the webhook URL minted for `event_source`. + * Narrow it to one event with `event_id`, or omit `event_id` to accept every event delivered to + * the URL. + */ + fun asWebhookTrigger(): JourneyWebhookTriggerNode = webhookTrigger.getOrThrow("webhookTrigger") + /** * Send to the recipient. A send node sources its content from EXACTLY ONE of `message.template` * (a single notification template) or `experiment` (an A/B split across weighted template @@ -276,6 +324,8 @@ private constructor( when { apiInvokeTrigger != null -> visitor.visitApiInvokeTrigger(apiInvokeTrigger) segmentTrigger != null -> visitor.visitSegmentTrigger(segmentTrigger) + audienceTrigger != null -> visitor.visitAudienceTrigger(audienceTrigger) + webhookTrigger != null -> visitor.visitWebhookTrigger(webhookTrigger) send != null -> visitor.visitSend(send) delayDuration != null -> visitor.visitDelayDuration(delayDuration) delayUntil != null -> visitor.visitDelayUntil(delayUntil) @@ -316,6 +366,14 @@ private constructor( segmentTrigger.validate() } + override fun visitAudienceTrigger(audienceTrigger: JourneyAudienceTriggerNode) { + audienceTrigger.validate() + } + + override fun visitWebhookTrigger(webhookTrigger: JourneyWebhookTriggerNode) { + webhookTrigger.validate() + } + override fun visitSend(send: JourneySendNode) { send.validate() } @@ -391,6 +449,12 @@ private constructor( override fun visitSegmentTrigger(segmentTrigger: JourneySegmentTriggerNode) = segmentTrigger.validity() + override fun visitAudienceTrigger(audienceTrigger: JourneyAudienceTriggerNode) = + audienceTrigger.validity() + + override fun visitWebhookTrigger(webhookTrigger: JourneyWebhookTriggerNode) = + webhookTrigger.validity() + override fun visitSend(send: JourneySendNode) = send.validity() override fun visitDelayDuration(delayDuration: JourneyDelayDurationNode) = @@ -434,6 +498,8 @@ private constructor( return other is JourneyNode && apiInvokeTrigger == other.apiInvokeTrigger && segmentTrigger == other.segmentTrigger && + audienceTrigger == other.audienceTrigger && + webhookTrigger == other.webhookTrigger && send == other.send && delayDuration == other.delayDuration && delayUntil == other.delayUntil && @@ -452,6 +518,8 @@ private constructor( Objects.hash( apiInvokeTrigger, segmentTrigger, + audienceTrigger, + webhookTrigger, send, delayDuration, delayUntil, @@ -470,6 +538,8 @@ private constructor( when { apiInvokeTrigger != null -> "JourneyNode{apiInvokeTrigger=$apiInvokeTrigger}" segmentTrigger != null -> "JourneyNode{segmentTrigger=$segmentTrigger}" + audienceTrigger != null -> "JourneyNode{audienceTrigger=$audienceTrigger}" + webhookTrigger != null -> "JourneyNode{webhookTrigger=$webhookTrigger}" send != null -> "JourneyNode{send=$send}" delayDuration != null -> "JourneyNode{delayDuration=$delayDuration}" delayUntil != null -> "JourneyNode{delayUntil=$delayUntil}" @@ -496,11 +566,35 @@ private constructor( fun ofApiInvokeTrigger(apiInvokeTrigger: JourneyApiInvokeTriggerNode) = JourneyNode(apiInvokeTrigger = apiInvokeTrigger) - /** Trigger fired by a segment event (`identify`, `group`, or `track`). */ + /** + * Trigger fired by a segment event (`identify`, `group`, `track`, or `page`). A trigger + * with no `event_id` fires on any event of its type — the only shape `identify` and `group` + * can take, and the one that catches a stock `analytics.page()` call. + */ @JvmStatic fun ofSegmentTrigger(segmentTrigger: JourneySegmentTriggerNode) = JourneyNode(segmentTrigger = segmentTrigger) + /** + * Trigger fired when a user newly matches an Audience. Leaving and re-joining the Audience + * re-enters the Journey. Membership is new-members-only: users already in the Audience when + * the Journey is published do not enter. Unlike the v2 Automations audience trigger, there + * is no member scope, event type, or frequency mode to configure, and `audience_id` must + * name one Audience — wildcards are not supported. + */ + @JvmStatic + fun ofAudienceTrigger(audienceTrigger: JourneyAudienceTriggerNode) = + JourneyNode(audienceTrigger = audienceTrigger) + + /** + * Trigger fired when an external system POSTs to the webhook URL minted for `event_source`. + * Narrow it to one event with `event_id`, or omit `event_id` to accept every event + * delivered to the URL. + */ + @JvmStatic + fun ofWebhookTrigger(webhookTrigger: JourneyWebhookTriggerNode) = + JourneyNode(webhookTrigger = webhookTrigger) + /** * Send to the recipient. A send node sources its content from EXACTLY ONE of * `message.template` (a single notification template) or `experiment` (an A/B split across @@ -593,9 +687,29 @@ private constructor( */ fun visitApiInvokeTrigger(apiInvokeTrigger: JourneyApiInvokeTriggerNode): T - /** Trigger fired by a segment event (`identify`, `group`, or `track`). */ + /** + * Trigger fired by a segment event (`identify`, `group`, `track`, or `page`). A trigger + * with no `event_id` fires on any event of its type — the only shape `identify` and `group` + * can take, and the one that catches a stock `analytics.page()` call. + */ fun visitSegmentTrigger(segmentTrigger: JourneySegmentTriggerNode): T + /** + * Trigger fired when a user newly matches an Audience. Leaving and re-joining the Audience + * re-enters the Journey. Membership is new-members-only: users already in the Audience when + * the Journey is published do not enter. Unlike the v2 Automations audience trigger, there + * is no member scope, event type, or frequency mode to configure, and `audience_id` must + * name one Audience — wildcards are not supported. + */ + fun visitAudienceTrigger(audienceTrigger: JourneyAudienceTriggerNode): T + + /** + * Trigger fired when an external system POSTs to the webhook URL minted for `event_source`. + * Narrow it to one event with `event_id`, or omit `event_id` to accept every event + * delivered to the URL. + */ + fun visitWebhookTrigger(webhookTrigger: JourneyWebhookTriggerNode): T + /** * Send to the recipient. A send node sources its content from EXACTLY ONE of * `message.template` (a single notification template) or `experiment` (an A/B split across @@ -690,6 +804,12 @@ private constructor( tryDeserialize(node, jacksonTypeRef())?.let { JourneyNode(segmentTrigger = it, _json = json) }, + tryDeserialize(node, jacksonTypeRef())?.let { + JourneyNode(audienceTrigger = it, _json = json) + }, + tryDeserialize(node, jacksonTypeRef())?.let { + JourneyNode(webhookTrigger = it, _json = json) + }, tryDeserialize(node, jacksonTypeRef())?.let { JourneyNode(send = it, _json = json) }, @@ -752,6 +872,8 @@ private constructor( when { value.apiInvokeTrigger != null -> generator.writeObject(value.apiInvokeTrigger) value.segmentTrigger != null -> generator.writeObject(value.segmentTrigger) + value.audienceTrigger != null -> generator.writeObject(value.audienceTrigger) + value.webhookTrigger != null -> generator.writeObject(value.webhookTrigger) value.send != null -> generator.writeObject(value.send) value.delayDuration != null -> generator.writeObject(value.delayDuration) value.delayUntil != null -> generator.writeObject(value.delayUntil) @@ -2824,6 +2946,19 @@ private constructor( fun addNode(segmentTrigger: JourneySegmentTriggerNode) = addNode(JourneyNode.ofSegmentTrigger(segmentTrigger)) + /** + * Alias for calling [addNode] with + * `JourneyNode.ofAudienceTrigger(audienceTrigger)`. + */ + fun addNode(audienceTrigger: JourneyAudienceTriggerNode) = + addNode(JourneyNode.ofAudienceTrigger(audienceTrigger)) + + /** + * Alias for calling [addNode] with `JourneyNode.ofWebhookTrigger(webhookTrigger)`. + */ + fun addNode(webhookTrigger: JourneyWebhookTriggerNode) = + addNode(JourneyNode.ofWebhookTrigger(webhookTrigger)) + /** Alias for calling [addNode] with `JourneyNode.ofSend(send)`. */ fun addNode(send: JourneySendNode) = addNode(JourneyNode.ofSend(send)) @@ -3179,6 +3314,19 @@ private constructor( fun addNode(segmentTrigger: JourneySegmentTriggerNode) = addNode(JourneyNode.ofSegmentTrigger(segmentTrigger)) + /** + * Alias for calling [addNode] with + * `JourneyNode.ofAudienceTrigger(audienceTrigger)`. + */ + fun addNode(audienceTrigger: JourneyAudienceTriggerNode) = + addNode(JourneyNode.ofAudienceTrigger(audienceTrigger)) + + /** + * Alias for calling [addNode] with `JourneyNode.ofWebhookTrigger(webhookTrigger)`. + */ + fun addNode(webhookTrigger: JourneyWebhookTriggerNode) = + addNode(JourneyNode.ofWebhookTrigger(webhookTrigger)) + /** Alias for calling [addNode] with `JourneyNode.ofSend(send)`. */ fun addNode(send: JourneySendNode) = addNode(JourneyNode.ofSend(send)) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyResponse.kt index 64a31e0e..abe7e70a 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyResponse.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyResponse.kt @@ -354,6 +354,14 @@ private constructor( fun addNode(segmentTrigger: JourneySegmentTriggerNode) = addNode(JourneyNode.ofSegmentTrigger(segmentTrigger)) + /** Alias for calling [addNode] with `JourneyNode.ofAudienceTrigger(audienceTrigger)`. */ + fun addNode(audienceTrigger: JourneyAudienceTriggerNode) = + addNode(JourneyNode.ofAudienceTrigger(audienceTrigger)) + + /** Alias for calling [addNode] with `JourneyNode.ofWebhookTrigger(webhookTrigger)`. */ + fun addNode(webhookTrigger: JourneyWebhookTriggerNode) = + addNode(JourneyNode.ofWebhookTrigger(webhookTrigger)) + /** Alias for calling [addNode] with `JourneyNode.ofSend(send)`. */ fun addNode(send: JourneySendNode) = addNode(JourneyNode.ofSend(send)) diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRun.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRun.kt new file mode 100644 index 00000000..8601fc12 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRun.kt @@ -0,0 +1,395 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * One run of a Journey. `status` and `created_at` are absent on a small number of legacy runs + * stored without them. + */ +class JourneyRun +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val runId: JsonField, + private val source: JsonField>, + private val createdAt: JsonField, + private val status: JsonField, + private val templateId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("run_id") @ExcludeMissing runId: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("template_id") + @ExcludeMissing + templateId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this(runId, source, createdAt, status, templateId, updatedAt, mutableMapOf()) + + /** + * A unique identifier representing the run. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun runId(): String = runId.getRequired("run_id") + + /** + * Internal provenance strings describing what started the run, e.g. `invoke/` or + * `segment/page/Pricing Page`. Diagnostic only — the format is unstable and should not be + * parsed. + * + * @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 source(): List = source.getRequired("source") + + /** + * When the run started, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * The state of the run: `PROCESSING`, `PROCESSED`, `WAITING`, `CANCELED`, `ERROR`, `THROTTLED`, + * or `NOT PROCESSED`. Not an enum — new values have been added before. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun status(): Optional = status.getOptional("status") + + /** + * The id of the Journey this run belongs to. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun templateId(): Optional = templateId.getOptional("template_id") + + /** + * When the run last changed state, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [runId]. + * + * Unlike [runId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("run_id") @ExcludeMissing fun _runId(): JsonField = runId + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField> = source + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [templateId]. + * + * Unlike [templateId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_id") @ExcludeMissing fun _templateId(): JsonField = templateId + + /** + * Returns the raw JSON value of [updatedAt]. + * + * Unlike [updatedAt], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("updated_at") @ExcludeMissing fun _updatedAt(): JsonField = updatedAt + + @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 [JourneyRun]. + * + * The following fields are required: + * ```java + * .runId() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyRun]. */ + class Builder internal constructor() { + + private var runId: JsonField? = null + private var source: JsonField>? = null + private var createdAt: JsonField = JsonMissing.of() + private var status: JsonField = JsonMissing.of() + private var templateId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyRun: JourneyRun) = apply { + runId = journeyRun.runId + source = journeyRun.source.map { it.toMutableList() } + createdAt = journeyRun.createdAt + status = journeyRun.status + templateId = journeyRun.templateId + updatedAt = journeyRun.updatedAt + additionalProperties = journeyRun.additionalProperties.toMutableMap() + } + + /** A unique identifier representing the run. */ + fun runId(runId: String) = runId(JsonField.of(runId)) + + /** + * Sets [Builder.runId] to an arbitrary JSON value. + * + * You should usually call [Builder.runId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun runId(runId: JsonField) = apply { this.runId = runId } + + /** + * Internal provenance strings describing what started the run, e.g. `invoke/` + * or `segment/page/Pricing Page`. Diagnostic only — the format is unstable and should not + * be parsed. + */ + fun source(source: List) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun source(source: JsonField>) = apply { + this.source = source.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.source]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: String) = apply { + this.source = + (this.source ?: JsonField.of(mutableListOf())).also { + checkKnown("source", it).add(source) + } + } + + /** When the run started, as an ISO 8601 timestamp. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** + * The state of the run: `PROCESSING`, `PROCESSED`, `WAITING`, `CANCELED`, `ERROR`, + * `THROTTLED`, or `NOT PROCESSED`. Not an enum — new values have been added before. + */ + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The id of the Journey this run belongs to. */ + fun templateId(templateId: String) = templateId(JsonField.of(templateId)) + + /** + * Sets [Builder.templateId] to an arbitrary JSON value. + * + * You should usually call [Builder.templateId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun templateId(templateId: JsonField) = apply { this.templateId = templateId } + + /** When the run last changed state, as an ISO 8601 timestamp. */ + 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 } + + 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 [JourneyRun]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .runId() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyRun = + JourneyRun( + checkRequired("runId", runId), + checkRequired("source", source).map { it.toImmutable() }, + createdAt, + status, + templateId, + updatedAt, + 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(): JourneyRun = apply { + if (validated) { + return@apply + } + + runId() + source() + createdAt() + status() + templateId() + updatedAt() + 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 (runId.asKnown().isPresent) 1 else 0) + + (source.asKnown().getOrNull()?.size ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (templateId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JourneyRun && + runId == other.runId && + source == other.source && + createdAt == other.createdAt && + status == other.status && + templateId == other.templateId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(runId, source, createdAt, status, templateId, updatedAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyRun{runId=$runId, source=$source, createdAt=$createdAt, status=$status, templateId=$templateId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunListItem.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunListItem.kt new file mode 100644 index 00000000..cd305c25 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunListItem.kt @@ -0,0 +1,347 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A Journey run as it appears in a list response, without `updated_at`. */ +class JourneyRunListItem +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val runId: JsonField, + private val source: JsonField>, + private val createdAt: JsonField, + private val status: JsonField, + private val templateId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("run_id") @ExcludeMissing runId: JsonField = JsonMissing.of(), + @JsonProperty("source") @ExcludeMissing source: JsonField> = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("template_id") + @ExcludeMissing + templateId: JsonField = JsonMissing.of(), + ) : this(runId, source, createdAt, status, templateId, mutableMapOf()) + + /** + * A unique identifier representing the run. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type or is + * unexpectedly missing or null (e.g. if the server responded with an unexpected value). + */ + fun runId(): String = runId.getRequired("run_id") + + /** + * Internal provenance strings describing what started the run. Diagnostic only. + * + * @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 source(): List = source.getRequired("source") + + /** + * When the run started, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * The state of the run. See `JourneyRun.status` for the values it takes. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun status(): Optional = status.getOptional("status") + + /** + * The id of the Journey this run belongs to. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun templateId(): Optional = templateId.getOptional("template_id") + + /** + * Returns the raw JSON value of [runId]. + * + * Unlike [runId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("run_id") @ExcludeMissing fun _runId(): JsonField = runId + + /** + * Returns the raw JSON value of [source]. + * + * Unlike [source], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("source") @ExcludeMissing fun _source(): JsonField> = source + + /** + * 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 [status]. + * + * Unlike [status], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("status") @ExcludeMissing fun _status(): JsonField = status + + /** + * Returns the raw JSON value of [templateId]. + * + * Unlike [templateId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("template_id") @ExcludeMissing fun _templateId(): JsonField = templateId + + @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 [JourneyRunListItem]. + * + * The following fields are required: + * ```java + * .runId() + * .source() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyRunListItem]. */ + class Builder internal constructor() { + + private var runId: JsonField? = null + private var source: JsonField>? = null + private var createdAt: JsonField = JsonMissing.of() + private var status: JsonField = JsonMissing.of() + private var templateId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyRunListItem: JourneyRunListItem) = apply { + runId = journeyRunListItem.runId + source = journeyRunListItem.source.map { it.toMutableList() } + createdAt = journeyRunListItem.createdAt + status = journeyRunListItem.status + templateId = journeyRunListItem.templateId + additionalProperties = journeyRunListItem.additionalProperties.toMutableMap() + } + + /** A unique identifier representing the run. */ + fun runId(runId: String) = runId(JsonField.of(runId)) + + /** + * Sets [Builder.runId] to an arbitrary JSON value. + * + * You should usually call [Builder.runId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun runId(runId: JsonField) = apply { this.runId = runId } + + /** Internal provenance strings describing what started the run. Diagnostic only. */ + fun source(source: List) = source(JsonField.of(source)) + + /** + * Sets [Builder.source] to an arbitrary JSON value. + * + * You should usually call [Builder.source] with a well-typed `List` value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun source(source: JsonField>) = apply { + this.source = source.map { it.toMutableList() } + } + + /** + * Adds a single [String] to [Builder.source]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addSource(source: String) = apply { + this.source = + (this.source ?: JsonField.of(mutableListOf())).also { + checkKnown("source", it).add(source) + } + } + + /** When the run started, as an ISO 8601 timestamp. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** The state of the run. See `JourneyRun.status` for the values it takes. */ + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun status(status: JsonField) = apply { this.status = status } + + /** The id of the Journey this run belongs to. */ + fun templateId(templateId: String) = templateId(JsonField.of(templateId)) + + /** + * Sets [Builder.templateId] to an arbitrary JSON value. + * + * You should usually call [Builder.templateId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun templateId(templateId: JsonField) = apply { this.templateId = templateId } + + 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 [JourneyRunListItem]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .runId() + * .source() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyRunListItem = + JourneyRunListItem( + checkRequired("runId", runId), + checkRequired("source", source).map { it.toImmutable() }, + createdAt, + status, + templateId, + 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(): JourneyRunListItem = apply { + if (validated) { + return@apply + } + + runId() + source() + createdAt() + status() + templateId() + 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 (runId.asKnown().isPresent) 1 else 0) + + (source.asKnown().getOrNull()?.size ?: 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (templateId.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JourneyRunListItem && + runId == other.runId && + source == other.source && + createdAt == other.createdAt && + status == other.status && + templateId == other.templateId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(runId, source, createdAt, status, templateId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyRunListItem{runId=$runId, source=$source, createdAt=$createdAt, status=$status, templateId=$templateId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunListResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunListResponse.kt new file mode 100644 index 00000000..1cb90641 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunListResponse.kt @@ -0,0 +1,275 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** A page of Journey runs. */ +class JourneyRunListResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val runs: JsonField>, + private val nextCursor: JsonField, + private val prevCursor: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("runs") + @ExcludeMissing + runs: JsonField> = JsonMissing.of(), + @JsonProperty("next_cursor") + @ExcludeMissing + nextCursor: JsonField = JsonMissing.of(), + @JsonProperty("prev_cursor") + @ExcludeMissing + prevCursor: JsonField = JsonMissing.of(), + ) : this(runs, nextCursor, prevCursor, 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 runs(): List = runs.getRequired("runs") + + /** + * Pass back as `cursor` to fetch the next page. Absent on the last page. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nextCursor(): Optional = nextCursor.getOptional("next_cursor") + + /** + * Pass back as `cursor` to fetch the previous page. Absent on the first page. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun prevCursor(): Optional = prevCursor.getOptional("prev_cursor") + + /** + * Returns the raw JSON value of [runs]. + * + * Unlike [runs], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("runs") @ExcludeMissing fun _runs(): JsonField> = runs + + /** + * Returns the raw JSON value of [nextCursor]. + * + * Unlike [nextCursor], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("next_cursor") @ExcludeMissing fun _nextCursor(): JsonField = nextCursor + + /** + * Returns the raw JSON value of [prevCursor]. + * + * Unlike [prevCursor], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("prev_cursor") @ExcludeMissing fun _prevCursor(): JsonField = prevCursor + + @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 [JourneyRunListResponse]. + * + * The following fields are required: + * ```java + * .runs() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyRunListResponse]. */ + class Builder internal constructor() { + + private var runs: JsonField>? = null + private var nextCursor: JsonField = JsonMissing.of() + private var prevCursor: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyRunListResponse: JourneyRunListResponse) = apply { + runs = journeyRunListResponse.runs.map { it.toMutableList() } + nextCursor = journeyRunListResponse.nextCursor + prevCursor = journeyRunListResponse.prevCursor + additionalProperties = journeyRunListResponse.additionalProperties.toMutableMap() + } + + fun runs(runs: List) = runs(JsonField.of(runs)) + + /** + * Sets [Builder.runs] to an arbitrary JSON value. + * + * You should usually call [Builder.runs] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun runs(runs: JsonField>) = apply { + this.runs = runs.map { it.toMutableList() } + } + + /** + * Adds a single [JourneyRunListItem] to [runs]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addRun(run: JourneyRunListItem) = apply { + runs = (runs ?: JsonField.of(mutableListOf())).also { checkKnown("runs", it).add(run) } + } + + /** Pass back as `cursor` to fetch the next page. Absent on the last page. */ + fun nextCursor(nextCursor: String) = nextCursor(JsonField.of(nextCursor)) + + /** + * Sets [Builder.nextCursor] to an arbitrary JSON value. + * + * You should usually call [Builder.nextCursor] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun nextCursor(nextCursor: JsonField) = apply { this.nextCursor = nextCursor } + + /** Pass back as `cursor` to fetch the previous page. Absent on the first page. */ + fun prevCursor(prevCursor: String) = prevCursor(JsonField.of(prevCursor)) + + /** + * Sets [Builder.prevCursor] to an arbitrary JSON value. + * + * You should usually call [Builder.prevCursor] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun prevCursor(prevCursor: JsonField) = apply { this.prevCursor = prevCursor } + + 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 [JourneyRunListResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .runs() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyRunListResponse = + JourneyRunListResponse( + checkRequired("runs", runs).map { it.toImmutable() }, + nextCursor, + prevCursor, + 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(): JourneyRunListResponse = apply { + if (validated) { + return@apply + } + + runs().forEach { it.validate() } + nextCursor() + prevCursor() + 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 = + (runs.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + (if (nextCursor.asKnown().isPresent) 1 else 0) + + (if (prevCursor.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JourneyRunListResponse && + runs == other.runs && + nextCursor == other.nextCursor && + prevCursor == other.prevCursor && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(runs, nextCursor, prevCursor, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyRunListResponse{runs=$runs, nextCursor=$nextCursor, prevCursor=$prevCursor, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunResponse.kt new file mode 100644 index 00000000..7d249874 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunResponse.kt @@ -0,0 +1,184 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 + +/** A single Journey run. */ +class JourneyRunResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val run: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("run") @ExcludeMissing run: JsonField = JsonMissing.of() + ) : this(run, mutableMapOf()) + + /** + * One run of a Journey. `status` and `created_at` are absent on a small number of legacy runs + * stored without them. + * + * @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 run(): JourneyRun = run.getRequired("run") + + /** + * Returns the raw JSON value of [run]. + * + * Unlike [run], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("run") @ExcludeMissing fun _run(): JsonField = run + + @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 [JourneyRunResponse]. + * + * The following fields are required: + * ```java + * .run() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyRunResponse]. */ + class Builder internal constructor() { + + private var run: JsonField? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyRunResponse: JourneyRunResponse) = apply { + run = journeyRunResponse.run + additionalProperties = journeyRunResponse.additionalProperties.toMutableMap() + } + + /** + * One run of a Journey. `status` and `created_at` are absent on a small number of legacy + * runs stored without them. + */ + fun run(run: JourneyRun) = run(JsonField.of(run)) + + /** + * Sets [Builder.run] to an arbitrary JSON value. + * + * You should usually call [Builder.run] with a well-typed [JourneyRun] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun run(run: JsonField) = apply { this.run = run } + + 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 [JourneyRunResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .run() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyRunResponse = + JourneyRunResponse(checkRequired("run", run), 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(): JourneyRunResponse = apply { + if (validated) { + return@apply + } + + run().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 = (run.asKnown().getOrNull()?.validity() ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JourneyRunResponse && + run == other.run && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(run, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyRunResponse{run=$run, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunStep.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunStep.kt new file mode 100644 index 00000000..f64e418d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunStep.kt @@ -0,0 +1,375 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 + +/** + * One executed node of a Journey run. `node_id` is the id of the node in the published Journey, so + * a step maps directly onto the Journey graph. + */ +class JourneyRunStep +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val action: JsonField, + private val status: JsonField, + private val createdAt: JsonField, + private val messageId: JsonField, + private val nodeId: JsonField, + private val updatedAt: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("action") @ExcludeMissing action: JsonField = JsonMissing.of(), + @JsonProperty("status") @ExcludeMissing status: JsonField = JsonMissing.of(), + @JsonProperty("created_at") @ExcludeMissing createdAt: JsonField = JsonMissing.of(), + @JsonProperty("message_id") @ExcludeMissing messageId: JsonField = JsonMissing.of(), + @JsonProperty("node_id") @ExcludeMissing nodeId: JsonField = JsonMissing.of(), + @JsonProperty("updated_at") @ExcludeMissing updatedAt: JsonField = JsonMissing.of(), + ) : this(action, status, createdAt, messageId, nodeId, updatedAt, mutableMapOf()) + + /** + * The kind of node that ran, e.g. `send`, `delay`, or `exit`. + * + * @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 action(): String = action.getRequired("action") + + /** + * The state of the step: the seven run statuses, plus `SKIPPED` and `COMPUTING`. Not an enum — + * new values have been added before. + * + * @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(): String = status.getRequired("status") + + /** + * When the step started, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun createdAt(): Optional = createdAt.getOptional("created_at") + + /** + * The message this step produced, present on send steps. Pass it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one id + * for the request, not one per recipient. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun messageId(): Optional = messageId.getOptional("message_id") + + /** + * The id of the node in the published Journey that this step executed. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun nodeId(): Optional = nodeId.getOptional("node_id") + + /** + * When the step last changed state, as an ISO 8601 timestamp. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun updatedAt(): Optional = updatedAt.getOptional("updated_at") + + /** + * Returns the raw JSON value of [action]. + * + * Unlike [action], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("action") @ExcludeMissing fun _action(): JsonField = action + + /** + * 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 [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 [messageId]. + * + * Unlike [messageId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("message_id") @ExcludeMissing fun _messageId(): JsonField = messageId + + /** + * Returns the raw JSON value of [nodeId]. + * + * Unlike [nodeId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("node_id") @ExcludeMissing fun _nodeId(): JsonField = nodeId + + /** + * 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 + + @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 [JourneyRunStep]. + * + * The following fields are required: + * ```java + * .action() + * .status() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyRunStep]. */ + class Builder internal constructor() { + + private var action: JsonField? = null + private var status: JsonField? = null + private var createdAt: JsonField = JsonMissing.of() + private var messageId: JsonField = JsonMissing.of() + private var nodeId: JsonField = JsonMissing.of() + private var updatedAt: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyRunStep: JourneyRunStep) = apply { + action = journeyRunStep.action + status = journeyRunStep.status + createdAt = journeyRunStep.createdAt + messageId = journeyRunStep.messageId + nodeId = journeyRunStep.nodeId + updatedAt = journeyRunStep.updatedAt + additionalProperties = journeyRunStep.additionalProperties.toMutableMap() + } + + /** The kind of node that ran, e.g. `send`, `delay`, or `exit`. */ + fun action(action: String) = action(JsonField.of(action)) + + /** + * Sets [Builder.action] to an arbitrary JSON value. + * + * You should usually call [Builder.action] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun action(action: JsonField) = apply { this.action = action } + + /** + * The state of the step: the seven run statuses, plus `SKIPPED` and `COMPUTING`. Not an + * enum — new values have been added before. + */ + fun status(status: String) = status(JsonField.of(status)) + + /** + * Sets [Builder.status] to an arbitrary JSON value. + * + * You should usually call [Builder.status] with a well-typed [String] 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 } + + /** When the step started, as an ISO 8601 timestamp. */ + fun createdAt(createdAt: String) = createdAt(JsonField.of(createdAt)) + + /** + * Sets [Builder.createdAt] to an arbitrary JSON value. + * + * You should usually call [Builder.createdAt] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun createdAt(createdAt: JsonField) = apply { this.createdAt = createdAt } + + /** + * The message this step produced, present on send steps. Pass it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one + * id for the request, not one per recipient. + */ + fun messageId(messageId: String) = messageId(JsonField.of(messageId)) + + /** + * Sets [Builder.messageId] to an arbitrary JSON value. + * + * You should usually call [Builder.messageId] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun messageId(messageId: JsonField) = apply { this.messageId = messageId } + + /** The id of the node in the published Journey that this step executed. */ + fun nodeId(nodeId: String) = nodeId(JsonField.of(nodeId)) + + /** + * Sets [Builder.nodeId] to an arbitrary JSON value. + * + * You should usually call [Builder.nodeId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun nodeId(nodeId: JsonField) = apply { this.nodeId = nodeId } + + /** When the step last changed state, as an ISO 8601 timestamp. */ + 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 } + + 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 [JourneyRunStep]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .action() + * .status() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyRunStep = + JourneyRunStep( + checkRequired("action", action), + checkRequired("status", status), + createdAt, + messageId, + nodeId, + updatedAt, + 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(): JourneyRunStep = apply { + if (validated) { + return@apply + } + + action() + status() + createdAt() + messageId() + nodeId() + updatedAt() + 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 (action.asKnown().isPresent) 1 else 0) + + (if (status.asKnown().isPresent) 1 else 0) + + (if (createdAt.asKnown().isPresent) 1 else 0) + + (if (messageId.asKnown().isPresent) 1 else 0) + + (if (nodeId.asKnown().isPresent) 1 else 0) + + (if (updatedAt.asKnown().isPresent) 1 else 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JourneyRunStep && + action == other.action && + status == other.status && + createdAt == other.createdAt && + messageId == other.messageId && + nodeId == other.nodeId && + updatedAt == other.updatedAt && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(action, status, createdAt, messageId, nodeId, updatedAt, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyRunStep{action=$action, status=$status, createdAt=$createdAt, messageId=$messageId, nodeId=$nodeId, updatedAt=$updatedAt, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunStepsResponse.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunStepsResponse.kt new file mode 100644 index 00000000..2f1bec44 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyRunStepsResponse.kt @@ -0,0 +1,199 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +import com.courier.core.ExcludeMissing +import com.courier.core.JsonField +import com.courier.core.JsonMissing +import com.courier.core.JsonValue +import com.courier.core.checkKnown +import com.courier.core.checkRequired +import com.courier.core.toImmutable +import com.courier.errors.CourierInvalidDataException +import com.fasterxml.jackson.annotation.JsonAnyGetter +import com.fasterxml.jackson.annotation.JsonAnySetter +import com.fasterxml.jackson.annotation.JsonCreator +import com.fasterxml.jackson.annotation.JsonProperty +import java.util.Collections +import java.util.Objects +import kotlin.jvm.optionals.getOrNull + +/** Every step of a Journey run. Not paginated. */ +class JourneyRunStepsResponse +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val steps: JsonField>, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("steps") + @ExcludeMissing + steps: JsonField> = JsonMissing.of() + ) : this(steps, 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 steps(): List = steps.getRequired("steps") + + /** + * Returns the raw JSON value of [steps]. + * + * Unlike [steps], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("steps") @ExcludeMissing fun _steps(): JsonField> = steps + + @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 [JourneyRunStepsResponse]. + * + * The following fields are required: + * ```java + * .steps() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyRunStepsResponse]. */ + class Builder internal constructor() { + + private var steps: JsonField>? = null + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyRunStepsResponse: JourneyRunStepsResponse) = apply { + steps = journeyRunStepsResponse.steps.map { it.toMutableList() } + additionalProperties = journeyRunStepsResponse.additionalProperties.toMutableMap() + } + + fun steps(steps: List) = steps(JsonField.of(steps)) + + /** + * Sets [Builder.steps] to an arbitrary JSON value. + * + * You should usually call [Builder.steps] with a well-typed `List` value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun steps(steps: JsonField>) = apply { + this.steps = steps.map { it.toMutableList() } + } + + /** + * Adds a single [JourneyRunStep] to [steps]. + * + * @throws IllegalStateException if the field was previously set to a non-list. + */ + fun addStep(step: JourneyRunStep) = apply { + steps = + (steps ?: JsonField.of(mutableListOf())).also { checkKnown("steps", it).add(step) } + } + + 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 [JourneyRunStepsResponse]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .steps() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyRunStepsResponse = + JourneyRunStepsResponse( + checkRequired("steps", steps).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(): JourneyRunStepsResponse = apply { + if (validated) { + return@apply + } + + steps().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 = + (steps.asKnown().getOrNull()?.sumOf { it.validity().toInt() } ?: 0) + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is JourneyRunStepsResponse && + steps == other.steps && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { Objects.hash(steps, additionalProperties) } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyRunStepsResponse{steps=$steps, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneySegmentTriggerNode.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneySegmentTriggerNode.kt index 5d9b2e81..fa6ad87e 100644 --- a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneySegmentTriggerNode.kt +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneySegmentTriggerNode.kt @@ -18,7 +18,11 @@ import java.util.Objects import java.util.Optional import kotlin.jvm.optionals.getOrNull -/** Trigger fired by a segment event (`identify`, `group`, or `track`). */ +/** + * Trigger fired by a segment event (`identify`, `group`, `track`, or `page`). A trigger with no + * `event_id` fires on any event of its type — the only shape `identify` and `group` can take, and + * the one that catches a stock `analytics.page()` call. + */ class JourneySegmentTriggerNode @JsonCreator(mode = JsonCreator.Mode.DISABLED) private constructor( @@ -390,6 +394,8 @@ private constructor( @JvmField val TRACK = of("track") + @JvmField val PAGE = of("page") + @JvmStatic fun of(value: String) = RequestType(JsonField.of(value)) } @@ -398,6 +404,7 @@ private constructor( IDENTIFY, GROUP, TRACK, + PAGE, } /** @@ -413,6 +420,7 @@ private constructor( IDENTIFY, GROUP, TRACK, + PAGE, /** * An enum member indicating that [RequestType] was instantiated with an unknown value. */ @@ -431,6 +439,7 @@ private constructor( IDENTIFY -> Value.IDENTIFY GROUP -> Value.GROUP TRACK -> Value.TRACK + PAGE -> Value.PAGE else -> Value._UNKNOWN } @@ -448,6 +457,7 @@ private constructor( IDENTIFY -> Known.IDENTIFY GROUP -> Known.GROUP TRACK -> Known.TRACK + PAGE -> Known.PAGE else -> throw CourierInvalidDataException("Unknown RequestType: $value") } diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyWebhookTriggerNode.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyWebhookTriggerNode.kt new file mode 100644 index 00000000..e48d2e29 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/JourneyWebhookTriggerNode.kt @@ -0,0 +1,671 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 + +/** + * Trigger fired when an external system POSTs to the webhook URL minted for `event_source`. Narrow + * it to one event with `event_id`, or omit `event_id` to accept every event delivered to the URL. + */ +class JourneyWebhookTriggerNode +@JsonCreator(mode = JsonCreator.Mode.DISABLED) +private constructor( + private val eventSource: JsonField, + private val triggerType: JsonField, + private val type: JsonField, + private val id: JsonField, + private val conditions: JsonField, + private val eventId: JsonField, + private val additionalProperties: MutableMap, +) { + + @JsonCreator + private constructor( + @JsonProperty("event_source") + @ExcludeMissing + eventSource: JsonField = JsonMissing.of(), + @JsonProperty("trigger_type") + @ExcludeMissing + triggerType: JsonField = JsonMissing.of(), + @JsonProperty("type") @ExcludeMissing type: JsonField = JsonMissing.of(), + @JsonProperty("id") @ExcludeMissing id: JsonField = JsonMissing.of(), + @JsonProperty("conditions") + @ExcludeMissing + conditions: JsonField = JsonMissing.of(), + @JsonProperty("event_id") @ExcludeMissing eventId: JsonField = JsonMissing.of(), + ) : this(eventSource, triggerType, type, id, conditions, eventId, mutableMapOf()) + + /** + * The provider key the webhook URL is minted for. Required, and must not contain a forward + * slash. + * + * @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 eventSource(): String = eventSource.getRequired("event_source") + + /** + * @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 triggerType(): TriggerType = triggerType.getRequired("trigger_type") + + /** + * @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 type(): Type = type.getRequired("type") + + /** + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun id(): Optional = id.getOptional("id") + + /** + * Condition spec for a journey node. Accepts a single condition atom, an AND/OR group, or an + * AND/OR nested group. Omit the `conditions` property entirely to express "no conditions". + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun conditions(): Optional = conditions.getOptional("conditions") + + /** + * An optional event filter, matched against the payload's `event` field. A sender that supplies + * no `event` matches the literal `custom`. Must not contain a forward slash. Omit to accept + * every event delivered to the URL. + * + * @throws CourierInvalidDataException if the JSON field has an unexpected type (e.g. if the + * server responded with an unexpected value). + */ + fun eventId(): Optional = eventId.getOptional("event_id") + + /** + * Returns the raw JSON value of [eventSource]. + * + * Unlike [eventSource], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("event_source") + @ExcludeMissing + fun _eventSource(): JsonField = eventSource + + /** + * Returns the raw JSON value of [triggerType]. + * + * Unlike [triggerType], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("trigger_type") + @ExcludeMissing + fun _triggerType(): JsonField = triggerType + + /** + * Returns the raw JSON value of [type]. + * + * Unlike [type], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("type") @ExcludeMissing fun _type(): JsonField = type + + /** + * 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 [conditions]. + * + * Unlike [conditions], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("conditions") + @ExcludeMissing + fun _conditions(): JsonField = conditions + + /** + * Returns the raw JSON value of [eventId]. + * + * Unlike [eventId], this method doesn't throw if the JSON field has an unexpected type. + */ + @JsonProperty("event_id") @ExcludeMissing fun _eventId(): JsonField = eventId + + @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 [JourneyWebhookTriggerNode]. + * + * The following fields are required: + * ```java + * .eventSource() + * .triggerType() + * .type() + * ``` + */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [JourneyWebhookTriggerNode]. */ + class Builder internal constructor() { + + private var eventSource: JsonField? = null + private var triggerType: JsonField? = null + private var type: JsonField? = null + private var id: JsonField = JsonMissing.of() + private var conditions: JsonField = JsonMissing.of() + private var eventId: JsonField = JsonMissing.of() + private var additionalProperties: MutableMap = mutableMapOf() + + @JvmSynthetic + internal fun from(journeyWebhookTriggerNode: JourneyWebhookTriggerNode) = apply { + eventSource = journeyWebhookTriggerNode.eventSource + triggerType = journeyWebhookTriggerNode.triggerType + type = journeyWebhookTriggerNode.type + id = journeyWebhookTriggerNode.id + conditions = journeyWebhookTriggerNode.conditions + eventId = journeyWebhookTriggerNode.eventId + additionalProperties = journeyWebhookTriggerNode.additionalProperties.toMutableMap() + } + + /** + * The provider key the webhook URL is minted for. Required, and must not contain a forward + * slash. + */ + fun eventSource(eventSource: String) = eventSource(JsonField.of(eventSource)) + + /** + * Sets [Builder.eventSource] to an arbitrary JSON value. + * + * You should usually call [Builder.eventSource] with a well-typed [String] value instead. + * This method is primarily for setting the field to an undocumented or not yet supported + * value. + */ + fun eventSource(eventSource: JsonField) = apply { this.eventSource = eventSource } + + fun triggerType(triggerType: TriggerType) = triggerType(JsonField.of(triggerType)) + + /** + * Sets [Builder.triggerType] to an arbitrary JSON value. + * + * You should usually call [Builder.triggerType] with a well-typed [TriggerType] value + * instead. This method is primarily for setting the field to an undocumented or not yet + * supported value. + */ + fun triggerType(triggerType: JsonField) = apply { + this.triggerType = triggerType + } + + fun type(type: Type) = type(JsonField.of(type)) + + /** + * Sets [Builder.type] to an arbitrary JSON value. + * + * You should usually call [Builder.type] with a well-typed [Type] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun type(type: JsonField) = apply { this.type = type } + + 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 } + + /** + * Condition spec for a journey node. Accepts a single condition atom, an AND/OR group, or + * an AND/OR nested group. Omit the `conditions` property entirely to express "no + * conditions". + */ + fun conditions(conditions: JourneyConditionsField) = conditions(JsonField.of(conditions)) + + /** + * Sets [Builder.conditions] to an arbitrary JSON value. + * + * You should usually call [Builder.conditions] with a well-typed [JourneyConditionsField] + * value instead. This method is primarily for setting the field to an undocumented or not + * yet supported value. + */ + fun conditions(conditions: JsonField) = apply { + this.conditions = conditions + } + + /** + * Alias for calling [conditions] with + * `JourneyConditionsField.ofConditionAtom(conditionAtom)`. + */ + fun conditionsOfConditionAtom(conditionAtom: List) = + conditions(JourneyConditionsField.ofConditionAtom(conditionAtom)) + + /** + * Alias for calling [conditions] with + * `JourneyConditionsField.ofConditionGroup(conditionGroup)`. + */ + fun conditions(conditionGroup: JourneyConditionGroup) = + conditions(JourneyConditionsField.ofConditionGroup(conditionGroup)) + + /** + * Alias for calling [conditions] with + * `JourneyConditionsField.ofConditionNestedGroup(conditionNestedGroup)`. + */ + fun conditions(conditionNestedGroup: JourneyConditionNestedGroup) = + conditions(JourneyConditionsField.ofConditionNestedGroup(conditionNestedGroup)) + + /** + * An optional event filter, matched against the payload's `event` field. A sender that + * supplies no `event` matches the literal `custom`. Must not contain a forward slash. Omit + * to accept every event delivered to the URL. + */ + fun eventId(eventId: String) = eventId(JsonField.of(eventId)) + + /** + * Sets [Builder.eventId] to an arbitrary JSON value. + * + * You should usually call [Builder.eventId] with a well-typed [String] value instead. This + * method is primarily for setting the field to an undocumented or not yet supported value. + */ + fun eventId(eventId: JsonField) = apply { this.eventId = eventId } + + 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 [JourneyWebhookTriggerNode]. + * + * Further updates to this [Builder] will not mutate the returned instance. + * + * The following fields are required: + * ```java + * .eventSource() + * .triggerType() + * .type() + * ``` + * + * @throws IllegalStateException if any required field is unset. + */ + fun build(): JourneyWebhookTriggerNode = + JourneyWebhookTriggerNode( + checkRequired("eventSource", eventSource), + checkRequired("triggerType", triggerType), + checkRequired("type", type), + id, + conditions, + eventId, + 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(): JourneyWebhookTriggerNode = apply { + if (validated) { + return@apply + } + + eventSource() + triggerType().validate() + type().validate() + id() + conditions().ifPresent { it.validate() } + eventId() + 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 (eventSource.asKnown().isPresent) 1 else 0) + + (triggerType.asKnown().getOrNull()?.validity() ?: 0) + + (type.asKnown().getOrNull()?.validity() ?: 0) + + (if (id.asKnown().isPresent) 1 else 0) + + (conditions.asKnown().getOrNull()?.validity() ?: 0) + + (if (eventId.asKnown().isPresent) 1 else 0) + + class TriggerType @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 WEBHOOK = of("webhook") + + @JvmStatic fun of(value: String) = TriggerType(JsonField.of(value)) + } + + /** An enum containing [TriggerType]'s known values. */ + enum class Known { + WEBHOOK + } + + /** + * An enum containing [TriggerType]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [TriggerType] 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 { + WEBHOOK, + /** + * An enum member indicating that [TriggerType] 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) { + WEBHOOK -> Value.WEBHOOK + 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) { + WEBHOOK -> Known.WEBHOOK + else -> throw CourierInvalidDataException("Unknown TriggerType: $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(): TriggerType = 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 TriggerType && value == other.value + } + + override fun hashCode() = value.hashCode() + + override fun toString() = value.toString() + } + + class Type @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 TRIGGER = of("trigger") + + @JvmStatic fun of(value: String) = Type(JsonField.of(value)) + } + + /** An enum containing [Type]'s known values. */ + enum class Known { + TRIGGER + } + + /** + * An enum containing [Type]'s known values, as well as an [_UNKNOWN] member. + * + * An instance of [Type] 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 { + TRIGGER, + /** An enum member indicating that [Type] 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) { + TRIGGER -> Value.TRIGGER + 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) { + TRIGGER -> Known.TRIGGER + else -> throw CourierInvalidDataException("Unknown Type: $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(): Type = 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 Type && 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 JourneyWebhookTriggerNode && + eventSource == other.eventSource && + triggerType == other.triggerType && + type == other.type && + id == other.id && + conditions == other.conditions && + eventId == other.eventId && + additionalProperties == other.additionalProperties + } + + private val hashCode: Int by lazy { + Objects.hash(eventSource, triggerType, type, id, conditions, eventId, additionalProperties) + } + + override fun hashCode(): Int = hashCode + + override fun toString() = + "JourneyWebhookTriggerNode{eventSource=$eventSource, triggerType=$triggerType, type=$type, id=$id, conditions=$conditions, eventId=$eventId, additionalProperties=$additionalProperties}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunListParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunListParams.kt new file mode 100644 index 00000000..edb728d0 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunListParams.kt @@ -0,0 +1,302 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys.runs + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * List runs of the workspace's Journeys, newest first, filtered by status, Journey, or date range + * and paged by cursor. Runs of v2 Automations are listed by `GET /automations/runs` instead — the + * two surfaces never return each other's runs. Runs are retained for 95 days. + */ +class RunListParams +private constructor( + private val cursor: String?, + private val endDate: String?, + private val limit: String?, + private val startDate: String?, + private val status: String?, + private val templateId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + /** + * A cursor token for pagination. Use the `next_cursor` from the previous response to fetch the + * next page of results. Treat it as opaque. + */ + fun cursor(): Optional = Optional.ofNullable(cursor) + + /** An inclusive upper bound on `created_at`, in the same format as `start_date`. */ + fun endDate(): Optional = Optional.ofNullable(endDate) + + /** + * The number of runs to return per page, between `1` and `50`. Defaults to `20`. Values outside + * the range are clamped, and a non-numeric value falls back to `20`. + */ + fun limit(): Optional = Optional.ofNullable(limit) + + /** + * An inclusive lower bound on `created_at`, as an ISO 8601 date or timestamp (e.g. `2026-08-18` + * or `2026-08-18T20:06:36.259Z`). Any other format returns `400`. + */ + fun startDate(): Optional = Optional.ofNullable(startDate) + + /** A comma-separated list of run statuses to filter on, e.g. `PROCESSED,ERROR`. */ + fun status(): Optional = Optional.ofNullable(status) + + /** A comma-separated list of Journey ids to filter on. */ + fun templateId(): Optional = Optional.ofNullable(templateId) + + /** Additional headers to send with the request. */ + fun _additionalHeaders(): Headers = additionalHeaders + + /** Additional query param to send with the request. */ + fun _additionalQueryParams(): QueryParams = additionalQueryParams + + fun toBuilder() = Builder().from(this) + + companion object { + + @JvmStatic fun none(): RunListParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RunListParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListParams]. */ + class Builder internal constructor() { + + private var cursor: String? = null + private var endDate: String? = null + private var limit: String? = null + private var startDate: String? = null + private var status: String? = null + private var templateId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runListParams: RunListParams) = apply { + cursor = runListParams.cursor + endDate = runListParams.endDate + limit = runListParams.limit + startDate = runListParams.startDate + status = runListParams.status + templateId = runListParams.templateId + additionalHeaders = runListParams.additionalHeaders.toBuilder() + additionalQueryParams = runListParams.additionalQueryParams.toBuilder() + } + + /** + * A cursor token for pagination. Use the `next_cursor` from the previous response to fetch + * the next page of results. Treat it as opaque. + */ + fun cursor(cursor: String?) = apply { this.cursor = cursor } + + /** Alias for calling [Builder.cursor] with `cursor.orElse(null)`. */ + fun cursor(cursor: Optional) = cursor(cursor.getOrNull()) + + /** An inclusive upper bound on `created_at`, in the same format as `start_date`. */ + fun endDate(endDate: String?) = apply { this.endDate = endDate } + + /** Alias for calling [Builder.endDate] with `endDate.orElse(null)`. */ + fun endDate(endDate: Optional) = endDate(endDate.getOrNull()) + + /** + * The number of runs to return per page, between `1` and `50`. Defaults to `20`. Values + * outside the range are clamped, and a non-numeric value falls back to `20`. + */ + fun limit(limit: String?) = apply { this.limit = limit } + + /** Alias for calling [Builder.limit] with `limit.orElse(null)`. */ + fun limit(limit: Optional) = limit(limit.getOrNull()) + + /** + * An inclusive lower bound on `created_at`, as an ISO 8601 date or timestamp (e.g. + * `2026-08-18` or `2026-08-18T20:06:36.259Z`). Any other format returns `400`. + */ + fun startDate(startDate: String?) = apply { this.startDate = startDate } + + /** Alias for calling [Builder.startDate] with `startDate.orElse(null)`. */ + fun startDate(startDate: Optional) = startDate(startDate.getOrNull()) + + /** A comma-separated list of run statuses to filter on, e.g. `PROCESSED,ERROR`. */ + fun status(status: String?) = apply { this.status = status } + + /** Alias for calling [Builder.status] with `status.orElse(null)`. */ + fun status(status: Optional) = status(status.getOrNull()) + + /** A comma-separated list of Journey ids to filter on. */ + fun templateId(templateId: String?) = apply { this.templateId = templateId } + + /** Alias for calling [Builder.templateId] with `templateId.orElse(null)`. */ + fun templateId(templateId: Optional) = templateId(templateId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RunListParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RunListParams = + RunListParams( + cursor, + endDate, + limit, + startDate, + status, + templateId, + additionalHeaders.build(), + additionalQueryParams.build(), + ) + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = + QueryParams.builder() + .apply { + cursor?.let { put("cursor", it) } + endDate?.let { put("end_date", it) } + limit?.let { put("limit", it) } + startDate?.let { put("start_date", it) } + status?.let { put("status", it) } + templateId?.let { put("template_id", it) } + putAll(additionalQueryParams) + } + .build() + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RunListParams && + cursor == other.cursor && + endDate == other.endDate && + limit == other.limit && + startDate == other.startDate && + status == other.status && + templateId == other.templateId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = + Objects.hash( + cursor, + endDate, + limit, + startDate, + status, + templateId, + additionalHeaders, + additionalQueryParams, + ) + + override fun toString() = + "RunListParams{cursor=$cursor, endDate=$endDate, limit=$limit, startDate=$startDate, status=$status, templateId=$templateId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunListStepsParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunListStepsParams.kt new file mode 100644 index 00000000..f5badce2 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunListStepsParams.kt @@ -0,0 +1,194 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys.runs + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * List the per-node state of one Journey run, in full — this endpoint is not paginated. Each step's + * `node_id` is the id of the node in the published Journey, so a step maps directly onto the + * Journey graph. `message_id` is present on send steps that produced a message; follow it to `GET + * /messages/{message_id}` for delivery status. + */ +class RunListStepsParams +private constructor( + private val runId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun runId(): Optional = Optional.ofNullable(runId) + + /** 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(): RunListStepsParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RunListStepsParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunListStepsParams]. */ + class Builder internal constructor() { + + private var runId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runListStepsParams: RunListStepsParams) = apply { + runId = runListStepsParams.runId + additionalHeaders = runListStepsParams.additionalHeaders.toBuilder() + additionalQueryParams = runListStepsParams.additionalQueryParams.toBuilder() + } + + fun runId(runId: String?) = apply { this.runId = runId } + + /** Alias for calling [Builder.runId] with `runId.orElse(null)`. */ + fun runId(runId: Optional) = runId(runId.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 [RunListStepsParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RunListStepsParams = + RunListStepsParams(runId, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> runId ?: "" + 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 RunListStepsParams && + runId == other.runId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(runId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RunListStepsParams{runId=$runId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunRetrieveParams.kt b/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunRetrieveParams.kt new file mode 100644 index 00000000..75f0a630 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/models/journeys/runs/RunRetrieveParams.kt @@ -0,0 +1,193 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys.runs + +import com.courier.core.Params +import com.courier.core.http.Headers +import com.courier.core.http.QueryParams +import java.util.Objects +import java.util.Optional +import kotlin.jvm.optionals.getOrNull + +/** + * Fetch one Journey run by id. Returns `404` for an unknown run, a run belonging to another + * workspace, a run past the 95-day retention window, or an Automation run id — the same body in + * every case, so the response never reveals whether a run exists elsewhere. + */ +class RunRetrieveParams +private constructor( + private val runId: String?, + private val additionalHeaders: Headers, + private val additionalQueryParams: QueryParams, +) : Params { + + fun runId(): Optional = Optional.ofNullable(runId) + + /** 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(): RunRetrieveParams = builder().build() + + /** Returns a mutable builder for constructing an instance of [RunRetrieveParams]. */ + @JvmStatic fun builder() = Builder() + } + + /** A builder for [RunRetrieveParams]. */ + class Builder internal constructor() { + + private var runId: String? = null + private var additionalHeaders: Headers.Builder = Headers.builder() + private var additionalQueryParams: QueryParams.Builder = QueryParams.builder() + + @JvmSynthetic + internal fun from(runRetrieveParams: RunRetrieveParams) = apply { + runId = runRetrieveParams.runId + additionalHeaders = runRetrieveParams.additionalHeaders.toBuilder() + additionalQueryParams = runRetrieveParams.additionalQueryParams.toBuilder() + } + + fun runId(runId: String?) = apply { this.runId = runId } + + /** Alias for calling [Builder.runId] with `runId.orElse(null)`. */ + fun runId(runId: Optional) = runId(runId.getOrNull()) + + fun additionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun additionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.clear() + putAllAdditionalHeaders(additionalHeaders) + } + + fun putAdditionalHeader(name: String, value: String) = apply { + additionalHeaders.put(name, value) + } + + fun putAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.put(name, values) + } + + fun putAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun putAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.putAll(additionalHeaders) + } + + fun replaceAdditionalHeaders(name: String, value: String) = apply { + additionalHeaders.replace(name, value) + } + + fun replaceAdditionalHeaders(name: String, values: Iterable) = apply { + additionalHeaders.replace(name, values) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Headers) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun replaceAllAdditionalHeaders(additionalHeaders: Map>) = apply { + this.additionalHeaders.replaceAll(additionalHeaders) + } + + fun removeAdditionalHeaders(name: String) = apply { additionalHeaders.remove(name) } + + fun removeAllAdditionalHeaders(names: Set) = apply { + additionalHeaders.removeAll(names) + } + + fun additionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun additionalQueryParams(additionalQueryParams: Map>) = apply { + this.additionalQueryParams.clear() + putAllAdditionalQueryParams(additionalQueryParams) + } + + fun putAdditionalQueryParam(key: String, value: String) = apply { + additionalQueryParams.put(key, value) + } + + fun putAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.put(key, values) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun putAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.putAll(additionalQueryParams) + } + + fun replaceAdditionalQueryParams(key: String, value: String) = apply { + additionalQueryParams.replace(key, value) + } + + fun replaceAdditionalQueryParams(key: String, values: Iterable) = apply { + additionalQueryParams.replace(key, values) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: QueryParams) = apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun replaceAllAdditionalQueryParams(additionalQueryParams: Map>) = + apply { + this.additionalQueryParams.replaceAll(additionalQueryParams) + } + + fun removeAdditionalQueryParams(key: String) = apply { additionalQueryParams.remove(key) } + + fun removeAllAdditionalQueryParams(keys: Set) = apply { + additionalQueryParams.removeAll(keys) + } + + /** + * Returns an immutable instance of [RunRetrieveParams]. + * + * Further updates to this [Builder] will not mutate the returned instance. + */ + fun build(): RunRetrieveParams = + RunRetrieveParams(runId, additionalHeaders.build(), additionalQueryParams.build()) + } + + fun _pathParam(index: Int): String = + when (index) { + 0 -> runId ?: "" + else -> "" + } + + override fun _headers(): Headers = additionalHeaders + + override fun _queryParams(): QueryParams = additionalQueryParams + + override fun equals(other: Any?): Boolean { + if (this === other) { + return true + } + + return other is RunRetrieveParams && + runId == other.runId && + additionalHeaders == other.additionalHeaders && + additionalQueryParams == other.additionalQueryParams + } + + override fun hashCode(): Int = Objects.hash(runId, additionalHeaders, additionalQueryParams) + + override fun toString() = + "RunRetrieveParams{runId=$runId, additionalHeaders=$additionalHeaders, additionalQueryParams=$additionalQueryParams}" +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsync.kt index 815b235b..9983c0db 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsync.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsync.kt @@ -8,6 +8,7 @@ import com.courier.core.http.HttpResponseFor import com.courier.models.automations.AutomationListParams import com.courier.models.automations.AutomationTemplateListResponse import com.courier.services.async.automations.InvokeServiceAsync +import com.courier.services.async.automations.RunServiceAsync import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -29,6 +30,9 @@ interface AutomationServiceAsync { /** Invoke a stored automation template or an ad hoc automation defined in the request. */ fun invoke(): InvokeServiceAsync + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + fun runs(): RunServiceAsync + /** * Lists the workspace's saved automation templates, each with its id and a cursor for paging to * the next page of results. @@ -69,6 +73,9 @@ interface AutomationServiceAsync { /** Invoke a stored automation template or an ad hoc automation defined in the request. */ fun invoke(): InvokeServiceAsync.WithRawResponse + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + fun runs(): RunServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `get /automations`, but is otherwise the same as * [AutomationServiceAsync.list]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsyncImpl.kt index fe176621..942a1a95 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsyncImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/AutomationServiceAsyncImpl.kt @@ -18,6 +18,8 @@ import com.courier.models.automations.AutomationListParams import com.courier.models.automations.AutomationTemplateListResponse import com.courier.services.async.automations.InvokeServiceAsync import com.courier.services.async.automations.InvokeServiceAsyncImpl +import com.courier.services.async.automations.RunServiceAsync +import com.courier.services.async.automations.RunServiceAsyncImpl import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -31,6 +33,8 @@ class AutomationServiceAsyncImpl internal constructor(private val clientOptions: private val invoke: InvokeServiceAsync by lazy { InvokeServiceAsyncImpl(clientOptions) } + private val runs: RunServiceAsync by lazy { RunServiceAsyncImpl(clientOptions) } + override fun withRawResponse(): AutomationServiceAsync.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): AutomationServiceAsync = @@ -39,6 +43,9 @@ class AutomationServiceAsyncImpl internal constructor(private val clientOptions: /** Invoke a stored automation template or an ad hoc automation defined in the request. */ override fun invoke(): InvokeServiceAsync = invoke + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + override fun runs(): RunServiceAsync = runs + override fun list( params: AutomationListParams, requestOptions: RequestOptions, @@ -56,6 +63,10 @@ class AutomationServiceAsyncImpl internal constructor(private val clientOptions: InvokeServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val runs: RunServiceAsync.WithRawResponse by lazy { + RunServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): AutomationServiceAsync.WithRawResponse = @@ -66,6 +77,9 @@ class AutomationServiceAsyncImpl internal constructor(private val clientOptions: /** Invoke a stored automation template or an ad hoc automation defined in the request. */ override fun invoke(): InvokeServiceAsync.WithRawResponse = invoke + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + override fun runs(): RunServiceAsync.WithRawResponse = runs + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsync.kt index a4710fac..bc4b5453 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsync.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsync.kt @@ -22,6 +22,7 @@ import com.courier.models.journeys.JourneyRetrieveParams import com.courier.models.journeys.JourneyVersionsListResponse import com.courier.models.journeys.JourneysInvokeResponse import com.courier.models.journeys.JourneysListResponse +import com.courier.services.async.journeys.RunServiceAsync import com.courier.services.async.journeys.TemplateServiceAsync import java.util.concurrent.CompletableFuture import java.util.function.Consumer @@ -50,6 +51,12 @@ interface JourneyServiceAsync { */ fun templates(): TemplateServiceAsync + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ + fun runs(): RunServiceAsync + /** * Creates a journey from a set of nodes, in draft state unless you pass a published state. Send * nodes cannot be included until their templates exist. @@ -375,6 +382,12 @@ interface JourneyServiceAsync { */ fun templates(): TemplateServiceAsync.WithRawResponse + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with + * the templates scoped to them. + */ + fun runs(): RunServiceAsync.WithRawResponse + /** * Returns a raw HTTP response for `post /journeys`, but is otherwise the same as * [JourneyServiceAsync.create]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsyncImpl.kt index 2df9bdf8..c8940ca3 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsyncImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/JourneyServiceAsyncImpl.kt @@ -31,6 +31,8 @@ import com.courier.models.journeys.JourneyRetrieveParams import com.courier.models.journeys.JourneyVersionsListResponse import com.courier.models.journeys.JourneysInvokeResponse import com.courier.models.journeys.JourneysListResponse +import com.courier.services.async.journeys.RunServiceAsync +import com.courier.services.async.journeys.RunServiceAsyncImpl import com.courier.services.async.journeys.TemplateServiceAsync import com.courier.services.async.journeys.TemplateServiceAsyncImpl import java.util.concurrent.CompletableFuture @@ -50,6 +52,8 @@ class JourneyServiceAsyncImpl internal constructor(private val clientOptions: Cl private val templates: TemplateServiceAsync by lazy { TemplateServiceAsyncImpl(clientOptions) } + private val runs: RunServiceAsync by lazy { RunServiceAsyncImpl(clientOptions) } + override fun withRawResponse(): JourneyServiceAsync.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): JourneyServiceAsync = @@ -61,6 +65,12 @@ class JourneyServiceAsyncImpl internal constructor(private val clientOptions: Cl */ override fun templates(): TemplateServiceAsync = templates + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ + override fun runs(): RunServiceAsync = runs + override fun create( params: JourneyCreateParams, requestOptions: RequestOptions, @@ -134,6 +144,10 @@ class JourneyServiceAsyncImpl internal constructor(private val clientOptions: Cl TemplateServiceAsyncImpl.WithRawResponseImpl(clientOptions) } + private val runs: RunServiceAsync.WithRawResponse by lazy { + RunServiceAsyncImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): JourneyServiceAsync.WithRawResponse = @@ -147,6 +161,12 @@ class JourneyServiceAsyncImpl internal constructor(private val clientOptions: Cl */ override fun templates(): TemplateServiceAsync.WithRawResponse = templates + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with + * the templates scoped to them. + */ + override fun runs(): RunServiceAsync.WithRawResponse = runs + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/automations/RunServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/automations/RunServiceAsync.kt new file mode 100644 index 00000000..9f6a9bae --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/automations/RunServiceAsync.kt @@ -0,0 +1,168 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.automations + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.automations.AutomationRunListResponse +import com.courier.models.automations.AutomationRunStepsResponse +import com.courier.models.automations.runs.RunListParams +import com.courier.models.automations.runs.RunListStepsParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +/** Invoke a stored automation template or an ad hoc automation defined in the request. */ +interface RunServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunServiceAsync + + /** + * List runs of the workspace's v2 Automations, newest first, filtered by status, Template, or + * date range and paged by cursor. Journey (v3) runs are listed by `GET /journeys/runs` instead + * — the two surfaces never return each other's runs. Runs are retained for 95 days. + */ + fun list(): CompletableFuture = list(RunListParams.none()) + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(RunListParams.none(), requestOptions) + + /** + * List the per-step state of one Automation run, in full — this endpoint is not paginated. + * `message_id` is present on send steps that produced a message; follow it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one + * `message_id` for the request, not one per recipient. + */ + fun listSteps(id: String): CompletableFuture = + listSteps(id, RunListStepsParams.none()) + + /** @see listSteps */ + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + listSteps(params.toBuilder().id(id).build(), requestOptions) + + /** @see listSteps */ + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): CompletableFuture = listSteps(id, params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see listSteps */ + fun listSteps(params: RunListStepsParams): CompletableFuture = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture = + listSteps(id, RunListStepsParams.none(), requestOptions) + + /** A view of [RunServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /automations/runs`, but is otherwise the same as + * [RunServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(RunListParams.none()) + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(RunListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /automations/runs/{id}/steps`, but is otherwise the + * same as [RunServiceAsync.listSteps]. + */ + fun listSteps(id: String): CompletableFuture> = + listSteps(id, RunListStepsParams.none()) + + /** @see listSteps */ + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + listSteps(params.toBuilder().id(id).build(), requestOptions) + + /** @see listSteps */ + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): CompletableFuture> = + listSteps(id, params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams + ): CompletableFuture> = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + id: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + listSteps(id, RunListStepsParams.none(), requestOptions) + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/automations/RunServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/automations/RunServiceAsyncImpl.kt new file mode 100644 index 00000000..5366f163 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/automations/RunServiceAsyncImpl.kt @@ -0,0 +1,129 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.automations + +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.parseable +import com.courier.core.prepareAsync +import com.courier.models.automations.AutomationRunListResponse +import com.courier.models.automations.AutomationRunStepsResponse +import com.courier.models.automations.runs.RunListParams +import com.courier.models.automations.runs.RunListStepsParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** Invoke a stored automation template or an ad hoc automation defined in the request. */ +class RunServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + RunServiceAsync { + + private val withRawResponse: RunServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RunServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RunServiceAsync = + RunServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /automations/runs + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /automations/runs/{id}/steps + withRawResponse().listSteps(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RunServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RunServiceAsync.WithRawResponse = + RunServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("automations", "runs") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listStepsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("automations", "runs", params._pathParam(0), "steps") + .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 { listStepsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/journeys/RunServiceAsync.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/journeys/RunServiceAsync.kt new file mode 100644 index 00000000..0ed11570 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/journeys/RunServiceAsync.kt @@ -0,0 +1,253 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.journeys + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.journeys.JourneyRunListResponse +import com.courier.models.journeys.JourneyRunResponse +import com.courier.models.journeys.JourneyRunStepsResponse +import com.courier.models.journeys.runs.RunListParams +import com.courier.models.journeys.runs.RunListStepsParams +import com.courier.models.journeys.runs.RunRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer + +/** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ +interface RunServiceAsync { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunServiceAsync + + /** + * Fetch one Journey run by id. Returns `404` for an unknown run, a run belonging to another + * workspace, a run past the 95-day retention window, or an Automation run id — the same body in + * every case, so the response never reveals whether a run exists elsewhere. + */ + fun retrieve(runId: String): CompletableFuture = + retrieve(runId, RunRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + retrieve(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + ): CompletableFuture = retrieve(runId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see retrieve */ + fun retrieve(params: RunRetrieveParams): CompletableFuture = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + runId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + retrieve(runId, RunRetrieveParams.none(), requestOptions) + + /** + * List runs of the workspace's Journeys, newest first, filtered by status, Journey, or date + * range and paged by cursor. Runs of v2 Automations are listed by `GET /automations/runs` + * instead — the two surfaces never return each other's runs. Runs are retained for 95 days. + */ + fun list(): CompletableFuture = list(RunListParams.none()) + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none() + ): CompletableFuture = list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): CompletableFuture = + list(RunListParams.none(), requestOptions) + + /** + * List the per-node state of one Journey run, in full — this endpoint is not paginated. Each + * step's `node_id` is the id of the node in the published Journey, so a step maps directly onto + * the Journey graph. `message_id` is present on send steps that produced a message; follow it + * to `GET /messages/{message_id}` for delivery status. + */ + fun listSteps(runId: String): CompletableFuture = + listSteps(runId, RunListStepsParams.none()) + + /** @see listSteps */ + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture = + listSteps(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see listSteps */ + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): CompletableFuture = listSteps(runId, params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture + + /** @see listSteps */ + fun listSteps(params: RunListStepsParams): CompletableFuture = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + runId: String, + requestOptions: RequestOptions, + ): CompletableFuture = + listSteps(runId, RunListStepsParams.none(), requestOptions) + + /** A view of [RunServiceAsync] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunServiceAsync.WithRawResponse + + /** + * Returns a raw HTTP response for `get /journeys/runs/{run_id}`, but is otherwise the same + * as [RunServiceAsync.retrieve]. + */ + fun retrieve(runId: String): CompletableFuture> = + retrieve(runId, RunRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + retrieve(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + ): CompletableFuture> = + retrieve(runId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams + ): CompletableFuture> = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + runId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + retrieve(runId, RunRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /journeys/runs`, but is otherwise the same as + * [RunServiceAsync.list]. + */ + fun list(): CompletableFuture> = + list(RunListParams.none()) + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none() + ): CompletableFuture> = + list(params, RequestOptions.none()) + + /** @see list */ + fun list( + requestOptions: RequestOptions + ): CompletableFuture> = + list(RunListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /journeys/runs/{run_id}/steps`, but is otherwise the + * same as [RunServiceAsync.listSteps]. + */ + fun listSteps(runId: String): CompletableFuture> = + listSteps(runId, RunListStepsParams.none()) + + /** @see listSteps */ + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> = + listSteps(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see listSteps */ + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): CompletableFuture> = + listSteps(runId, params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): CompletableFuture> + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams + ): CompletableFuture> = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + runId: String, + requestOptions: RequestOptions, + ): CompletableFuture> = + listSteps(runId, RunListStepsParams.none(), requestOptions) + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/async/journeys/RunServiceAsyncImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/async/journeys/RunServiceAsyncImpl.kt new file mode 100644 index 00000000..88bb1d2d --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/async/journeys/RunServiceAsyncImpl.kt @@ -0,0 +1,174 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.journeys + +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.parseable +import com.courier.core.prepareAsync +import com.courier.models.journeys.JourneyRunListResponse +import com.courier.models.journeys.JourneyRunResponse +import com.courier.models.journeys.JourneyRunStepsResponse +import com.courier.models.journeys.runs.RunListParams +import com.courier.models.journeys.runs.RunListStepsParams +import com.courier.models.journeys.runs.RunRetrieveParams +import java.util.concurrent.CompletableFuture +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ +class RunServiceAsyncImpl internal constructor(private val clientOptions: ClientOptions) : + RunServiceAsync { + + private val withRawResponse: RunServiceAsync.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RunServiceAsync.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RunServiceAsync = + RunServiceAsyncImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /journeys/runs/{run_id} + withRawResponse().retrieve(params, requestOptions).thenApply { it.parse() } + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /journeys/runs + withRawResponse().list(params, requestOptions).thenApply { it.parse() } + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): CompletableFuture = + // get /journeys/runs/{run_id}/steps + withRawResponse().listSteps(params, requestOptions).thenApply { it.parse() } + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RunServiceAsync.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RunServiceAsync.WithRawResponse = + RunServiceAsyncImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("runId", params.runId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("journeys", "runs", 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 listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("journeys", "runs") + .build() + .prepareAsync(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + return request + .thenComposeAsync { clientOptions.httpClient.executeAsync(it, requestOptions) } + .thenApply { response -> + errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + + private val listStepsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): CompletableFuture> { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("runId", params.runId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("journeys", "runs", params._pathParam(0), "steps") + .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 { listStepsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationService.kt index 926c96ea..6f322b6b 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationService.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationService.kt @@ -8,6 +8,7 @@ import com.courier.core.http.HttpResponseFor import com.courier.models.automations.AutomationListParams import com.courier.models.automations.AutomationTemplateListResponse import com.courier.services.blocking.automations.InvokeService +import com.courier.services.blocking.automations.RunService import com.google.errorprone.annotations.MustBeClosed import java.util.function.Consumer @@ -29,6 +30,9 @@ interface AutomationService { /** Invoke a stored automation template or an ad hoc automation defined in the request. */ fun invoke(): InvokeService + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + fun runs(): RunService + /** * Lists the workspace's saved automation templates, each with its id and a cursor for paging to * the next page of results. @@ -65,6 +69,9 @@ interface AutomationService { /** Invoke a stored automation template or an ad hoc automation defined in the request. */ fun invoke(): InvokeService.WithRawResponse + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + fun runs(): RunService.WithRawResponse + /** * Returns a raw HTTP response for `get /automations`, but is otherwise the same as * [AutomationService.list]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationServiceImpl.kt index 700ccec7..dd597820 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationServiceImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/AutomationServiceImpl.kt @@ -18,6 +18,8 @@ import com.courier.models.automations.AutomationListParams import com.courier.models.automations.AutomationTemplateListResponse import com.courier.services.blocking.automations.InvokeService import com.courier.services.blocking.automations.InvokeServiceImpl +import com.courier.services.blocking.automations.RunService +import com.courier.services.blocking.automations.RunServiceImpl import java.util.function.Consumer /** Invoke a stored automation template or an ad hoc automation defined in the request. */ @@ -30,6 +32,8 @@ class AutomationServiceImpl internal constructor(private val clientOptions: Clie private val invoke: InvokeService by lazy { InvokeServiceImpl(clientOptions) } + private val runs: RunService by lazy { RunServiceImpl(clientOptions) } + override fun withRawResponse(): AutomationService.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): AutomationService = @@ -38,6 +42,9 @@ class AutomationServiceImpl internal constructor(private val clientOptions: Clie /** Invoke a stored automation template or an ad hoc automation defined in the request. */ override fun invoke(): InvokeService = invoke + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + override fun runs(): RunService = runs + override fun list( params: AutomationListParams, requestOptions: RequestOptions, @@ -55,6 +62,10 @@ class AutomationServiceImpl internal constructor(private val clientOptions: Clie InvokeServiceImpl.WithRawResponseImpl(clientOptions) } + private val runs: RunService.WithRawResponse by lazy { + RunServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): AutomationService.WithRawResponse = @@ -65,6 +76,9 @@ class AutomationServiceImpl internal constructor(private val clientOptions: Clie /** Invoke a stored automation template or an ad hoc automation defined in the request. */ override fun invoke(): InvokeService.WithRawResponse = invoke + /** Invoke a stored automation template or an ad hoc automation defined in the request. */ + override fun runs(): RunService.WithRawResponse = runs + private val listHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyService.kt index 42527ac7..47c9b5e1 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyService.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyService.kt @@ -22,6 +22,7 @@ import com.courier.models.journeys.JourneyRetrieveParams import com.courier.models.journeys.JourneyVersionsListResponse import com.courier.models.journeys.JourneysInvokeResponse import com.courier.models.journeys.JourneysListResponse +import com.courier.services.blocking.journeys.RunService import com.courier.services.blocking.journeys.TemplateService import com.google.errorprone.annotations.MustBeClosed import java.util.function.Consumer @@ -50,6 +51,12 @@ interface JourneyService { */ fun templates(): TemplateService + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ + fun runs(): RunService + /** * Creates a journey from a set of nodes, in draft state unless you pass a published state. Send * nodes cannot be included until their templates exist. @@ -345,6 +352,12 @@ interface JourneyService { */ fun templates(): TemplateService.WithRawResponse + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with + * the templates scoped to them. + */ + fun runs(): RunService.WithRawResponse + /** * Returns a raw HTTP response for `post /journeys`, but is otherwise the same as * [JourneyService.create]. diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyServiceImpl.kt index 45fd53c0..15404c13 100644 --- a/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyServiceImpl.kt +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/JourneyServiceImpl.kt @@ -31,6 +31,8 @@ import com.courier.models.journeys.JourneyRetrieveParams import com.courier.models.journeys.JourneyVersionsListResponse import com.courier.models.journeys.JourneysInvokeResponse import com.courier.models.journeys.JourneysListResponse +import com.courier.services.blocking.journeys.RunService +import com.courier.services.blocking.journeys.RunServiceImpl import com.courier.services.blocking.journeys.TemplateService import com.courier.services.blocking.journeys.TemplateServiceImpl import java.util.function.Consumer @@ -49,6 +51,8 @@ class JourneyServiceImpl internal constructor(private val clientOptions: ClientO private val templates: TemplateService by lazy { TemplateServiceImpl(clientOptions) } + private val runs: RunService by lazy { RunServiceImpl(clientOptions) } + override fun withRawResponse(): JourneyService.WithRawResponse = withRawResponse override fun withOptions(modifier: Consumer): JourneyService = @@ -60,6 +64,12 @@ class JourneyServiceImpl internal constructor(private val clientOptions: ClientO */ override fun templates(): TemplateService = templates + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ + override fun runs(): RunService = runs + override fun create( params: JourneyCreateParams, requestOptions: RequestOptions, @@ -131,6 +141,10 @@ class JourneyServiceImpl internal constructor(private val clientOptions: ClientO TemplateServiceImpl.WithRawResponseImpl(clientOptions) } + private val runs: RunService.WithRawResponse by lazy { + RunServiceImpl.WithRawResponseImpl(clientOptions) + } + override fun withOptions( modifier: Consumer ): JourneyService.WithRawResponse = @@ -144,6 +158,12 @@ class JourneyServiceImpl internal constructor(private val clientOptions: ClientO */ override fun templates(): TemplateService.WithRawResponse = templates + /** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with + * the templates scoped to them. + */ + override fun runs(): RunService.WithRawResponse = runs + private val createHandler: Handler = jsonHandler(clientOptions.jsonMapper) diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/automations/RunService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/automations/RunService.kt new file mode 100644 index 00000000..3d82d508 --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/automations/RunService.kt @@ -0,0 +1,166 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.automations + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.automations.AutomationRunListResponse +import com.courier.models.automations.AutomationRunStepsResponse +import com.courier.models.automations.runs.RunListParams +import com.courier.models.automations.runs.RunListStepsParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +/** Invoke a stored automation template or an ad hoc automation defined in the request. */ +interface RunService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunService + + /** + * List runs of the workspace's v2 Automations, newest first, filtered by status, Template, or + * date range and paged by cursor. Journey (v3) runs are listed by `GET /journeys/runs` instead + * — the two surfaces never return each other's runs. Runs are retained for 95 days. + */ + fun list(): AutomationRunListResponse = list(RunListParams.none()) + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AutomationRunListResponse + + /** @see list */ + fun list(params: RunListParams = RunListParams.none()): AutomationRunListResponse = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): AutomationRunListResponse = + list(RunListParams.none(), requestOptions) + + /** + * List the per-step state of one Automation run, in full — this endpoint is not paginated. + * `message_id` is present on send steps that produced a message; follow it to `GET + * /messages/{message_id}` for delivery status. A send to a List or an Audience yields one + * `message_id` for the request, not one per recipient. + */ + fun listSteps(id: String): AutomationRunStepsResponse = listSteps(id, RunListStepsParams.none()) + + /** @see listSteps */ + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): AutomationRunStepsResponse = listSteps(params.toBuilder().id(id).build(), requestOptions) + + /** @see listSteps */ + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): AutomationRunStepsResponse = listSteps(id, params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): AutomationRunStepsResponse + + /** @see listSteps */ + fun listSteps(params: RunListStepsParams): AutomationRunStepsResponse = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps(id: String, requestOptions: RequestOptions): AutomationRunStepsResponse = + listSteps(id, RunListStepsParams.none(), requestOptions) + + /** A view of [RunService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /automations/runs`, but is otherwise the same as + * [RunService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = list(RunListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: RunListParams = RunListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(RunListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /automations/runs/{id}/steps`, but is otherwise the + * same as [RunService.listSteps]. + */ + @MustBeClosed + fun listSteps(id: String): HttpResponseFor = + listSteps(id, RunListStepsParams.none()) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + listSteps(params.toBuilder().id(id).build(), requestOptions) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + id: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): HttpResponseFor = + listSteps(id, params, RequestOptions.none()) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see listSteps */ + @MustBeClosed + fun listSteps(params: RunListStepsParams): HttpResponseFor = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + id: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + listSteps(id, RunListStepsParams.none(), requestOptions) + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/automations/RunServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/automations/RunServiceImpl.kt new file mode 100644 index 00000000..4b862bec --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/automations/RunServiceImpl.kt @@ -0,0 +1,121 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.automations + +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.parseable +import com.courier.core.prepare +import com.courier.models.automations.AutomationRunListResponse +import com.courier.models.automations.AutomationRunStepsResponse +import com.courier.models.automations.runs.RunListParams +import com.courier.models.automations.runs.RunListStepsParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** Invoke a stored automation template or an ad hoc automation defined in the request. */ +class RunServiceImpl internal constructor(private val clientOptions: ClientOptions) : RunService { + + private val withRawResponse: RunService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RunService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RunService = + RunServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): AutomationRunListResponse = + // get /automations/runs + withRawResponse().list(params, requestOptions).parse() + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): AutomationRunStepsResponse = + // get /automations/runs/{id}/steps + withRawResponse().listSteps(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RunService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RunService.WithRawResponse = + RunServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("automations", "runs") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listStepsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("id", params.id().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("automations", "runs", params._pathParam(0), "steps") + .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 { listStepsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/journeys/RunService.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/journeys/RunService.kt new file mode 100644 index 00000000..dccd5efc --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/journeys/RunService.kt @@ -0,0 +1,250 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.journeys + +import com.courier.core.ClientOptions +import com.courier.core.RequestOptions +import com.courier.core.http.HttpResponseFor +import com.courier.models.journeys.JourneyRunListResponse +import com.courier.models.journeys.JourneyRunResponse +import com.courier.models.journeys.JourneyRunStepsResponse +import com.courier.models.journeys.runs.RunListParams +import com.courier.models.journeys.runs.RunListStepsParams +import com.courier.models.journeys.runs.RunRetrieveParams +import com.google.errorprone.annotations.MustBeClosed +import java.util.function.Consumer + +/** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ +interface RunService { + + /** + * Returns a view of this service that provides access to raw HTTP responses for each method. + */ + fun withRawResponse(): WithRawResponse + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunService + + /** + * Fetch one Journey run by id. Returns `404` for an unknown run, a run belonging to another + * workspace, a run past the 95-day retention window, or an Automation run id — the same body in + * every case, so the response never reveals whether a run exists elsewhere. + */ + fun retrieve(runId: String): JourneyRunResponse = retrieve(runId, RunRetrieveParams.none()) + + /** @see retrieve */ + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): JourneyRunResponse = retrieve(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see retrieve */ + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + ): JourneyRunResponse = retrieve(runId, params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): JourneyRunResponse + + /** @see retrieve */ + fun retrieve(params: RunRetrieveParams): JourneyRunResponse = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + fun retrieve(runId: String, requestOptions: RequestOptions): JourneyRunResponse = + retrieve(runId, RunRetrieveParams.none(), requestOptions) + + /** + * List runs of the workspace's Journeys, newest first, filtered by status, Journey, or date + * range and paged by cursor. Runs of v2 Automations are listed by `GET /automations/runs` + * instead — the two surfaces never return each other's runs. Runs are retained for 95 days. + */ + fun list(): JourneyRunListResponse = list(RunListParams.none()) + + /** @see list */ + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): JourneyRunListResponse + + /** @see list */ + fun list(params: RunListParams = RunListParams.none()): JourneyRunListResponse = + list(params, RequestOptions.none()) + + /** @see list */ + fun list(requestOptions: RequestOptions): JourneyRunListResponse = + list(RunListParams.none(), requestOptions) + + /** + * List the per-node state of one Journey run, in full — this endpoint is not paginated. Each + * step's `node_id` is the id of the node in the published Journey, so a step maps directly onto + * the Journey graph. `message_id` is present on send steps that produced a message; follow it + * to `GET /messages/{message_id}` for delivery status. + */ + fun listSteps(runId: String): JourneyRunStepsResponse = + listSteps(runId, RunListStepsParams.none()) + + /** @see listSteps */ + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): JourneyRunStepsResponse = listSteps(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see listSteps */ + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): JourneyRunStepsResponse = listSteps(runId, params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): JourneyRunStepsResponse + + /** @see listSteps */ + fun listSteps(params: RunListStepsParams): JourneyRunStepsResponse = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + fun listSteps(runId: String, requestOptions: RequestOptions): JourneyRunStepsResponse = + listSteps(runId, RunListStepsParams.none(), requestOptions) + + /** A view of [RunService] that provides access to raw HTTP responses for each method. */ + interface WithRawResponse { + + /** + * Returns a view of this service with the given option modifications applied. + * + * The original service is not modified. + */ + fun withOptions(modifier: Consumer): RunService.WithRawResponse + + /** + * Returns a raw HTTP response for `get /journeys/runs/{run_id}`, but is otherwise the same + * as [RunService.retrieve]. + */ + @MustBeClosed + fun retrieve(runId: String): HttpResponseFor = + retrieve(runId, RunRetrieveParams.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + retrieve(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + runId: String, + params: RunRetrieveParams = RunRetrieveParams.none(), + ): HttpResponseFor = retrieve(runId, params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see retrieve */ + @MustBeClosed + fun retrieve(params: RunRetrieveParams): HttpResponseFor = + retrieve(params, RequestOptions.none()) + + /** @see retrieve */ + @MustBeClosed + fun retrieve( + runId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + retrieve(runId, RunRetrieveParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /journeys/runs`, but is otherwise the same as + * [RunService.list]. + */ + @MustBeClosed + fun list(): HttpResponseFor = list(RunListParams.none()) + + /** @see list */ + @MustBeClosed + fun list( + params: RunListParams = RunListParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see list */ + @MustBeClosed + fun list( + params: RunListParams = RunListParams.none() + ): HttpResponseFor = list(params, RequestOptions.none()) + + /** @see list */ + @MustBeClosed + fun list(requestOptions: RequestOptions): HttpResponseFor = + list(RunListParams.none(), requestOptions) + + /** + * Returns a raw HTTP response for `get /journeys/runs/{run_id}/steps`, but is otherwise the + * same as [RunService.listSteps]. + */ + @MustBeClosed + fun listSteps(runId: String): HttpResponseFor = + listSteps(runId, RunListStepsParams.none()) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor = + listSteps(params.toBuilder().runId(runId).build(), requestOptions) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + runId: String, + params: RunListStepsParams = RunListStepsParams.none(), + ): HttpResponseFor = + listSteps(runId, params, RequestOptions.none()) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions = RequestOptions.none(), + ): HttpResponseFor + + /** @see listSteps */ + @MustBeClosed + fun listSteps(params: RunListStepsParams): HttpResponseFor = + listSteps(params, RequestOptions.none()) + + /** @see listSteps */ + @MustBeClosed + fun listSteps( + runId: String, + requestOptions: RequestOptions, + ): HttpResponseFor = + listSteps(runId, RunListStepsParams.none(), requestOptions) + } +} diff --git a/courier-java-core/src/main/kotlin/com/courier/services/blocking/journeys/RunServiceImpl.kt b/courier-java-core/src/main/kotlin/com/courier/services/blocking/journeys/RunServiceImpl.kt new file mode 100644 index 00000000..55f4dc9c --- /dev/null +++ b/courier-java-core/src/main/kotlin/com/courier/services/blocking/journeys/RunServiceImpl.kt @@ -0,0 +1,163 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.journeys + +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.parseable +import com.courier.core.prepare +import com.courier.models.journeys.JourneyRunListResponse +import com.courier.models.journeys.JourneyRunResponse +import com.courier.models.journeys.JourneyRunStepsResponse +import com.courier.models.journeys.runs.RunListParams +import com.courier.models.journeys.runs.RunListStepsParams +import com.courier.models.journeys.runs.RunRetrieveParams +import java.util.function.Consumer +import kotlin.jvm.optionals.getOrNull + +/** + * Build, version, publish, invoke, and cancel multi-step notification workflows, along with the + * templates scoped to them. + */ +class RunServiceImpl internal constructor(private val clientOptions: ClientOptions) : RunService { + + private val withRawResponse: RunService.WithRawResponse by lazy { + WithRawResponseImpl(clientOptions) + } + + override fun withRawResponse(): RunService.WithRawResponse = withRawResponse + + override fun withOptions(modifier: Consumer): RunService = + RunServiceImpl(clientOptions.toBuilder().apply(modifier::accept).build()) + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): JourneyRunResponse = + // get /journeys/runs/{run_id} + withRawResponse().retrieve(params, requestOptions).parse() + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): JourneyRunListResponse = + // get /journeys/runs + withRawResponse().list(params, requestOptions).parse() + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): JourneyRunStepsResponse = + // get /journeys/runs/{run_id}/steps + withRawResponse().listSteps(params, requestOptions).parse() + + class WithRawResponseImpl internal constructor(private val clientOptions: ClientOptions) : + RunService.WithRawResponse { + + private val errorHandler: Handler = + errorHandler(errorBodyHandler(clientOptions.jsonMapper)) + + override fun withOptions( + modifier: Consumer + ): RunService.WithRawResponse = + RunServiceImpl.WithRawResponseImpl( + clientOptions.toBuilder().apply(modifier::accept).build() + ) + + private val retrieveHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun retrieve( + params: RunRetrieveParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("runId", params.runId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("journeys", "runs", 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 listHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun list( + params: RunListParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("journeys", "runs") + .build() + .prepare(clientOptions, params) + val requestOptions = requestOptions.applyDefaults(RequestOptions.from(clientOptions)) + val response = clientOptions.httpClient.execute(request, requestOptions) + return errorHandler.handle(response).parseable { + response + .use { listHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + + private val listStepsHandler: Handler = + jsonHandler(clientOptions.jsonMapper) + + override fun listSteps( + params: RunListStepsParams, + requestOptions: RequestOptions, + ): HttpResponseFor { + // We check here instead of in the params builder because this can be specified + // positionally or in the params class. + checkRequired("runId", params.runId().getOrNull()) + val request = + HttpRequest.builder() + .method(HttpMethod.GET) + .baseUrl(clientOptions.baseUrl()) + .addPathSegments("journeys", "runs", params._pathParam(0), "steps") + .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 { listStepsHandler.handle(it) } + .also { + if (requestOptions.responseValidation!!) { + it.validate() + } + } + } + } + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunListItemTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunListItemTest.kt new file mode 100644 index 00000000..c1cb23d8 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunListItemTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +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 AutomationRunListItemTest { + + @Test + fun create() { + val automationRunListItem = + AutomationRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + + assertThat(automationRunListItem.runId()).isEqualTo("run_id") + assertThat(automationRunListItem.source()).containsExactly("string") + assertThat(automationRunListItem.createdAt()).contains("created_at") + assertThat(automationRunListItem.status()).contains("status") + assertThat(automationRunListItem.templateId()).contains("template_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val automationRunListItem = + AutomationRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + + val roundtrippedAutomationRunListItem = + jsonMapper.readValue( + jsonMapper.writeValueAsString(automationRunListItem), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAutomationRunListItem).isEqualTo(automationRunListItem) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunListResponseTest.kt new file mode 100644 index 00000000..51263e9a --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunListResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +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 AutomationRunListResponseTest { + + @Test + fun create() { + val automationRunListResponse = + AutomationRunListResponse.builder() + .addRun( + AutomationRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + ) + .nextCursor("next_cursor") + .build() + + assertThat(automationRunListResponse.runs()) + .containsExactly( + AutomationRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + ) + assertThat(automationRunListResponse.nextCursor()).contains("next_cursor") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val automationRunListResponse = + AutomationRunListResponse.builder() + .addRun( + AutomationRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + ) + .nextCursor("next_cursor") + .build() + + val roundtrippedAutomationRunListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(automationRunListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAutomationRunListResponse).isEqualTo(automationRunListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunStepTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunStepTest.kt new file mode 100644 index 00000000..c789e497 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunStepTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +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 AutomationRunStepTest { + + @Test + fun create() { + val automationRunStep = + AutomationRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .stepId("step_id") + .updatedAt("updated_at") + .build() + + assertThat(automationRunStep.action()).isEqualTo("action") + assertThat(automationRunStep.status()).isEqualTo("status") + assertThat(automationRunStep.createdAt()).contains("created_at") + assertThat(automationRunStep.messageId()).contains("message_id") + assertThat(automationRunStep.stepId()).contains("step_id") + assertThat(automationRunStep.updatedAt()).contains("updated_at") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val automationRunStep = + AutomationRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .stepId("step_id") + .updatedAt("updated_at") + .build() + + val roundtrippedAutomationRunStep = + jsonMapper.readValue( + jsonMapper.writeValueAsString(automationRunStep), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAutomationRunStep).isEqualTo(automationRunStep) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunStepsResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunStepsResponseTest.kt new file mode 100644 index 00000000..6ddac20f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/automations/AutomationRunStepsResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations + +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 AutomationRunStepsResponseTest { + + @Test + fun create() { + val automationRunStepsResponse = + AutomationRunStepsResponse.builder() + .addStep( + AutomationRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .stepId("step_id") + .updatedAt("updated_at") + .build() + ) + .build() + + assertThat(automationRunStepsResponse.steps()) + .containsExactly( + AutomationRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .stepId("step_id") + .updatedAt("updated_at") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val automationRunStepsResponse = + AutomationRunStepsResponse.builder() + .addStep( + AutomationRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .stepId("step_id") + .updatedAt("updated_at") + .build() + ) + .build() + + val roundtrippedAutomationRunStepsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(automationRunStepsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedAutomationRunStepsResponse).isEqualTo(automationRunStepsResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/automations/runs/RunListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/automations/runs/RunListParamsTest.kt new file mode 100644 index 00000000..e7286252 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/automations/runs/RunListParamsTest.kt @@ -0,0 +1,58 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations.runs + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListParamsTest { + + @Test + fun create() { + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + } + + @Test + fun queryParams() { + val params = + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("cursor", "cursor") + .put("end_date", "end_date") + .put("limit", "321669910225") + .put("start_date", "start_date") + .put("status", "status") + .put("template_id", "template_id") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = RunListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/automations/runs/RunListStepsParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/automations/runs/RunListStepsParamsTest.kt new file mode 100644 index 00000000..74c497b1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/automations/runs/RunListStepsParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.automations.runs + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListStepsParamsTest { + + @Test + fun create() { + RunListStepsParams.builder().id("x").build() + } + + @Test + fun pathParams() { + val params = RunListStepsParams.builder().id("x").build() + + assertThat(params._pathParam(0)).isEqualTo("x") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyAudienceTriggerNodeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyAudienceTriggerNodeTest.kt new file mode 100644 index 00000000..96144e2a --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyAudienceTriggerNodeTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyAudienceTriggerNodeTest { + + @Test + fun create() { + val journeyAudienceTriggerNode = + JourneyAudienceTriggerNode.builder() + .audienceId("x") + .triggerType(JourneyAudienceTriggerNode.TriggerType.AUDIENCE) + .type(JourneyAudienceTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .build() + + assertThat(journeyAudienceTriggerNode.audienceId()).isEqualTo("x") + assertThat(journeyAudienceTriggerNode.triggerType()) + .isEqualTo(JourneyAudienceTriggerNode.TriggerType.AUDIENCE) + assertThat(journeyAudienceTriggerNode.type()) + .isEqualTo(JourneyAudienceTriggerNode.Type.TRIGGER) + assertThat(journeyAudienceTriggerNode.id()).contains("x") + assertThat(journeyAudienceTriggerNode.conditions()) + .contains(JourneyConditionsField.ofConditionAtom(listOf("string", "string"))) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyAudienceTriggerNode = + JourneyAudienceTriggerNode.builder() + .audienceId("x") + .triggerType(JourneyAudienceTriggerNode.TriggerType.AUDIENCE) + .type(JourneyAudienceTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .build() + + val roundtrippedJourneyAudienceTriggerNode = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyAudienceTriggerNode), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyAudienceTriggerNode).isEqualTo(journeyAudienceTriggerNode) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyNodeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyNodeTest.kt index 0bf83ae6..5ff80f56 100644 --- a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyNodeTest.kt +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyNodeTest.kt @@ -33,6 +33,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).contains(apiInvokeTrigger) assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -90,6 +92,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).contains(segmentTrigger) + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -128,6 +132,116 @@ internal class JourneyNodeTest { assertThat(roundtrippedJourneyNode).isEqualTo(journeyNode) } + @Test + fun ofAudienceTrigger() { + val audienceTrigger = + JourneyAudienceTriggerNode.builder() + .audienceId("x") + .triggerType(JourneyAudienceTriggerNode.TriggerType.AUDIENCE) + .type(JourneyAudienceTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .build() + + val journeyNode = JourneyNode.ofAudienceTrigger(audienceTrigger) + + assertThat(journeyNode.apiInvokeTrigger()).isEmpty + assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).contains(audienceTrigger) + assertThat(journeyNode.webhookTrigger()).isEmpty + assertThat(journeyNode.send()).isEmpty + assertThat(journeyNode.delayDuration()).isEmpty + assertThat(journeyNode.delayUntil()).isEmpty + assertThat(journeyNode.fetchGetDelete()).isEmpty + assertThat(journeyNode.fetchPostPut()).isEmpty + assertThat(journeyNode.ai()).isEmpty + assertThat(journeyNode.throttleStatic()).isEmpty + assertThat(journeyNode.throttleDynamic()).isEmpty + assertThat(journeyNode.batch()).isEmpty + assertThat(journeyNode.addToDigest()).isEmpty + assertThat(journeyNode.exit()).isEmpty + assertThat(journeyNode.branch()).isEmpty + } + + @Test + fun ofAudienceTriggerRoundtrip() { + val jsonMapper = jsonMapper() + val journeyNode = + JourneyNode.ofAudienceTrigger( + JourneyAudienceTriggerNode.builder() + .audienceId("x") + .triggerType(JourneyAudienceTriggerNode.TriggerType.AUDIENCE) + .type(JourneyAudienceTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .build() + ) + + val roundtrippedJourneyNode = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyNode), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyNode).isEqualTo(journeyNode) + } + + @Test + fun ofWebhookTrigger() { + val webhookTrigger = + JourneyWebhookTriggerNode.builder() + .eventSource("event_source") + .triggerType(JourneyWebhookTriggerNode.TriggerType.WEBHOOK) + .type(JourneyWebhookTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .eventId("event_id") + .build() + + val journeyNode = JourneyNode.ofWebhookTrigger(webhookTrigger) + + assertThat(journeyNode.apiInvokeTrigger()).isEmpty + assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).contains(webhookTrigger) + assertThat(journeyNode.send()).isEmpty + assertThat(journeyNode.delayDuration()).isEmpty + assertThat(journeyNode.delayUntil()).isEmpty + assertThat(journeyNode.fetchGetDelete()).isEmpty + assertThat(journeyNode.fetchPostPut()).isEmpty + assertThat(journeyNode.ai()).isEmpty + assertThat(journeyNode.throttleStatic()).isEmpty + assertThat(journeyNode.throttleDynamic()).isEmpty + assertThat(journeyNode.batch()).isEmpty + assertThat(journeyNode.addToDigest()).isEmpty + assertThat(journeyNode.exit()).isEmpty + assertThat(journeyNode.branch()).isEmpty + } + + @Test + fun ofWebhookTriggerRoundtrip() { + val jsonMapper = jsonMapper() + val journeyNode = + JourneyNode.ofWebhookTrigger( + JourneyWebhookTriggerNode.builder() + .eventSource("event_source") + .triggerType(JourneyWebhookTriggerNode.TriggerType.WEBHOOK) + .type(JourneyWebhookTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .eventId("event_id") + .build() + ) + + val roundtrippedJourneyNode = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyNode), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyNode).isEqualTo(journeyNode) + } + @Test fun ofSend() { val send = @@ -185,6 +299,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).contains(send) assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -284,6 +400,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).contains(delayDuration) assertThat(journeyNode.delayUntil()).isEmpty @@ -336,6 +454,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).contains(delayUntil) @@ -404,6 +524,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -489,6 +611,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -564,6 +688,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -623,6 +749,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -678,6 +806,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -742,6 +872,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -803,6 +935,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -847,6 +981,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty @@ -915,6 +1051,8 @@ internal class JourneyNodeTest { assertThat(journeyNode.apiInvokeTrigger()).isEmpty assertThat(journeyNode.segmentTrigger()).isEmpty + assertThat(journeyNode.audienceTrigger()).isEmpty + assertThat(journeyNode.webhookTrigger()).isEmpty assertThat(journeyNode.send()).isEmpty assertThat(journeyNode.delayDuration()).isEmpty assertThat(journeyNode.delayUntil()).isEmpty diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunListItemTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunListItemTest.kt new file mode 100644 index 00000000..7352494e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunListItemTest.kt @@ -0,0 +1,50 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyRunListItemTest { + + @Test + fun create() { + val journeyRunListItem = + JourneyRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + + assertThat(journeyRunListItem.runId()).isEqualTo("run_id") + assertThat(journeyRunListItem.source()).containsExactly("string") + assertThat(journeyRunListItem.createdAt()).contains("created_at") + assertThat(journeyRunListItem.status()).contains("status") + assertThat(journeyRunListItem.templateId()).contains("template_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyRunListItem = + JourneyRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + + val roundtrippedJourneyRunListItem = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyRunListItem), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyRunListItem).isEqualTo(journeyRunListItem) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunListResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunListResponseTest.kt new file mode 100644 index 00000000..0bbea8fe --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunListResponseTest.kt @@ -0,0 +1,69 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyRunListResponseTest { + + @Test + fun create() { + val journeyRunListResponse = + JourneyRunListResponse.builder() + .addRun( + JourneyRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + ) + .nextCursor("next_cursor") + .prevCursor("prev_cursor") + .build() + + assertThat(journeyRunListResponse.runs()) + .containsExactly( + JourneyRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + ) + assertThat(journeyRunListResponse.nextCursor()).contains("next_cursor") + assertThat(journeyRunListResponse.prevCursor()).contains("prev_cursor") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyRunListResponse = + JourneyRunListResponse.builder() + .addRun( + JourneyRunListItem.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .build() + ) + .nextCursor("next_cursor") + .prevCursor("prev_cursor") + .build() + + val roundtrippedJourneyRunListResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyRunListResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyRunListResponse).isEqualTo(journeyRunListResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunResponseTest.kt new file mode 100644 index 00000000..b1acd76c --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyRunResponseTest { + + @Test + fun create() { + val journeyRunResponse = + JourneyRunResponse.builder() + .run( + JourneyRun.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .updatedAt("updated_at") + .build() + ) + .build() + + assertThat(journeyRunResponse.run()) + .isEqualTo( + JourneyRun.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .updatedAt("updated_at") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyRunResponse = + JourneyRunResponse.builder() + .run( + JourneyRun.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .updatedAt("updated_at") + .build() + ) + .build() + + val roundtrippedJourneyRunResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyRunResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyRunResponse).isEqualTo(journeyRunResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunStepTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunStepTest.kt new file mode 100644 index 00000000..6952df37 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunStepTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyRunStepTest { + + @Test + fun create() { + val journeyRunStep = + JourneyRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .nodeId("node_id") + .updatedAt("updated_at") + .build() + + assertThat(journeyRunStep.action()).isEqualTo("action") + assertThat(journeyRunStep.status()).isEqualTo("status") + assertThat(journeyRunStep.createdAt()).contains("created_at") + assertThat(journeyRunStep.messageId()).contains("message_id") + assertThat(journeyRunStep.nodeId()).contains("node_id") + assertThat(journeyRunStep.updatedAt()).contains("updated_at") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyRunStep = + JourneyRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .nodeId("node_id") + .updatedAt("updated_at") + .build() + + val roundtrippedJourneyRunStep = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyRunStep), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyRunStep).isEqualTo(journeyRunStep) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunStepsResponseTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunStepsResponseTest.kt new file mode 100644 index 00000000..5deb1d46 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunStepsResponseTest.kt @@ -0,0 +1,66 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyRunStepsResponseTest { + + @Test + fun create() { + val journeyRunStepsResponse = + JourneyRunStepsResponse.builder() + .addStep( + JourneyRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .nodeId("node_id") + .updatedAt("updated_at") + .build() + ) + .build() + + assertThat(journeyRunStepsResponse.steps()) + .containsExactly( + JourneyRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .nodeId("node_id") + .updatedAt("updated_at") + .build() + ) + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyRunStepsResponse = + JourneyRunStepsResponse.builder() + .addStep( + JourneyRunStep.builder() + .action("action") + .status("status") + .createdAt("created_at") + .messageId("message_id") + .nodeId("node_id") + .updatedAt("updated_at") + .build() + ) + .build() + + val roundtrippedJourneyRunStepsResponse = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyRunStepsResponse), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyRunStepsResponse).isEqualTo(journeyRunStepsResponse) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunTest.kt new file mode 100644 index 00000000..b76a9f3a --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyRunTest.kt @@ -0,0 +1,53 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyRunTest { + + @Test + fun create() { + val journeyRun = + JourneyRun.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .updatedAt("updated_at") + .build() + + assertThat(journeyRun.runId()).isEqualTo("run_id") + assertThat(journeyRun.source()).containsExactly("string") + assertThat(journeyRun.createdAt()).contains("created_at") + assertThat(journeyRun.status()).contains("status") + assertThat(journeyRun.templateId()).contains("template_id") + assertThat(journeyRun.updatedAt()).contains("updated_at") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyRun = + JourneyRun.builder() + .runId("run_id") + .addSource("string") + .createdAt("created_at") + .status("status") + .templateId("template_id") + .updatedAt("updated_at") + .build() + + val roundtrippedJourneyRun = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyRun), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyRun).isEqualTo(journeyRun) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyWebhookTriggerNodeTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyWebhookTriggerNodeTest.kt new file mode 100644 index 00000000..66c7f7f1 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/JourneyWebhookTriggerNodeTest.kt @@ -0,0 +1,56 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys + +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 JourneyWebhookTriggerNodeTest { + + @Test + fun create() { + val journeyWebhookTriggerNode = + JourneyWebhookTriggerNode.builder() + .eventSource("event_source") + .triggerType(JourneyWebhookTriggerNode.TriggerType.WEBHOOK) + .type(JourneyWebhookTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .eventId("event_id") + .build() + + assertThat(journeyWebhookTriggerNode.eventSource()).isEqualTo("event_source") + assertThat(journeyWebhookTriggerNode.triggerType()) + .isEqualTo(JourneyWebhookTriggerNode.TriggerType.WEBHOOK) + assertThat(journeyWebhookTriggerNode.type()) + .isEqualTo(JourneyWebhookTriggerNode.Type.TRIGGER) + assertThat(journeyWebhookTriggerNode.id()).contains("x") + assertThat(journeyWebhookTriggerNode.conditions()) + .contains(JourneyConditionsField.ofConditionAtom(listOf("string", "string"))) + assertThat(journeyWebhookTriggerNode.eventId()).contains("event_id") + } + + @Test + fun roundtrip() { + val jsonMapper = jsonMapper() + val journeyWebhookTriggerNode = + JourneyWebhookTriggerNode.builder() + .eventSource("event_source") + .triggerType(JourneyWebhookTriggerNode.TriggerType.WEBHOOK) + .type(JourneyWebhookTriggerNode.Type.TRIGGER) + .id("x") + .conditionsOfConditionAtom(listOf("string", "string")) + .eventId("event_id") + .build() + + val roundtrippedJourneyWebhookTriggerNode = + jsonMapper.readValue( + jsonMapper.writeValueAsString(journeyWebhookTriggerNode), + jacksonTypeRef(), + ) + + assertThat(roundtrippedJourneyWebhookTriggerNode).isEqualTo(journeyWebhookTriggerNode) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunListParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunListParamsTest.kt new file mode 100644 index 00000000..52c3ba1e --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunListParamsTest.kt @@ -0,0 +1,58 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys.runs + +import com.courier.core.http.QueryParams +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListParamsTest { + + @Test + fun create() { + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + } + + @Test + fun queryParams() { + val params = + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + + val queryParams = params._queryParams() + + assertThat(queryParams) + .isEqualTo( + QueryParams.builder() + .put("cursor", "cursor") + .put("end_date", "end_date") + .put("limit", "321669910225") + .put("start_date", "start_date") + .put("status", "status") + .put("template_id", "template_id") + .build() + ) + } + + @Test + fun queryParamsWithoutOptionalFields() { + val params = RunListParams.builder().build() + + val queryParams = params._queryParams() + + assertThat(queryParams).isEqualTo(QueryParams.builder().build()) + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunListStepsParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunListStepsParamsTest.kt new file mode 100644 index 00000000..a98f74a9 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunListStepsParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys.runs + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunListStepsParamsTest { + + @Test + fun create() { + RunListStepsParams.builder().runId("x").build() + } + + @Test + fun pathParams() { + val params = RunListStepsParams.builder().runId("x").build() + + assertThat(params._pathParam(0)).isEqualTo("x") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunRetrieveParamsTest.kt b/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunRetrieveParamsTest.kt new file mode 100644 index 00000000..b65a851f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/models/journeys/runs/RunRetrieveParamsTest.kt @@ -0,0 +1,23 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.models.journeys.runs + +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test + +internal class RunRetrieveParamsTest { + + @Test + fun create() { + RunRetrieveParams.builder().runId("x").build() + } + + @Test + fun pathParams() { + val params = RunRetrieveParams.builder().runId("x").build() + + assertThat(params._pathParam(0)).isEqualTo("x") + // out-of-bound path param + assertThat(params._pathParam(1)).isEqualTo("") + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/automations/RunServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/automations/RunServiceAsyncTest.kt new file mode 100644 index 00000000..632181d9 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/automations/RunServiceAsyncTest.kt @@ -0,0 +1,45 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.automations + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.models.automations.runs.RunListParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RunServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.automations().runs() + + val automationRunListResponseFuture = + runServiceAsync.list( + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + ) + + val automationRunListResponse = automationRunListResponseFuture.get() + automationRunListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listSteps() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.automations().runs() + + val automationRunStepsResponseFuture = runServiceAsync.listSteps("x") + + val automationRunStepsResponse = automationRunStepsResponseFuture.get() + automationRunStepsResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/async/journeys/RunServiceAsyncTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/async/journeys/RunServiceAsyncTest.kt new file mode 100644 index 00000000..d63e1be5 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/async/journeys/RunServiceAsyncTest.kt @@ -0,0 +1,57 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.async.journeys + +import com.courier.client.okhttp.CourierOkHttpClientAsync +import com.courier.models.journeys.runs.RunListParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RunServiceAsyncTest { + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.journeys().runs() + + val journeyRunResponseFuture = runServiceAsync.retrieve("x") + + val journeyRunResponse = journeyRunResponseFuture.get() + journeyRunResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.journeys().runs() + + val journeyRunListResponseFuture = + runServiceAsync.list( + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + ) + + val journeyRunListResponse = journeyRunListResponseFuture.get() + journeyRunListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listSteps() { + val client = CourierOkHttpClientAsync.builder().apiKey("My API Key").build() + val runServiceAsync = client.journeys().runs() + + val journeyRunStepsResponseFuture = runServiceAsync.listSteps("x") + + val journeyRunStepsResponse = journeyRunStepsResponseFuture.get() + journeyRunStepsResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/automations/RunServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/automations/RunServiceTest.kt new file mode 100644 index 00000000..32a20f9f --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/automations/RunServiceTest.kt @@ -0,0 +1,43 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.automations + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.models.automations.runs.RunListParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RunServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.automations().runs() + + val automationRunListResponse = + runService.list( + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + ) + + automationRunListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listSteps() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.automations().runs() + + val automationRunStepsResponse = runService.listSteps("x") + + automationRunStepsResponse.validate() + } +} diff --git a/courier-java-core/src/test/kotlin/com/courier/services/blocking/journeys/RunServiceTest.kt b/courier-java-core/src/test/kotlin/com/courier/services/blocking/journeys/RunServiceTest.kt new file mode 100644 index 00000000..9187bc97 --- /dev/null +++ b/courier-java-core/src/test/kotlin/com/courier/services/blocking/journeys/RunServiceTest.kt @@ -0,0 +1,54 @@ +// File generated from our OpenAPI spec by Stainless. + +package com.courier.services.blocking.journeys + +import com.courier.client.okhttp.CourierOkHttpClient +import com.courier.models.journeys.runs.RunListParams +import org.junit.jupiter.api.Disabled +import org.junit.jupiter.api.Test + +internal class RunServiceTest { + + @Disabled("Mock server tests are disabled") + @Test + fun retrieve() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.journeys().runs() + + val journeyRunResponse = runService.retrieve("x") + + journeyRunResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun list() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.journeys().runs() + + val journeyRunListResponse = + runService.list( + RunListParams.builder() + .cursor("cursor") + .endDate("end_date") + .limit("321669910225") + .startDate("start_date") + .status("status") + .templateId("template_id") + .build() + ) + + journeyRunListResponse.validate() + } + + @Disabled("Mock server tests are disabled") + @Test + fun listSteps() { + val client = CourierOkHttpClient.builder().apiKey("My API Key").build() + val runService = client.journeys().runs() + + val journeyRunStepsResponse = runService.listSteps("x") + + journeyRunStepsResponse.validate() + } +}