From cbf26c7083d9a2307d09961074f6c938ab1fcfdc Mon Sep 17 00:00:00 2001 From: YIFAN WU <14408339+yifanplanet@users.noreply.github.com> Date: Mon, 18 Dec 2023 16:13:40 -0500 Subject: [PATCH] Events API Send-RSVP support (#175) - Events API Send-RSVP support # License I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner. --- .../kotlin/com/nylas/models/RsvpStatus.kt | 17 +++++++++++ .../com/nylas/models/SendRsvpQueryParams.kt | 28 +++++++++++++++++++ .../com/nylas/models/SendRsvpRequest.kt | 14 ++++++++++ src/main/kotlin/com/nylas/resources/Events.kt | 17 +++++++++++ 4 files changed, 76 insertions(+) create mode 100644 src/main/kotlin/com/nylas/models/RsvpStatus.kt create mode 100644 src/main/kotlin/com/nylas/models/SendRsvpQueryParams.kt create mode 100644 src/main/kotlin/com/nylas/models/SendRsvpRequest.kt diff --git a/src/main/kotlin/com/nylas/models/RsvpStatus.kt b/src/main/kotlin/com/nylas/models/RsvpStatus.kt new file mode 100644 index 00000000..ec38e076 --- /dev/null +++ b/src/main/kotlin/com/nylas/models/RsvpStatus.kt @@ -0,0 +1,17 @@ +package com.nylas.models + +import com.squareup.moshi.Json + +/** + * Enum representing the allowed RSVP status values. + */ +enum class RsvpStatus { + @Json(name = "yes") + YES, + + @Json(name = "no") + NO, + + @Json(name = "maybe") + MAYBE, +} diff --git a/src/main/kotlin/com/nylas/models/SendRsvpQueryParams.kt b/src/main/kotlin/com/nylas/models/SendRsvpQueryParams.kt new file mode 100644 index 00000000..345f1c28 --- /dev/null +++ b/src/main/kotlin/com/nylas/models/SendRsvpQueryParams.kt @@ -0,0 +1,28 @@ +package com.nylas.models + +import com.squareup.moshi.Json + +/** + * Class representation of the query parameters for sending RSVP. + */ +data class SendRsvpQueryParams( + /** + * The RSVP status for the event. Must be yes, no, or maybe + */ + @Json(name = "status") + val status: RsvpStatus +) : IQueryParams { + + /** + * Builder for [SendRsvpQueryParams]. + * @param status The RSVP status for the event. Must be yes, no, or maybe + */ + data class Builder(private val status: RsvpStatus) { + + /** + * Builds a [SendRsvpQueryParams] instance. + * @return The [SendRsvpQueryParams] instance. + */ + fun build() = SendRsvpQueryParams(status) + } +} diff --git a/src/main/kotlin/com/nylas/models/SendRsvpRequest.kt b/src/main/kotlin/com/nylas/models/SendRsvpRequest.kt new file mode 100644 index 00000000..bbdccf70 --- /dev/null +++ b/src/main/kotlin/com/nylas/models/SendRsvpRequest.kt @@ -0,0 +1,14 @@ +package com.nylas.models + +import com.squareup.moshi.Json + +/** + * Class representation of a Nylas send-rsvp request + */ +data class SendRsvpRequest( + /** + * RSVP status. must be yes, no, or maybe + */ + @Json(name = "status") + val status: RsvpStatus, +) diff --git a/src/main/kotlin/com/nylas/resources/Events.kt b/src/main/kotlin/com/nylas/resources/Events.kt index d9735aef..bf80e7a1 100644 --- a/src/main/kotlin/com/nylas/resources/Events.kt +++ b/src/main/kotlin/com/nylas/resources/Events.kt @@ -80,4 +80,21 @@ class Events(client: NylasClient) : Resource(client, Event::class.java) { val path = String.format("v3/grants/%s/events/%s", identifier, eventId) return destroyResource(path, queryParams) } + + /** + * Send RSVP. Allows users to respond to events they have been added to as an attendee. + * @param identifier The identifier of the grant to act upon + * @param eventId The id of the Event to update. + * @param requestBody The values to send the RSVP with + * @param queryParams The query parameters to include in the request + * @return The send-rsvp response + */ + @Throws(NylasApiError::class, NylasSdkTimeoutError::class) + fun sendRsvp(identifier: String, requestBody: SendRsvpRequest, queryParams: SendRsvpQueryParams): DeleteResponse{ + val path = String.format("v3/grants/%s/events/%s/send-rsvp", identifier, eventId) + val adapter = JsonHelper.moshi().adapter(SendRsvpRequest::class.java) + val serializedRequestBody = adapter.toJson(requestBody) + return createResource(path, serializedRequestBody, queryParams) + } + }