From 6d1a09e75155ebf632c7814552c7a85647336d24 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:47:38 +0400 Subject: [PATCH 1/7] Fix reminders model --- .../com/nylas/models/ReminderOverride.kt | 20 +++++++++++++++++++ src/main/kotlin/com/nylas/models/Reminders.kt | 15 +++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 src/main/kotlin/com/nylas/models/ReminderOverride.kt diff --git a/src/main/kotlin/com/nylas/models/ReminderOverride.kt b/src/main/kotlin/com/nylas/models/ReminderOverride.kt new file mode 100644 index 00000000..a8b98888 --- /dev/null +++ b/src/main/kotlin/com/nylas/models/ReminderOverride.kt @@ -0,0 +1,20 @@ +package com.nylas.models + +import com.squareup.moshi.Json + +/** + * Class representing the reminder details for an event. + */ +data class ReminderOverride( + /** + * The number of minutes before the event start time when a user wants a reminder for this event. + * Reminder minutes are in the following format: "[20]". + */ + @Json(name = "reminder_minutes") + val reminderMinutes: String? = null, + /** + * Method to remind the user about the event. (Google only). + */ + @Json(name = "reminder_method") + val reminderMethod: ReminderMethod? = null, +) diff --git a/src/main/kotlin/com/nylas/models/Reminders.kt b/src/main/kotlin/com/nylas/models/Reminders.kt index d43670c7..1a4e885e 100644 --- a/src/main/kotlin/com/nylas/models/Reminders.kt +++ b/src/main/kotlin/com/nylas/models/Reminders.kt @@ -7,15 +7,14 @@ import com.squareup.moshi.Json */ data class Reminders( /** - * The number of minutes before the event start time when a user wants a reminder for this event. - * Reminder minutes are in the following format: "[20]". + * Whether to use the default reminders for the calendar. + * When true, uses the default reminder settings for the calendar */ - @Json(name = "reminder_minutes") - val reminderMinutes: String? = null, - + @Json(name = "use_default") + val useDefault: Boolean, /** - * Method to remind the user about the event. (Google only). + * list of reminders for the event if useDefault is set to false. */ - @Json(name = "reminder_method") - val reminderMethod: ReminderMethod? = null, + @Json(name = "override") + val override: List? = null, ) From 65ceafa5f4b1afdf708e10090dbef2811040d6b9 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:55:44 +0400 Subject: [PATCH 2/7] fix reminders in create/update --- .../com/nylas/models/CreateEventRequest.kt | 67 ++++++--------- .../com/nylas/models/UpdateEventRequest.kt | 82 ++++++++++--------- 2 files changed, 68 insertions(+), 81 deletions(-) diff --git a/src/main/kotlin/com/nylas/models/CreateEventRequest.kt b/src/main/kotlin/com/nylas/models/CreateEventRequest.kt index 501be69f..0886461c 100644 --- a/src/main/kotlin/com/nylas/models/CreateEventRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateEventRequest.kt @@ -48,16 +48,10 @@ data class CreateEventRequest( @Json(name = "conferencing") val conferencing: Conferencing? = null, /** - * The number of minutes before the event start time when a user wants a reminder for this event. - * Reminder minutes need to be entered in the following format: "[20]". + * A list of reminders to send for the event. If left empty or omitted, the event uses the provider defaults. */ - @Json(name = "reminder_minutes") - val reminderMinutes: String? = null, - /** - * Method to remind the user about the event. (Google only). - */ - @Json(name = "reminder_method") - val reminderMethod: ReminderMethod? = null, + @Json(name = "reminders") + val reminders: Reminders? = null, /** * A list of key-value pairs storing additional data. */ @@ -96,7 +90,6 @@ data class CreateEventRequest( @Json(name = "hide_participant") val hideParticipant: Boolean? = null, ) { - /** * This sealed class represents the different types of event time configurations. */ @@ -430,8 +423,7 @@ data class CreateEventRequest( private var participants: List? = null private var busy: Boolean? = null private var conferencing: Conferencing? = null - private var reminderMinutes: String? = null - private var reminderMethod: ReminderMethod? = null + private var reminders: Reminders? = null private var metadata: Map? = null private var recurrence: List? = null private var calendarId: String? = null @@ -487,19 +479,12 @@ data class CreateEventRequest( fun conferencing(conferencing: Conferencing) = apply { this.conferencing = conferencing } /** - * Set the number of minutes before the event start time when a user wants a reminder for this event. - * Reminder minutes need to be entered in the following format: "[20]". - * @param reminderMinutes The number of minutes before the event start time when a user wants a reminder for this event. - * @return The builder. - */ - fun reminderMinutes(reminderMinutes: String) = apply { this.reminderMinutes = reminderMinutes } - - /** - * Set the method to remind the user about the event. (Google only). - * @param reminderMethod Method to remind the user about the event. + * Set the event reminders. + * A list of reminders to send for the event. If left empty or omitted, the event uses the provider defaults. + * @param reminders The event reminders. * @return The builder. */ - fun reminderMethod(reminderMethod: ReminderMethod) = apply { this.reminderMethod = reminderMethod } + fun reminders(reminders: Reminders) = apply { this.reminders = reminders } /** * Set the metadata, which is a key-value pair storing additional data. @@ -557,23 +542,23 @@ data class CreateEventRequest( * Builds the [CreateEventRequest] object. * @return [CreateEventRequest] object. */ - fun build() = CreateEventRequest( - whenObj, - title, - description, - location, - participants, - busy, - conferencing, - reminderMinutes, - reminderMethod, - metadata, - recurrence, - calendarId, - readOnly, - visibility, - capacity, - hideParticipant, - ) + fun build() = + CreateEventRequest( + whenObj, + title, + description, + location, + participants, + busy, + conferencing, + reminders, + metadata, + recurrence, + calendarId, + readOnly, + visibility, + capacity, + hideParticipant, + ) } } diff --git a/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt b/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt index dbb22e83..5b1cab29 100644 --- a/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt +++ b/src/main/kotlin/com/nylas/models/UpdateEventRequest.kt @@ -48,16 +48,10 @@ data class UpdateEventRequest( @Json(name = "conferencing") val conferencing: Conferencing? = null, /** - * The number of minutes before the event start time when a user wants a reminder for this event. - * Reminder minutes need to be entered in the following format: "[20]". + * A list of reminders to send for the event. If left empty or omitted, the event uses the provider defaults. */ - @Json(name = "reminder_minutes") - val reminderMinutes: String? = null, - /** - * Method to remind the user about the event. (Google only). - */ - @Json(name = "reminder_method") - val reminderMethod: ReminderMethod? = null, + @Json(name = "reminders") + val reminders: Reminders? = null, /** * A list of key-value pairs storing additional data. */ @@ -96,7 +90,6 @@ data class UpdateEventRequest( @Json(name = "hide_participant") val hideParticipant: Boolean? = null, ) { - /** * This sealed class represents the different types of event time configurations. */ @@ -502,6 +495,23 @@ data class UpdateEventRequest( } } + /** + * Class representing the reminders field of an event. + */ + data class Reminders( + /** + * Whether to use the default reminders for the calendar. + * When true, uses the default reminder settings for the calendar + */ + @Json(name = "use_default") + val useDefault: Boolean? = null, + /** + * A list of reminders for the event if useDefault is set to false. + */ + @Json(name = "override") + val override: List? = null, + ) + /** * Builder for [UpdateEventRequest]. */ @@ -513,8 +523,7 @@ data class UpdateEventRequest( private var participants: List? = null private var busy: Boolean? = null private var conferencing: Conferencing? = null - private var reminderMinutes: String? = null - private var reminderMethod: ReminderMethod? = null + private var reminders: Reminders? = null private var metadata: Map? = null private var recurrence: List? = null private var calendarId: String? = null @@ -581,18 +590,11 @@ data class UpdateEventRequest( fun conferencing(conferencing: Conferencing) = apply { this.conferencing = conferencing } /** - * Update the reminder minutes of the event. - * @param reminderMinutes The number of minutes before the event start time when a user wants a reminder for this event. - * @return The builder. - */ - fun reminderMinutes(reminderMinutes: String) = apply { this.reminderMinutes = reminderMinutes } - - /** - * Update the reminder method of the event. - * @param reminderMethod Method to remind the user about the event. (Google only). + * Update the reminders of the event. + * @param reminders A list of reminders to send for the event. If left empty or omitted, the event uses the provider defaults. * @return The builder. */ - fun reminderMethod(reminderMethod: ReminderMethod) = apply { this.reminderMethod = reminderMethod } + fun reminders(reminders: Reminders) = apply { this.reminders = reminders } /** * Update the metadata of the event. @@ -648,23 +650,23 @@ data class UpdateEventRequest( * Builds the [UpdateEventRequest] object. * @return [UpdateEventRequest] object. */ - fun build() = UpdateEventRequest( - whenObj, - title, - description, - location, - participants, - busy, - conferencing, - reminderMinutes, - reminderMethod, - metadata, - recurrence, - calendarId, - readOnly, - visibility, - capacity, - hideParticipant, - ) + fun build() = + UpdateEventRequest( + whenObj, + title, + description, + location, + participants, + busy, + conferencing, + reminders, + metadata, + recurrence, + calendarId, + readOnly, + visibility, + capacity, + hideParticipant, + ) } } From 2507b29ac67da816e85f02e7d4d8640f1c74c595 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 1 Feb 2024 22:55:55 +0400 Subject: [PATCH 3/7] fix event visibility --- src/main/kotlin/com/nylas/models/CreateEventRequest.kt | 2 +- src/main/kotlin/com/nylas/models/Event.kt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/nylas/models/CreateEventRequest.kt b/src/main/kotlin/com/nylas/models/CreateEventRequest.kt index 0886461c..30e248b9 100644 --- a/src/main/kotlin/com/nylas/models/CreateEventRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateEventRequest.kt @@ -428,7 +428,7 @@ data class CreateEventRequest( private var recurrence: List? = null private var calendarId: String? = null private var readOnly: Boolean? = null - private var visibility: EventVisibility? = EventVisibility.PUBLIC + private var visibility: EventVisibility? = null private var capacity: Int? = null private var hideParticipant: Boolean? = null diff --git a/src/main/kotlin/com/nylas/models/Event.kt b/src/main/kotlin/com/nylas/models/Event.kt index 32ca04d9..7fa5b07e 100644 --- a/src/main/kotlin/com/nylas/models/Event.kt +++ b/src/main/kotlin/com/nylas/models/Event.kt @@ -55,6 +55,11 @@ data class Event( */ @Json(name = "read_only") val readOnly: Boolean = false, + /** + * Visibility of the event, if the event is private or public. + */ + @Json(name = "visibility") + val visibility: EventVisibility = EventVisibility.DEFAULT, /** * Unix timestamp when the event was created. */ @@ -119,11 +124,6 @@ data class Event( */ @Json(name = "title") val title: String? = null, - /** - * Visibility of the event, if the event is private or public. - */ - @Json(name = "visibility") - val visibility: EventVisibility? = null, /** * User who created the event. * Not supported for all providers. From 6de701d0af4b46962be1aa1a4acc5eecdc9a6c78 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:01:46 +0400 Subject: [PATCH 4/7] AV-3202 Remove contact type enum --- .../kotlin/com/nylas/models/ContactEmail.kt | 8 +++-- .../kotlin/com/nylas/models/ContactType.kt | 17 ---------- .../nylas/models/InstantMessagingAddress.kt | 8 +++-- .../kotlin/com/nylas/models/PhoneNumber.kt | 8 +++-- .../com/nylas/models/PhysicalAddress.kt | 33 +++++++++++-------- src/main/kotlin/com/nylas/models/WebPage.kt | 8 +++-- .../com/nylas/resources/ContactsTests.kt | 30 ++++++++--------- 7 files changed, 55 insertions(+), 57 deletions(-) delete mode 100644 src/main/kotlin/com/nylas/models/ContactType.kt diff --git a/src/main/kotlin/com/nylas/models/ContactEmail.kt b/src/main/kotlin/com/nylas/models/ContactEmail.kt index 6106ac01..69943a2e 100644 --- a/src/main/kotlin/com/nylas/models/ContactEmail.kt +++ b/src/main/kotlin/com/nylas/models/ContactEmail.kt @@ -9,14 +9,16 @@ data class ContactEmail( @Json(name = "email") val email: String? = null, @Json(name = "type") - val type: ContactType? = null, + val type: String? = null, ) { class Builder { private var email: String? = null - private var type: ContactType? = null + private var type: String? = null fun email(email: String) = apply { this.email = email } - fun type(type: ContactType) = apply { this.type = type } + + fun type(type: String) = apply { this.type = type } + fun build() = ContactEmail(email, type) } } diff --git a/src/main/kotlin/com/nylas/models/ContactType.kt b/src/main/kotlin/com/nylas/models/ContactType.kt deleted file mode 100644 index ea8abffa..00000000 --- a/src/main/kotlin/com/nylas/models/ContactType.kt +++ /dev/null @@ -1,17 +0,0 @@ -package com.nylas.models - -import com.squareup.moshi.Json - -enum class ContactType { - @Json(name = "work") - WORK, - - @Json(name = "home") - HOME, - - @Json(name = "other") - OTHER, - - @Json(name = "mobile") - MOBILE, -} diff --git a/src/main/kotlin/com/nylas/models/InstantMessagingAddress.kt b/src/main/kotlin/com/nylas/models/InstantMessagingAddress.kt index f05d9711..7afba80e 100644 --- a/src/main/kotlin/com/nylas/models/InstantMessagingAddress.kt +++ b/src/main/kotlin/com/nylas/models/InstantMessagingAddress.kt @@ -9,14 +9,16 @@ data class InstantMessagingAddress( @Json(name = "im_address") val imAddress: String? = null, @Json(name = "type") - val type: ContactType? = null, + val type: String? = null, ) { class Builder { private var imAddress: String? = null - private var type: ContactType? = null + private var type: String? = null fun imAddress(imAddress: String) = apply { this.imAddress = imAddress } - fun type(type: ContactType) = apply { this.type = type } + + fun type(type: String) = apply { this.type = type } + fun build() = InstantMessagingAddress(imAddress, type) } } diff --git a/src/main/kotlin/com/nylas/models/PhoneNumber.kt b/src/main/kotlin/com/nylas/models/PhoneNumber.kt index 845dc7a4..00f91309 100644 --- a/src/main/kotlin/com/nylas/models/PhoneNumber.kt +++ b/src/main/kotlin/com/nylas/models/PhoneNumber.kt @@ -9,14 +9,16 @@ data class PhoneNumber( @Json(name = "number") val number: String? = null, @Json(name = "type") - val type: ContactType? = null, + val type: String? = null, ) { class Builder { private var number: String? = null - private var type: ContactType? = null + private var type: String? = null fun number(number: String) = apply { this.number = number } - fun type(type: ContactType) = apply { this.type = type } + + fun type(type: String) = apply { this.type = type } + fun build() = PhoneNumber(number, type) } } diff --git a/src/main/kotlin/com/nylas/models/PhysicalAddress.kt b/src/main/kotlin/com/nylas/models/PhysicalAddress.kt index 891f017b..9e8f76e1 100644 --- a/src/main/kotlin/com/nylas/models/PhysicalAddress.kt +++ b/src/main/kotlin/com/nylas/models/PhysicalAddress.kt @@ -19,7 +19,7 @@ data class PhysicalAddress( @Json(name = "country") val country: String? = null, @Json(name = "type") - val type: ContactType? = null, + val type: String? = null, ) { class Builder { private var format: String? = null @@ -28,24 +28,31 @@ data class PhysicalAddress( private var postalCode: String? = null private var state: String? = null private var country: String? = null - private var type: ContactType? = null + private var type: String? = null fun format(format: String) = apply { this.format = format } + fun streetAddress(streetAddress: String) = apply { this.streetAddress = streetAddress } + fun city(city: String) = apply { this.city = city } + fun postalCode(postalCode: String) = apply { this.postalCode = postalCode } + fun state(state: String) = apply { this.state = state } + fun country(country: String) = apply { this.country = country } - fun type(type: ContactType) = apply { this.type = type } - - fun build() = PhysicalAddress( - format = format, - streetAddress = streetAddress, - city = city, - postalCode = postalCode, - state = state, - country = country, - type = type, - ) + + fun type(type: String) = apply { this.type = type } + + fun build() = + PhysicalAddress( + format = format, + streetAddress = streetAddress, + city = city, + postalCode = postalCode, + state = state, + country = country, + type = type, + ) } } diff --git a/src/main/kotlin/com/nylas/models/WebPage.kt b/src/main/kotlin/com/nylas/models/WebPage.kt index e8e997f4..d641726e 100644 --- a/src/main/kotlin/com/nylas/models/WebPage.kt +++ b/src/main/kotlin/com/nylas/models/WebPage.kt @@ -9,14 +9,16 @@ data class WebPage( @Json(name = "url") val url: String? = null, @Json(name = "type") - val type: ContactType? = null, + val type: String? = null, ) { class Builder { private var url: String? = null - private var type: ContactType? = null + private var type: String? = null fun url(url: String) = apply { this.url = url } - fun type(type: ContactType) = apply { this.type = type } + + fun type(type: String) = apply { this.type = type } + fun build() = WebPage(url, type) } } diff --git a/src/test/kotlin/com/nylas/resources/ContactsTests.kt b/src/test/kotlin/com/nylas/resources/ContactsTests.kt index 54460c67..0cc2b4fa 100644 --- a/src/test/kotlin/com/nylas/resources/ContactsTests.kt +++ b/src/test/kotlin/com/nylas/resources/ContactsTests.kt @@ -122,7 +122,7 @@ class ContactsTests { assertEquals( listOf( ContactEmail( - type = ContactType.WORK, + type = "work", email = "john-work@example.com", ), ), @@ -139,7 +139,7 @@ class ContactsTests { assertEquals( listOf( InstantMessagingAddress( - type = ContactType.OTHER, + type = "other", imAddress = "myjabberaddress", ), ), @@ -148,7 +148,7 @@ class ContactsTests { assertEquals( listOf( PhoneNumber( - type = ContactType.WORK, + type = "work", number = "+1-555-555-5555", ), ), @@ -157,7 +157,7 @@ class ContactsTests { assertEquals( listOf( WebPage( - type = ContactType.WORK, + type = "work", url = "http://www.linkedin.com/in/johndoe", ), ), @@ -166,7 +166,7 @@ class ContactsTests { assertEquals( listOf( PhysicalAddress( - type = ContactType.WORK, + type = "work", streetAddress = "123 Main Street", postalCode = "94107", state = "CA", @@ -284,7 +284,7 @@ class ContactsTests { companyName = "Nylas", emails = listOf( ContactEmail( - type = ContactType.WORK, + type = "work", email = "test@gmail.com", ), ), @@ -296,7 +296,7 @@ class ContactsTests { ), imAddresses = listOf( InstantMessagingAddress( - type = ContactType.OTHER, + type = "other", imAddress = "myjabberaddress", ), ), @@ -308,13 +308,13 @@ class ContactsTests { officeLocation = "123 Main Street", phoneNumbers = listOf( PhoneNumber( - type = ContactType.WORK, + type = "work", number = "+1-555-555-5555", ), ), physicalAddresses = listOf( PhysicalAddress( - type = ContactType.WORK, + type = "work", streetAddress = "123 Main Street", postalCode = "94107", state = "CA", @@ -326,7 +326,7 @@ class ContactsTests { surname = "Doe", webPages = listOf( WebPage( - type = ContactType.WORK, + type = "work", url = "http://www.linkedin.com/in/johndoe", ), ), @@ -358,7 +358,7 @@ class ContactsTests { companyName = "Nylas", emails = listOf( ContactEmail( - type = ContactType.WORK, + type = "work", email = "test@gmail.com", ), ), @@ -370,7 +370,7 @@ class ContactsTests { ), imAddresses = listOf( InstantMessagingAddress( - type = ContactType.OTHER, + type = "other", imAddress = "myjabberaddress", ), ), @@ -382,13 +382,13 @@ class ContactsTests { officeLocation = "123 Main Street", phoneNumbers = listOf( PhoneNumber( - type = ContactType.WORK, + type = "work", number = "+1-555-555-5555", ), ), physicalAddresses = listOf( PhysicalAddress( - type = ContactType.WORK, + type = "work", streetAddress = "123 Main Street", postalCode = "94107", state = "CA", @@ -400,7 +400,7 @@ class ContactsTests { surname = "Doe", webPages = listOf( WebPage( - type = ContactType.WORK, + type = "work", url = "http://www.linkedin.com/in/johndoe", ), ), From 10dddb32dfb058de57f78d07fa3ebad3504d3cf4 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:03:17 +0400 Subject: [PATCH 5/7] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98fef65e..f8a907ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,10 +7,12 @@ ### Changed * Changed `clientSecret` to optional for token exchange methods; defaults to API Key now +* Updated `reminder` field to reflect the new API schema * Fixed various issues with the connector API * Fixed response type for smart compose methods * Fixed inaccuracies with webhook related models * Fixed models for creating drafts and sending messages +* Removed `ContactType` enum as the field allows for any string value ## [2.0.0-beta.4] - Released 2024-01-09 From 0d6f32139aa0177baca33b4170941c17a16f8057 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Thu, 1 Feb 2024 23:12:29 +0400 Subject: [PATCH 6/7] minor fixes for reminders --- .../com/nylas/models/ReminderOverride.kt | 2 +- src/main/kotlin/com/nylas/models/Reminders.kt | 4 +- .../kotlin/com/nylas/resources/EventsTests.kt | 106 ++++++++++-------- 3 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/main/kotlin/com/nylas/models/ReminderOverride.kt b/src/main/kotlin/com/nylas/models/ReminderOverride.kt index a8b98888..053e5950 100644 --- a/src/main/kotlin/com/nylas/models/ReminderOverride.kt +++ b/src/main/kotlin/com/nylas/models/ReminderOverride.kt @@ -11,7 +11,7 @@ data class ReminderOverride( * Reminder minutes are in the following format: "[20]". */ @Json(name = "reminder_minutes") - val reminderMinutes: String? = null, + val reminderMinutes: Int? = null, /** * Method to remind the user about the event. (Google only). */ diff --git a/src/main/kotlin/com/nylas/models/Reminders.kt b/src/main/kotlin/com/nylas/models/Reminders.kt index 1a4e885e..c18bde03 100644 --- a/src/main/kotlin/com/nylas/models/Reminders.kt +++ b/src/main/kotlin/com/nylas/models/Reminders.kt @@ -15,6 +15,6 @@ data class Reminders( /** * list of reminders for the event if useDefault is set to false. */ - @Json(name = "override") - val override: List? = null, + @Json(name = "overrides") + val overrides: List? = null, ) diff --git a/src/test/kotlin/com/nylas/resources/EventsTests.kt b/src/test/kotlin/com/nylas/resources/EventsTests.kt index 92b130bd..7788d073 100644 --- a/src/test/kotlin/com/nylas/resources/EventsTests.kt +++ b/src/test/kotlin/com/nylas/resources/EventsTests.kt @@ -40,8 +40,9 @@ class EventsTests { @Test fun `Event serializes properly`() { val adapter = JsonHelper.moshi().adapter(Event::class.java) - val jsonBuffer = Buffer().writeUtf8( - """ + val jsonBuffer = + Buffer().writeUtf8( + """ { "busy": true, "calendar_id": "7d93zl2palhxqdy6e5qinsakt", @@ -103,8 +104,8 @@ class EventsTests { "object": "timespan" } } - """.trimIndent(), - ) + """.trimIndent(), + ) val event = adapter.fromJson(jsonBuffer)!! assertIs(event) @@ -120,7 +121,10 @@ class EventsTests { assertEquals("Description of my new calendar", event.description) assertEquals(false, event.hideParticipants) assertEquals("41009df5-bf11-4c97-aa18-b285b5f2e386", event.grantId) - assertEquals("https://www.google.com/calendar/event?eid=bTMzcGJrNW4yYjk4bjk3OWE4Ef3feD2VuM29fMjAyMjA2MjdUMjIwMDAwWiBoYWxsYUBueWxhcy5jb20", event.htmlLink) + assertEquals( + "https://www.google.com/calendar/event?eid=bTMzcGJrNW4yYjk4bjk3OWE4Ef3feD2VuM29fMjAyMjA2MjdUMjIwMDAwWiBoYWxsYUBueWxhcy5jb20", + event.htmlLink, + ) assertEquals("5d3qmne77v32r8l4phyuksl2x", event.id) assertEquals("Roller Rink", event.location) assertEquals(mapOf("your_key" to "your_value"), event.metadata) @@ -134,6 +138,10 @@ class EventsTests { assertEquals("+1 23456778", event.participants[0].phoneNumber) assertEquals(ParticipantStatus.MAYBE, event.participants[0].status) assertEquals(false, event.readOnly) + assertEquals(false, event.reminders?.useDefault) + assertEquals(1, event.reminders?.overrides?.size) + assertEquals(10, event.reminders?.overrides?.get(0)?.reminderMinutes) + assertEquals(ReminderMethod.EMAIL, event.reminders?.overrides?.get(0)?.reminderMethod) assertEquals(2, event.recurrence?.size) assertEquals("RRULE:FREQ=WEEKLY;BYDAY=MO", event.recurrence?.get(0)) assertEquals("EXDATE:20211011T000000Z", event.recurrence?.get(1)) @@ -165,9 +173,10 @@ class EventsTests { @Test fun `listing events calls requests with the correct params`() { - val listEventQueryParams = ListEventQueryParams( - calendarId = "calendar-id", - ) + val listEventQueryParams = + ListEventQueryParams( + calendarId = "calendar-id", + ) events.list(grantId, listEventQueryParams) @@ -187,9 +196,10 @@ class EventsTests { @Test fun `finding a event calls requests with the correct params`() { val eventId = "event-123" - val findEventQueryParams = FindEventQueryParams( - calendarId = "calendar-id", - ) + val findEventQueryParams = + FindEventQueryParams( + calendarId = "calendar-id", + ) events.find(grantId, eventId, findEventQueryParams) @@ -209,21 +219,24 @@ class EventsTests { @Test fun `creating a event calls requests with the correct params`() { val adapter = JsonHelper.moshi().adapter(CreateEventRequest::class.java) - val createEventRequest = CreateEventRequest( - whenObj = CreateEventRequest.When.Timespan( - startTime = 1620000000, - endTime = 1620000000, - startTimezone = "America/Los_Angeles", - endTimezone = "America/Los_Angeles", - ), - description = "Description of my new event", - location = "Los Angeles, CA", - metadata = mapOf("your-key" to "value"), - ) - val createEventQueryParams = CreateEventQueryParams( - calendarId = "calendar-id", - notifyParticipants = true, - ) + val createEventRequest = + CreateEventRequest( + whenObj = + CreateEventRequest.When.Timespan( + startTime = 1620000000, + endTime = 1620000000, + startTimezone = "America/Los_Angeles", + endTimezone = "America/Los_Angeles", + ), + description = "Description of my new event", + location = "Los Angeles, CA", + metadata = mapOf("your-key" to "value"), + ) + val createEventQueryParams = + CreateEventQueryParams( + calendarId = "calendar-id", + notifyParticipants = true, + ) events.create(grantId, createEventRequest, createEventQueryParams) val pathCaptor = argumentCaptor() @@ -246,14 +259,16 @@ class EventsTests { fun `updating a event calls requests with the correct params`() { val eventId = "event-123" val adapter = JsonHelper.moshi().adapter(UpdateEventRequest::class.java) - val updateEventRequest = UpdateEventRequest( - description = "Description of my new event", - location = "Los Angeles, CA", - ) - val updateEventQueryParams = UpdateEventQueryParams( - calendarId = "calendar-id", - notifyParticipants = true, - ) + val updateEventRequest = + UpdateEventRequest( + description = "Description of my new event", + location = "Los Angeles, CA", + ) + val updateEventQueryParams = + UpdateEventQueryParams( + calendarId = "calendar-id", + notifyParticipants = true, + ) events.update(grantId, eventId, updateEventRequest, updateEventQueryParams) val pathCaptor = argumentCaptor() @@ -275,10 +290,11 @@ class EventsTests { @Test fun `destroying a event calls requests with the correct params`() { val eventId = "event-123" - val destroyEventQueryParams = DestroyEventQueryParams( - calendarId = "calendar-id", - notifyParticipants = true, - ) + val destroyEventQueryParams = + DestroyEventQueryParams( + calendarId = "calendar-id", + notifyParticipants = true, + ) events.destroy(grantId, eventId, destroyEventQueryParams) val pathCaptor = argumentCaptor() @@ -312,12 +328,14 @@ class EventsTests { fun `sending RSVP calls requests with the correct params`() { val eventId = "event-123" val adapter = JsonHelper.moshi().adapter(SendRsvpRequest::class.java) - val sendRsvpRequest = SendRsvpRequest( - status = RsvpStatus.YES, - ) - val sendRsvpQueryParams = SendRsvpQueryParams( - calendarId = "calendar-id", - ) + val sendRsvpRequest = + SendRsvpRequest( + status = RsvpStatus.YES, + ) + val sendRsvpQueryParams = + SendRsvpQueryParams( + calendarId = "calendar-id", + ) events.sendRsvp(grantId, eventId, sendRsvpRequest, sendRsvpQueryParams) val pathCaptor = argumentCaptor() From eb618be4b62d357e778f4eb094f43d773c298514 Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Mon, 5 Feb 2024 13:02:53 +0400 Subject: [PATCH 7/7] linting --- .editorconfig | 1 + .../com/nylas/interceptors/HttpLoggingInterceptor.kt | 7 +++++-- src/main/kotlin/com/nylas/models/Connector.kt | 11 ++++++----- .../com/nylas/models/CreateConnectorRequest.kt | 11 ++++++----- .../com/nylas/models/CreateCredentialRequest.kt | 9 +++++---- .../kotlin/com/nylas/models/CreateWebhookRequest.kt | 4 +++- .../kotlin/com/nylas/models/UpdateWebhookRequest.kt | 4 +++- src/test/kotlin/com/nylas/resources/EventsTests.kt | 12 ++++++------ 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/.editorconfig b/.editorconfig index 28404d8b..82cefe7b 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,7 @@ root = true [*.{kt,kts}] +ktlint_code_style = intellij_idea indent_size = 2 indent_style = space ktlint_standard_no-wildcard-imports = disabled diff --git a/src/main/kotlin/com/nylas/interceptors/HttpLoggingInterceptor.kt b/src/main/kotlin/com/nylas/interceptors/HttpLoggingInterceptor.kt index aa0cb0dc..91ae0432 100644 --- a/src/main/kotlin/com/nylas/interceptors/HttpLoggingInterceptor.kt +++ b/src/main/kotlin/com/nylas/interceptors/HttpLoggingInterceptor.kt @@ -145,10 +145,13 @@ class HttpLoggingInterceptor : Interceptor { (truncated ${buf.size} byte body after $bytesToLog bytes)""" } val charset = contentType!!.charset(StandardCharsets.UTF_8) - return """ + val str = + """ $prefix ${buf.readString(bytesToLog, charset!!)}$truncationMessage - """.trimIndent() + """.trimIndent() + + return str } private fun getContentLength(response: Response?): Long { diff --git a/src/main/kotlin/com/nylas/models/Connector.kt b/src/main/kotlin/com/nylas/models/Connector.kt index 20ee20d0..62eb9060 100644 --- a/src/main/kotlin/com/nylas/models/Connector.kt +++ b/src/main/kotlin/com/nylas/models/Connector.kt @@ -57,10 +57,11 @@ sealed class Connector( companion object { @JvmStatic - val CONNECTOR_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory = PolymorphicJsonAdapterFactory.of(Connector::class.java, "provider") - .withSubtype(Google::class.java, AuthProvider.GOOGLE.value) - .withSubtype(Microsoft::class.java, AuthProvider.MICROSOFT.value) - .withSubtype(Imap::class.java, AuthProvider.IMAP.value) - .withSubtype(VirtualCalendar::class.java, AuthProvider.VIRTUAL_CALENDAR.value) + val CONNECTOR_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory = + PolymorphicJsonAdapterFactory.of(Connector::class.java, "provider") + .withSubtype(Google::class.java, AuthProvider.GOOGLE.value) + .withSubtype(Microsoft::class.java, AuthProvider.MICROSOFT.value) + .withSubtype(Imap::class.java, AuthProvider.IMAP.value) + .withSubtype(VirtualCalendar::class.java, AuthProvider.VIRTUAL_CALENDAR.value) } } diff --git a/src/main/kotlin/com/nylas/models/CreateConnectorRequest.kt b/src/main/kotlin/com/nylas/models/CreateConnectorRequest.kt index 5a4eb416..7e86c881 100644 --- a/src/main/kotlin/com/nylas/models/CreateConnectorRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateConnectorRequest.kt @@ -103,10 +103,11 @@ sealed class CreateConnectorRequest( companion object { @JvmStatic - val CREATE_CONNECTOR_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory = PolymorphicJsonAdapterFactory.of(CreateConnectorRequest::class.java, "provider") - .withSubtype(Google::class.java, AuthProvider.GOOGLE.value) - .withSubtype(Microsoft::class.java, AuthProvider.MICROSOFT.value) - .withSubtype(Imap::class.java, AuthProvider.IMAP.value) - .withSubtype(VirtualCalendar::class.java, AuthProvider.VIRTUAL_CALENDAR.value) + val CREATE_CONNECTOR_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory = + PolymorphicJsonAdapterFactory.of(CreateConnectorRequest::class.java, "provider") + .withSubtype(Google::class.java, AuthProvider.GOOGLE.value) + .withSubtype(Microsoft::class.java, AuthProvider.MICROSOFT.value) + .withSubtype(Imap::class.java, AuthProvider.IMAP.value) + .withSubtype(VirtualCalendar::class.java, AuthProvider.VIRTUAL_CALENDAR.value) } } diff --git a/src/main/kotlin/com/nylas/models/CreateCredentialRequest.kt b/src/main/kotlin/com/nylas/models/CreateCredentialRequest.kt index 4dc0727a..946bf777 100644 --- a/src/main/kotlin/com/nylas/models/CreateCredentialRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateCredentialRequest.kt @@ -73,9 +73,10 @@ sealed class CreateCredentialRequest( companion object { @JvmStatic - val CREATE_CREDENTIAL_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory = PolymorphicJsonAdapterFactory.of(CreateCredentialRequest::class.java, "credential_type") - .withSubtype(Microsoft::class.java, CredentialType.ADMINCONSENT.value) - .withSubtype(Google::class.java, CredentialType.SERVICEACCOUNT.value) - .withSubtype(Override::class.java, CredentialType.CONNECTOR.value) + val CREATE_CREDENTIAL_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory = + PolymorphicJsonAdapterFactory.of(CreateCredentialRequest::class.java, "credential_type") + .withSubtype(Microsoft::class.java, CredentialType.ADMINCONSENT.value) + .withSubtype(Google::class.java, CredentialType.SERVICEACCOUNT.value) + .withSubtype(Override::class.java, CredentialType.CONNECTOR.value) } } diff --git a/src/main/kotlin/com/nylas/models/CreateWebhookRequest.kt b/src/main/kotlin/com/nylas/models/CreateWebhookRequest.kt index 77566cba..3f35cabf 100644 --- a/src/main/kotlin/com/nylas/models/CreateWebhookRequest.kt +++ b/src/main/kotlin/com/nylas/models/CreateWebhookRequest.kt @@ -51,7 +51,9 @@ data class CreateWebhookRequest( * @param notificationEmailAddresses The email addresses that Nylas notifies when a webhook is down for a while. * @return The builder. */ - fun notificationEmailAddresses(notificationEmailAddresses: List?) = apply { this.notificationEmailAddresses = notificationEmailAddresses } + fun notificationEmailAddresses(notificationEmailAddresses: List?) = apply { + this.notificationEmailAddresses = notificationEmailAddresses + } /** * Build the [CreateWebhookRequest]. diff --git a/src/main/kotlin/com/nylas/models/UpdateWebhookRequest.kt b/src/main/kotlin/com/nylas/models/UpdateWebhookRequest.kt index fbbc16ff..bf9ffdd3 100644 --- a/src/main/kotlin/com/nylas/models/UpdateWebhookRequest.kt +++ b/src/main/kotlin/com/nylas/models/UpdateWebhookRequest.kt @@ -62,7 +62,9 @@ data class UpdateWebhookRequest( * @param notificationEmailAddresses The email addresses that Nylas notifies when a webhook is down for a while. * @return The builder. */ - fun notificationEmailAddresses(notificationEmailAddresses: List?) = apply { this.notificationEmailAddresses = notificationEmailAddresses } + fun notificationEmailAddresses(notificationEmailAddresses: List?) = apply { + this.notificationEmailAddresses = notificationEmailAddresses + } /** * Build the [UpdateWebhookRequest]. diff --git a/src/test/kotlin/com/nylas/resources/EventsTests.kt b/src/test/kotlin/com/nylas/resources/EventsTests.kt index 7788d073..506dfc34 100644 --- a/src/test/kotlin/com/nylas/resources/EventsTests.kt +++ b/src/test/kotlin/com/nylas/resources/EventsTests.kt @@ -222,12 +222,12 @@ class EventsTests { val createEventRequest = CreateEventRequest( whenObj = - CreateEventRequest.When.Timespan( - startTime = 1620000000, - endTime = 1620000000, - startTimezone = "America/Los_Angeles", - endTimezone = "America/Los_Angeles", - ), + CreateEventRequest.When.Timespan( + startTime = 1620000000, + endTime = 1620000000, + startTimezone = "America/Los_Angeles", + endTimezone = "America/Los_Angeles", + ), description = "Description of my new event", location = "Los Angeles, CA", metadata = mapOf("your-key" to "value"),