From d2f36b7c6df0af3d36cdb332f9943521a16024a4 Mon Sep 17 00:00:00 2001 From: Aaron de Mello Date: Fri, 23 May 2025 11:07:53 -0400 Subject: [PATCH] feat: add name attribute support to Scheduler Configuration - Add name field to Configuration, CreateConfigurationRequest, and UpdateConfigurationRequest models - Add builder support for name attribute in both create and update request classes - Add comprehensive tests for name attribute serialization and builder functionality - Name field is optional and defaults to organizer's name when not set - Fully backward compatible implementation --- CHANGELOG.md | 5 ++ .../models/CreateConfigurationRequest.kt | 15 ++++ src/main/kotlin/com/nylas/models/Scheduler.kt | 5 ++ .../models/UpdateConfigurationRequest.kt | 21 ++++- .../com/nylas/resources/ConfigurationsTest.kt | 78 +++++++++++++++++++ 5 files changed, 121 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c6bbd80..bcc85f80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Nylas Java SDK Changelog +## [Unreleased] + +### Added +* Added support for `name` attribute in Scheduler Configuration class to allow custom naming of Scheduling Pages + ### [2.8.0] - Release 2025-04-30 * Added support for Notetaker APIs * Added support for Notetaker via the calendar and event APIs diff --git a/src/main/kotlin/com/nylas/models/CreateConfigurationRequest.kt b/src/main/kotlin/com/nylas/models/CreateConfigurationRequest.kt index 763dabd8..d50b4a89 100644 --- a/src/main/kotlin/com/nylas/models/CreateConfigurationRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateConfigurationRequest.kt @@ -21,6 +21,11 @@ data class CreateConfigurationRequest( */ @Json(name = "event_booking") val eventBooking: ConfigurationEventBooking, + /** + * The name of the Scheduling Page. If not set, it defaults to the organizer's name. + */ + @Json(name = "name") + val name: String? = null, /** * Unique identifier for the Configuration object. */ @@ -54,10 +59,19 @@ data class CreateConfigurationRequest( private val eventBooking: ConfigurationEventBooking, ) { private var requiresSessionAuth: Boolean? = null + private var name: String? = null private var slug: String? = null private var scheduler: ConfigurationSchedulerSettings? = null private var appearance: Map? = null + /** + * Set the name of the Scheduling Page. + * + * @param name The name of the Scheduling Page. If not set, it defaults to the organizer's name. + * @return The builder + */ + fun name(name: String) = apply { this.name = name } + /** * Set the unique identifier for the configuration. * @@ -99,6 +113,7 @@ data class CreateConfigurationRequest( participants, availability, eventBooking, + name, slug, requiresSessionAuth, scheduler, diff --git a/src/main/kotlin/com/nylas/models/Scheduler.kt b/src/main/kotlin/com/nylas/models/Scheduler.kt index 026491c9..e05fc401 100644 --- a/src/main/kotlin/com/nylas/models/Scheduler.kt +++ b/src/main/kotlin/com/nylas/models/Scheduler.kt @@ -26,6 +26,11 @@ data class Configuration( */ @Json(name = "event_booking") val eventBooking: ConfigurationEventBooking, + /** + * The name of the Scheduling Page. If not set, it defaults to the organizer's name. + */ + @Json(name = "name") + val name: String? = null, /** * Unique identifier for the Configuration object. */ diff --git a/src/main/kotlin/com/nylas/models/UpdateConfigurationRequest.kt b/src/main/kotlin/com/nylas/models/UpdateConfigurationRequest.kt index 3386ee0f..5e79048f 100644 --- a/src/main/kotlin/com/nylas/models/UpdateConfigurationRequest.kt +++ b/src/main/kotlin/com/nylas/models/UpdateConfigurationRequest.kt @@ -21,6 +21,11 @@ data class UpdateConfigurationRequest( */ @Json(name = "event_booking") val eventBooking: ConfigurationEventBooking? = null, + /** + * The name of the Scheduling Page. If not set, it defaults to the organizer's name. + */ + @Json(name = "name") + val name: String? = null, /** * Unique identifier for the Configuration object. */ @@ -49,6 +54,7 @@ data class UpdateConfigurationRequest( private var participants: List? = null private var availability: ConfigurationAvailability? = null private var eventBooking: ConfigurationEventBooking? = null + private var name: String? = null private var requiresSessionAuth: Boolean? = null private var slug: String? = null private var scheduler: ConfigurationSchedulerSettings? = null @@ -76,12 +82,12 @@ data class UpdateConfigurationRequest( fun eventBooking(eventBooking: ConfigurationEventBooking) = apply { this.eventBooking = eventBooking } /** - * Set the unique identifier for the configuration. + * Set the name of the Scheduling Page. * - * @param slug Unique identifier for the Configuration object. + * @param name The name of the Scheduling Page. If not set, it defaults to the organizer's name. * @return The builder */ - fun slug(slug: String) = apply { this.slug = slug } + fun name(name: String) = apply { this.name = name } /** * Set if scheduling Availability and Bookings endpoints require a valid session ID. @@ -107,6 +113,14 @@ data class UpdateConfigurationRequest( */ fun appearance(appearance: Map) = apply { this.appearance = appearance } + /** + * Set the unique identifier for the configuration. + * + * @param slug Unique identifier for the Configuration object. + * @return The builder + */ + fun slug(slug: String) = apply { this.slug = slug } + /** * Build the [UpdateConfigurationRequest]. * @@ -116,6 +130,7 @@ data class UpdateConfigurationRequest( participants, availability, eventBooking, + name, slug, requiresSessionAuth, scheduler, diff --git a/src/test/kotlin/com/nylas/resources/ConfigurationsTest.kt b/src/test/kotlin/com/nylas/resources/ConfigurationsTest.kt index 7fb5f34c..d7c06f91 100644 --- a/src/test/kotlin/com/nylas/resources/ConfigurationsTest.kt +++ b/src/test/kotlin/com/nylas/resources/ConfigurationsTest.kt @@ -45,6 +45,7 @@ class ConfigurationsTest { """ { "id": "abc-123-configuration-id", + "name": "My Scheduling Page", "slug": null, "participants": [ { @@ -148,6 +149,7 @@ class ConfigurationsTest { val config = adapter.fromJson(jsonBuffer)!! assertIs(config) assertEquals("abc-123-configuration-id", config.id) + assertEquals("My Scheduling Page", config.name) assertEquals(false, config.requiresSessionAuth) assertEquals(7, config.scheduler?.availableDaysInFuture) assertEquals(60, config.scheduler?.minCancellationNotice) @@ -262,6 +264,55 @@ class ConfigurationsTest { assertEquals(adapter.toJson(createConfigurationRequest), requestBodyCaptor.firstValue) } + @Test + fun `creating a configuration with name calls requests with the correct params`() { + val adapter = JsonHelper.moshi().adapter(CreateConfigurationRequest::class.java) + val participantCalendarIds = ArrayList() + participantCalendarIds.add("primary") + + val configurationAvailabilityParticipant = ConfigurationAvailabilityParticipant.Builder().calendarIds(participantCalendarIds).build() + + val configurationBookingParticipant = ConfigurationBookingParticipant.Builder().calendarId("primary").build() + + val configurationParticipant = ConfigurationParticipant.Builder("test@nylas.com") + .availability(configurationAvailabilityParticipant) + .booking(configurationBookingParticipant) + .name("Test Participant") + .isOrganizer(true) + .build() + + val configurationAvailability = ConfigurationAvailability.Builder().intervalMinutes(30).build() + + val configurationEventBooking = ConfigurationEventBooking.Builder().title("Test Event Booking").build() + + val participants = ArrayList() + participants.add(configurationParticipant) + + val createConfigurationRequest = CreateConfigurationRequest.Builder( + participants, + configurationAvailability, + configurationEventBooking, + ).name("My Custom Scheduling Page").build() + + configurations.create(grantId, createConfigurationRequest) + + val pathCaptor = argumentCaptor() + val typeCaptor = argumentCaptor() + val requestBodyCaptor = argumentCaptor() + val queryParamCaptor = argumentCaptor() + val overrideParamCaptor = argumentCaptor() + verify(mockNylasClient).executePost>( + pathCaptor.capture(), + typeCaptor.capture(), + requestBodyCaptor.capture(), + queryParamCaptor.capture(), + overrideParamCaptor.capture(), + ) + assertEquals("v3/grants/$grantId/scheduling/configurations", pathCaptor.firstValue) + assertEquals(Types.newParameterizedType(Response::class.java, Configuration::class.java), typeCaptor.firstValue) + assertEquals(adapter.toJson(createConfigurationRequest), requestBodyCaptor.firstValue) + } + @Test fun `updating a configuration calls requests with the correct params`() { val adapter = JsonHelper.moshi().adapter(UpdateConfigurationRequest::class.java) @@ -288,6 +339,33 @@ class ConfigurationsTest { assertEquals(adapter.toJson(updateConfigurationRequest), requestBodyCaptor.firstValue) } + @Test + fun `updating a configuration with name calls requests with the correct params`() { + val adapter = JsonHelper.moshi().adapter(UpdateConfigurationRequest::class.java) + val configId = "abc-123-configuration-id" + val updateConfigurationRequest = UpdateConfigurationRequest.Builder() + .name("Updated Scheduling Page Name") + .build() + + configurations.update(grantId, configId, updateConfigurationRequest) + + val pathCaptor = argumentCaptor() + val typeCaptor = argumentCaptor() + val requestBodyCaptor = argumentCaptor() + val queryParamCaptor = argumentCaptor() + val overrideParamCaptor = argumentCaptor() + verify(mockNylasClient).executePut>( + pathCaptor.capture(), + typeCaptor.capture(), + requestBodyCaptor.capture(), + queryParamCaptor.capture(), + overrideParamCaptor.capture(), + ) + assertEquals("v3/grants/$grantId/scheduling/configurations/$configId", pathCaptor.firstValue) + assertEquals(Types.newParameterizedType(Response::class.java, Configuration::class.java), typeCaptor.firstValue) + assertEquals(adapter.toJson(updateConfigurationRequest), requestBodyCaptor.firstValue) + } + @Test fun `finding a configuration calls requests with the correct params`() { val configId = "configuration-id"