diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d0b090f..83563dfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Nylas Java SDK Changelog +## [Unreleased] + +### Added +* `colorId` field on `Event`, `CreateEventRequest`, and `UpdateEventRequest` for Google Calendar event colors, mapped to the `color_id` JSON property. + Valid values are strings `"1"` through `"11"`. + See [Google Calendar Colors](https://developers.google.com/calendar/api/v3/reference/colors). + ## [v2.15.1] - Release 2026-03-30 ### Changed diff --git a/src/main/kotlin/com/nylas/models/CreateEventRequest.kt b/src/main/kotlin/com/nylas/models/CreateEventRequest.kt index ef187ec8..d42044b2 100644 --- a/src/main/kotlin/com/nylas/models/CreateEventRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateEventRequest.kt @@ -94,6 +94,13 @@ data class CreateEventRequest( */ @Json(name = "notetaker") val notetaker: EventNotetakerRequest? = null, + /** + * The Google color ID for the event. Only supported by Google Calendar providers; ignored by other providers. + * Valid values are strings "1" through "11". + * @see Google Calendar Colors + */ + @Json(name = "color_id") + val colorId: String? = null, ) { /** * This sealed class represents the different types of event time configurations. @@ -511,6 +518,7 @@ data class CreateEventRequest( private var capacity: Int? = null private var hideParticipant: Boolean? = null private var notetaker: EventNotetakerRequest? = null + private var colorId: String? = null /** * Set the event title. @@ -625,6 +633,15 @@ data class CreateEventRequest( */ fun notetaker(notetaker: EventNotetakerRequest) = apply { this.notetaker = notetaker } + /** + * Set the Google color ID for the event. Only supported by Google Calendar providers; ignored by other providers. + * Valid values are strings "1" through "11". + * @param colorId The Google color ID. + * @return The builder. + * @see Google Calendar Colors + */ + fun colorId(colorId: String) = apply { this.colorId = colorId } + /** * Builds the [CreateEventRequest] object. * @return [CreateEventRequest] object. @@ -647,6 +664,7 @@ data class CreateEventRequest( capacity, hideParticipant, notetaker, + colorId, ) } } diff --git a/src/main/kotlin/com/nylas/models/Event.kt b/src/main/kotlin/com/nylas/models/Event.kt index 0931cb3f..4c83af7c 100644 --- a/src/main/kotlin/com/nylas/models/Event.kt +++ b/src/main/kotlin/com/nylas/models/Event.kt @@ -155,6 +155,13 @@ data class Event( */ @Json(name = "original_start_time") val originalStartTime: Long? = null, + /** + * The Google color ID for the event. Only supported by Google Calendar providers; ignored by other providers. + * Valid values are strings "1" through "11". + * @see Google Calendar Colors + */ + @Json(name = "color_id") + val colorId: String? = null, ) { /** * Get the type of object. diff --git a/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt b/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt index aa9bfe02..6c3af4b4 100644 --- a/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt +++ b/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt @@ -94,6 +94,13 @@ data class UpdateEventRequest( */ @Json(name = "notetaker") val notetaker: EventNotetakerRequest? = null, + /** + * The Google color ID for the event. Only supported by Google Calendar providers; ignored by other providers. + * Valid values are strings "1" through "11". + * @see Google Calendar Colors + */ + @Json(name = "color_id") + val colorId: String? = null, ) { /** * This sealed class represents the different types of event time configurations. @@ -597,6 +604,7 @@ data class UpdateEventRequest( private var capacity: Int? = null private var hideParticipant: Boolean? = null private var notetaker: EventNotetakerRequest? = null + private var colorId: String? = null /** * Set the when object. @@ -719,6 +727,15 @@ data class UpdateEventRequest( */ fun notetaker(notetaker: EventNotetakerRequest) = apply { this.notetaker = notetaker } + /** + * Update the Google color ID for the event. Only supported by Google Calendar providers; ignored by other providers. + * Valid values are strings "1" through "11". + * @param colorId The Google color ID. + * @return The builder. + * @see Google Calendar Colors + */ + fun colorId(colorId: String) = apply { this.colorId = colorId } + /** * Builds the [UpdateEventRequest] object. * @return [UpdateEventRequest] object. @@ -741,6 +758,7 @@ data class UpdateEventRequest( capacity, hideParticipant, notetaker, + colorId, ) } } diff --git a/src/test/kotlin/com/nylas/resources/EventsTests.kt b/src/test/kotlin/com/nylas/resources/EventsTests.kt index 8778d122..8f6ffac5 100644 --- a/src/test/kotlin/com/nylas/resources/EventsTests.kt +++ b/src/test/kotlin/com/nylas/resources/EventsTests.kt @@ -15,7 +15,9 @@ import org.mockito.kotlin.* import java.lang.reflect.Type import kotlin.test.Test import kotlin.test.assertEquals +import kotlin.test.assertFalse import kotlin.test.assertIs +import kotlin.test.assertTrue class EventsTests { private val mockHttpClient: OkHttpClient = Mockito.mock(OkHttpClient::class.java) @@ -111,7 +113,8 @@ class EventsTests { "audio_recording": true, "transcription": true } - } + }, + "color_id": "7" } """.trimIndent(), ) @@ -171,6 +174,7 @@ class EventsTests { assertEquals(false, event.notetaker?.meetingSettings?.videoRecording) assertEquals(true, event.notetaker?.meetingSettings?.audioRecording) assertEquals(true, event.notetaker?.meetingSettings?.transcription) + assertEquals("7", event.colorId) } @Test @@ -439,6 +443,45 @@ class EventsTests { assertEquals("123456", details["pin"]) } + @Test + fun `CreateEventRequest with colorId serializes color_id field`() { + val adapter = JsonHelper.moshi().adapter(CreateEventRequest::class.java) + val request = CreateEventRequest( + whenObj = CreateEventRequest.When.Time(1620000000), + colorId = "7", + ) + + val jsonMap = JsonHelper.moshi().adapter(Map::class.java).fromJson(adapter.toJson(request))!! + assertEquals("7", jsonMap["color_id"]) + } + + @Test + fun `CreateEventRequest without colorId omits color_id from serialized JSON`() { + val adapter = JsonHelper.moshi().adapter(CreateEventRequest::class.java) + val request = CreateEventRequest(whenObj = CreateEventRequest.When.Time(1620000000)) + + val json = adapter.toJson(request) + assertFalse(json.contains("color_id")) + } + + @Test + fun `UpdateEventRequest with colorId serializes color_id field`() { + val adapter = JsonHelper.moshi().adapter(UpdateEventRequest::class.java) + val request = UpdateEventRequest(colorId = "11") + + val jsonMap = JsonHelper.moshi().adapter(Map::class.java).fromJson(adapter.toJson(request))!! + assertEquals("11", jsonMap["color_id"]) + } + + @Test + fun `UpdateEventRequest without colorId omits color_id from serialized JSON`() { + val adapter = JsonHelper.moshi().adapter(UpdateEventRequest::class.java) + val request = UpdateEventRequest(title = "Test") + + val json = adapter.toJson(request) + assertFalse(json.contains("color_id")) + } + @Test fun `Event with existing ConferencingProvider still works properly`() { // This test verifies that the original Event model continues to work with the original ConferencingProvider enum @@ -899,6 +942,7 @@ class EventsTests { transcription = true, ), ), + colorId = "7", ) val createEventQueryParams = CreateEventQueryParams( @@ -923,6 +967,7 @@ class EventsTests { assertEquals("v3/grants/$grantId/events", pathCaptor.firstValue) assertEquals(Types.newParameterizedType(Response::class.java, Event::class.java), typeCaptor.firstValue) assertEquals(adapter.toJson(createEventRequest), requestBodyCaptor.firstValue) + assertTrue(requestBodyCaptor.firstValue.contains("\"color_id\":\"7\"")) } @Test @@ -941,6 +986,7 @@ class EventsTests { transcription = true, ), ), + colorId = "11", ) val updateEventQueryParams = UpdateEventQueryParams( @@ -965,6 +1011,7 @@ class EventsTests { assertEquals("v3/grants/$grantId/events/$eventId", pathCaptor.firstValue) assertEquals(Types.newParameterizedType(Response::class.java, Event::class.java), typeCaptor.firstValue) assertEquals(adapter.toJson(updateEventRequest), requestBodyCaptor.firstValue) + assertTrue(requestBodyCaptor.firstValue.contains("\"color_id\":\"11\"")) } @Test