From db64b95fda4c8af777f3679de0eb9e91a5ea0f0a Mon Sep 17 00:00:00 2001 From: Mostafa Rashed <17770919+mrashed-dev@users.noreply.github.com> Date: Wed, 27 Dec 2023 10:58:49 -0500 Subject: [PATCH] Move `Grants` to `NylasClient` and custom authentication to `Auth` (#182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Description ⚠️ This is a breaking change ⚠️ This PR moves the following: * `Auth.grants()` to `NylasClient.grants()` * `Grants.create()` to `Auth.customAuthentication()` Functionality remains the same. # 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. --- CHANGELOG.md | 4 +++ src/main/kotlin/com/nylas/NylasClient.kt | 8 ++++++ src/main/kotlin/com/nylas/resources/Auth.kt | 25 ++++++++++++------- src/main/kotlin/com/nylas/resources/Grants.kt | 15 ----------- 4 files changed, 28 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6afad296..6294a7d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [2.0.0-beta.4] - TBD +### BREAKING CHANGES +* Moved grants API out of `Auth` to `NylasClient` +* Moved `Grants.create()` to `Auth.customAuthentication()` + ### Added * Added support for sending drafts diff --git a/src/main/kotlin/com/nylas/NylasClient.kt b/src/main/kotlin/com/nylas/NylasClient.kt index 46ccfc7e..048edc8b 100644 --- a/src/main/kotlin/com/nylas/NylasClient.kt +++ b/src/main/kotlin/com/nylas/NylasClient.kt @@ -135,6 +135,14 @@ class NylasClient( return Folders(this) } + /** + * Access the Grants API + * @return The Grants API + */ + fun grants(): Grants { + return Grants(this) + } + /** * Access the Messages API * @return The Messages API diff --git a/src/main/kotlin/com/nylas/resources/Auth.kt b/src/main/kotlin/com/nylas/resources/Auth.kt index e917ba11..a224b430 100644 --- a/src/main/kotlin/com/nylas/resources/Auth.kt +++ b/src/main/kotlin/com/nylas/resources/Auth.kt @@ -17,15 +17,6 @@ import java.util.* * @param client The configured Nylas API client */ class Auth(private val client: NylasClient) { - - /** - * Access the Grants API - * @return The Grants API - */ - fun grants(): Grants { - return Grants(client) - } - /** * Build the URL for authenticating users to your application with OAuth 2.0 * @param config The configuration for building the URL @@ -94,6 +85,22 @@ class Auth(private val client: NylasClient) { return urlBuilder.build().toString() } + /** + * Create a grant via custom authentication + * @param requestBody The values to create the grant with + * @return The created grant + */ + @Throws(NylasApiError::class, NylasSdkTimeoutError::class) + fun customAuthentication(requestBody: CreateGrantRequest): Response { + val path = "v3/connect/custom" + val serializedRequestBody = JsonHelper.moshi() + .adapter(CreateGrantRequest::class.java) + .toJson(requestBody) + val responseType = Types.newParameterizedType(Response::class.java, Grant::class.java) + + return client.executePost(path, responseType, serializedRequestBody) + } + /** * Refresh an access token * @param request The refresh token request diff --git a/src/main/kotlin/com/nylas/resources/Grants.kt b/src/main/kotlin/com/nylas/resources/Grants.kt index c496f7fc..f520fa42 100644 --- a/src/main/kotlin/com/nylas/resources/Grants.kt +++ b/src/main/kotlin/com/nylas/resources/Grants.kt @@ -35,21 +35,6 @@ class Grants(client: NylasClient) : Resource(client, Grant::class.java) { return findResource(path) } - /** - * Create a Grant via Custom Authentication - * @param requestBody The values to create the Grant with - * @return The created Grant - */ - @Throws(NylasApiError::class, NylasSdkTimeoutError::class) - fun create(requestBody: CreateGrantRequest): Response { - val path = "v3/connect/custom" - val serializedRequestBody = JsonHelper.moshi() - .adapter(CreateGrantRequest::class.java) - .toJson(requestBody) - - return createResource(path, serializedRequestBody) - } - /** * Update a Grant * @param grantId The id of the Grant to update.