From de6b5932d6dc25579a0882fd3216b8f5b2bf0230 Mon Sep 17 00:00:00 2001 From: Blag Date: Wed, 3 Jan 2024 12:55:17 -0500 Subject: [PATCH] Fixes for contacts api support (#185) This PR add some fixed and contact creation. https://nylas.atlassian.net/browse/TW-2468 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. --- src/main/kotlin/com/nylas/NylasClient.kt | 8 ++++++++ src/main/kotlin/com/nylas/models/Contact.kt | 2 +- src/main/kotlin/com/nylas/models/ContactEmail.kt | 2 +- src/main/kotlin/com/nylas/models/ContactGroup.kt | 2 +- src/main/kotlin/com/nylas/models/ContactGroupId.kt | 2 +- src/main/kotlin/com/nylas/models/ContactType.kt | 5 ++++- .../com/nylas/models/FindContactQueryParams.kt | 2 +- src/main/kotlin/com/nylas/models/GroupType.kt | 6 ++++-- .../com/nylas/models/ListContactsQueryParams.kt | 4 ++-- src/main/kotlin/com/nylas/models/SourceType.kt | 6 ++++-- src/main/kotlin/com/nylas/resources/Contacts.kt | 14 ++++++++++++++ 11 files changed, 41 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/com/nylas/NylasClient.kt b/src/main/kotlin/com/nylas/NylasClient.kt index 048edc8b..d74ebef6 100644 --- a/src/main/kotlin/com/nylas/NylasClient.kt +++ b/src/main/kotlin/com/nylas/NylasClient.kt @@ -167,6 +167,14 @@ class NylasClient( return Webhooks(this) } + /** + * Access the Contacts API + * @return The Contacts API + */ + fun contacts(): Contacts { + return Contacts(this) + } + /** * Get a URL builder instance for the Nylas API. */ diff --git a/src/main/kotlin/com/nylas/models/Contact.kt b/src/main/kotlin/com/nylas/models/Contact.kt index 534d0537..5a80c4ab 100644 --- a/src/main/kotlin/com/nylas/models/Contact.kt +++ b/src/main/kotlin/com/nylas/models/Contact.kt @@ -56,4 +56,4 @@ data class Contact( val groups: List? = null, ) { fun getObject() = obj -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/nylas/models/ContactEmail.kt b/src/main/kotlin/com/nylas/models/ContactEmail.kt index 1f4cdf2c..1cf4188f 100644 --- a/src/main/kotlin/com/nylas/models/ContactEmail.kt +++ b/src/main/kotlin/com/nylas/models/ContactEmail.kt @@ -15,4 +15,4 @@ data class ContactEmail( fun type(type: ContactType) = apply { this.type = type } fun build() = ContactEmail(email, type) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/nylas/models/ContactGroup.kt b/src/main/kotlin/com/nylas/models/ContactGroup.kt index 664ab5f4..b4fc571d 100644 --- a/src/main/kotlin/com/nylas/models/ContactGroup.kt +++ b/src/main/kotlin/com/nylas/models/ContactGroup.kt @@ -12,4 +12,4 @@ data class ContactGroup( private val obj: String = "contact_group", ) { fun getObject() = obj -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/nylas/models/ContactGroupId.kt b/src/main/kotlin/com/nylas/models/ContactGroupId.kt index 7b770ae6..4db33a7a 100644 --- a/src/main/kotlin/com/nylas/models/ContactGroupId.kt +++ b/src/main/kotlin/com/nylas/models/ContactGroupId.kt @@ -5,4 +5,4 @@ package com.nylas.models */ data class ContactGroupId( val id: String, -) \ No newline at end of file +) diff --git a/src/main/kotlin/com/nylas/models/ContactType.kt b/src/main/kotlin/com/nylas/models/ContactType.kt index 2b816aa7..ea8abffa 100644 --- a/src/main/kotlin/com/nylas/models/ContactType.kt +++ b/src/main/kotlin/com/nylas/models/ContactType.kt @@ -11,4 +11,7 @@ enum class ContactType { @Json(name = "other") OTHER, -} \ No newline at end of file + + @Json(name = "mobile") + MOBILE, +} diff --git a/src/main/kotlin/com/nylas/models/FindContactQueryParams.kt b/src/main/kotlin/com/nylas/models/FindContactQueryParams.kt index 9fefb24a..9e5970fd 100644 --- a/src/main/kotlin/com/nylas/models/FindContactQueryParams.kt +++ b/src/main/kotlin/com/nylas/models/FindContactQueryParams.kt @@ -5,4 +5,4 @@ import com.squareup.moshi.Json data class FindContactQueryParams( @Json(name = "profile_picture") val profilePicture: Boolean? = null, -): IQueryParams +) : IQueryParams diff --git a/src/main/kotlin/com/nylas/models/GroupType.kt b/src/main/kotlin/com/nylas/models/GroupType.kt index 6900f2b2..8370db95 100644 --- a/src/main/kotlin/com/nylas/models/GroupType.kt +++ b/src/main/kotlin/com/nylas/models/GroupType.kt @@ -5,8 +5,10 @@ import com.squareup.moshi.Json enum class GroupType { @Json(name = "user") USER, + @Json(name = "system") SYSTEM, + @Json(name = "other") - OTHER -} \ No newline at end of file + OTHER, +} diff --git a/src/main/kotlin/com/nylas/models/ListContactsQueryParams.kt b/src/main/kotlin/com/nylas/models/ListContactsQueryParams.kt index 7b3406ad..ed832d44 100644 --- a/src/main/kotlin/com/nylas/models/ListContactsQueryParams.kt +++ b/src/main/kotlin/com/nylas/models/ListContactsQueryParams.kt @@ -44,7 +44,7 @@ data class ListContactsQueryParams( */ @Json(name = "recurse") val recurse: Boolean? = null, -): IQueryParams { +) : IQueryParams { class Builder { private var limit: Int? = null private var pageToken: String? = null @@ -120,4 +120,4 @@ data class ListContactsQueryParams( recurse = recurse, ) } -} \ No newline at end of file +} diff --git a/src/main/kotlin/com/nylas/models/SourceType.kt b/src/main/kotlin/com/nylas/models/SourceType.kt index 8d7f5887..b0f36468 100644 --- a/src/main/kotlin/com/nylas/models/SourceType.kt +++ b/src/main/kotlin/com/nylas/models/SourceType.kt @@ -5,8 +5,10 @@ import com.squareup.moshi.Json enum class SourceType { @Json(name = "address_book") ADDRESS_BOOK, + @Json(name = "inbox") INBOX, + @Json(name = "domain") - DOMAIN -} \ No newline at end of file + DOMAIN, +} diff --git a/src/main/kotlin/com/nylas/resources/Contacts.kt b/src/main/kotlin/com/nylas/resources/Contacts.kt index b2a82870..e5c7870f 100644 --- a/src/main/kotlin/com/nylas/resources/Contacts.kt +++ b/src/main/kotlin/com/nylas/resources/Contacts.kt @@ -33,6 +33,20 @@ class Contacts(client: NylasClient) : Resource(client, Contact::class.j return findResource(path) } + /** + * Create a Contact + * @param identifier Grant ID or email account in which to create the object + * @param requestBody The values to create the event with + * @return The created contact + */ + @Throws(NylasApiError::class, NylasSdkTimeoutError::class) + fun create(identifier: String, requestBody: CreateContactRequest): Response { + val path = String.format("v3/grants/%s/contacts", identifier) + val adapter = JsonHelper.moshi().adapter(CreateContactRequest::class.java) + val serializedRequestBody = adapter.toJson(requestBody) + return createResource(path, serializedRequestBody) + } + /** * Update a Contact * @param identifier The identifier of the grant to act upon