From 4bbef53f0762d5ad92d00b2dcae4461a59a8c8fb Mon Sep 17 00:00:00 2001 From: "devin-ai-integration[bot]" <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Fri, 17 Jan 2025 22:14:05 -0500 Subject: [PATCH] feat: make NylasClient and its methods open for mocking (#258) # Make NylasClient and its methods open for mocking This PR makes the NylasClient class and its methods open to enable mocking in tests, addressing issue #257. ## Changes - Added `open` modifier to NylasClient class - Made all resource accessor methods (messages, calendars, etc.) open - Made HTTP execution methods open for comprehensive mocking support ## Testing These changes are purely related to class and method modifiers to enable mocking. The changes do not affect runtime behavior and maintain all existing functionality. The modifications only impact compile-time characteristics to allow for better testing capabilities. ## Notes - This change is backward compatible - No runtime behavior changes - Enables better testing capabilities for SDK users Fixes #257 Link to Devin run: https://app.devin.ai/sessions/f6b8eb21945e4b84a4b26f39136760cd --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Aaron de Mello Co-authored-by: Aaron de Mello <314152+AaronDDM@users.noreply.github.com> --- CHANGELOG.md | 1 + src/main/kotlin/com/nylas/NylasClient.kt | 46 ++++++++++++------------ 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e9cf24ec..c98c2cbe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Nylas Java SDK Changelog ### Unreleased +* Made `NylasClient` and its methods open to enable mocking in tests * Added pagination support for folders ### [2.5.2] - Released 2024-12-02 diff --git a/src/main/kotlin/com/nylas/NylasClient.kt b/src/main/kotlin/com/nylas/NylasClient.kt index e3e9085c..ce770e9e 100644 --- a/src/main/kotlin/com/nylas/NylasClient.kt +++ b/src/main/kotlin/com/nylas/NylasClient.kt @@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit * @param httpClientBuilder The builder to use for creating the http client. * @param apiUri The URL to use for communicating with the Nylas API. */ -class NylasClient( +open class NylasClient( val apiKey: String, httpClientBuilder: OkHttpClient.Builder = defaultHttpClient(), apiUri: String = DEFAULT_BASE_URL, @@ -77,79 +77,79 @@ class NylasClient( * Access the Applications API * @return The Applications API */ - fun applications(): Applications = Applications(this) + open fun applications(): Applications = Applications(this) /** * Access the Attachments API * @return The Attachments API */ - fun attachments(): Attachments = Attachments(this) + open fun attachments(): Attachments = Attachments(this) /** * Access the Auth API * @return The Auth API */ - fun auth(): Auth = Auth(this) + open fun auth(): Auth = Auth(this) /** * Access the Calendars API * @return The Calendars API */ - fun calendars(): Calendars = Calendars(this) + open fun calendars(): Calendars = Calendars(this) /** * Access the Connectors API * @return The Connectors API */ - fun connectors(): Connectors = Connectors(this) + open fun connectors(): Connectors = Connectors(this) /** * Access the Drafts API * @return The Drafts API */ - fun drafts(): Drafts = Drafts(this) + open fun drafts(): Drafts = Drafts(this) /** * Access the Events API * @return The Events API */ - fun events(): Events = Events(this) + open fun events(): Events = Events(this) /** * Access the Folders API * @return The Folders API */ - fun folders(): Folders = Folders(this) + open fun folders(): Folders = Folders(this) /** * Access the Grants API * @return The Grants API */ - fun grants(): Grants = Grants(this) + open fun grants(): Grants = Grants(this) /** * Access the Messages API * @return The Messages API */ - fun messages(): Messages = Messages(this) + open fun messages(): Messages = Messages(this) /** * Access the Threads API * @return The Threads API */ - fun threads(): Threads = Threads(this) + open fun threads(): Threads = Threads(this) /** * Access the Webhooks API * @return The Webhooks API */ - fun webhooks(): Webhooks = Webhooks(this) + open fun webhooks(): Webhooks = Webhooks(this) /** * Access the Contacts API * @return The Contacts API */ - fun contacts(): Contacts = Contacts(this) + open fun contacts(): Contacts = Contacts(this) /** * Access the Scheduler API @@ -160,7 +160,7 @@ class NylasClient( /** * Get a URL builder instance for the Nylas API. */ - fun newUrlBuilder(): HttpUrl.Builder = apiUri.newBuilder() + open fun newUrlBuilder(): HttpUrl.Builder = apiUri.newBuilder() /** * Execute a GET request to the Nylas API. @@ -171,7 +171,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executeGet( + open fun executeGet( path: String, resultType: Type, queryParams: IQueryParams? = null, @@ -191,7 +191,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executePut( + open fun executePut( path: String, resultType: Type, requestBody: String? = null, @@ -213,7 +213,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executePatch( + open fun executePatch( path: String, resultType: Type, requestBody: String? = null, @@ -235,7 +235,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executePost( + open fun executePost( path: String, resultType: Type, requestBody: String? = null, @@ -259,7 +259,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executeDelete( + open fun executeDelete( path: String, resultType: Type, queryParams: IQueryParams? = null, @@ -280,7 +280,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executeFormRequest( + open fun executeFormRequest( path: String, method: HttpMethod, requestBody: RequestBody, @@ -324,7 +324,7 @@ class NylasClient( * @suppress Not for public use. */ @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun executeRequest( + open fun executeRequest( url: HttpUrl.Builder, method: HttpMethod, body: RequestBody?, @@ -339,7 +339,7 @@ class NylasClient( } @Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class) - fun downloadResponse( + open fun downloadResponse( path: String, queryParams: IQueryParams? = null, overrides: RequestOverrides? = null,