Skip to content

Commit 4bbef53

Browse files
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 <[email protected]> Co-authored-by: Aaron de Mello <[email protected]>
1 parent 1aba5c8 commit 4bbef53

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Nylas Java SDK Changelog
22

33
### Unreleased
4+
* Made `NylasClient` and its methods open to enable mocking in tests
45
* Added pagination support for folders
56

67
### [2.5.2] - Released 2024-12-02

src/main/kotlin/com/nylas/NylasClient.kt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import java.util.concurrent.TimeUnit
2626
* @param httpClientBuilder The builder to use for creating the http client.
2727
* @param apiUri The URL to use for communicating with the Nylas API.
2828
*/
29-
class NylasClient(
29+
open class NylasClient(
3030
val apiKey: String,
3131
httpClientBuilder: OkHttpClient.Builder = defaultHttpClient(),
3232
apiUri: String = DEFAULT_BASE_URL,
@@ -77,79 +77,79 @@ class NylasClient(
7777
* Access the Applications API
7878
* @return The Applications API
7979
*/
80-
fun applications(): Applications = Applications(this)
80+
open fun applications(): Applications = Applications(this)
8181

8282
/**
8383
* Access the Attachments API
8484
* @return The Attachments API
8585
*/
86-
fun attachments(): Attachments = Attachments(this)
86+
open fun attachments(): Attachments = Attachments(this)
8787

8888
/**
8989
* Access the Auth API
9090
* @return The Auth API
9191
*/
92-
fun auth(): Auth = Auth(this)
92+
open fun auth(): Auth = Auth(this)
9393

9494
/**
9595
* Access the Calendars API
9696
* @return The Calendars API
9797
*/
98-
fun calendars(): Calendars = Calendars(this)
98+
open fun calendars(): Calendars = Calendars(this)
9999

100100
/**
101101
* Access the Connectors API
102102
* @return The Connectors API
103103
*/
104-
fun connectors(): Connectors = Connectors(this)
104+
open fun connectors(): Connectors = Connectors(this)
105105

106106
/**
107107
* Access the Drafts API
108108
* @return The Drafts API
109109
*/
110-
fun drafts(): Drafts = Drafts(this)
110+
open fun drafts(): Drafts = Drafts(this)
111111

112112
/**
113113
* Access the Events API
114114
* @return The Events API
115115
*/
116-
fun events(): Events = Events(this)
116+
open fun events(): Events = Events(this)
117117

118118
/**
119119
* Access the Folders API
120120
* @return The Folders API
121121
*/
122-
fun folders(): Folders = Folders(this)
122+
open fun folders(): Folders = Folders(this)
123123

124124
/**
125125
* Access the Grants API
126126
* @return The Grants API
127127
*/
128-
fun grants(): Grants = Grants(this)
128+
open fun grants(): Grants = Grants(this)
129129

130130
/**
131131
* Access the Messages API
132132
* @return The Messages API
133133
*/
134-
fun messages(): Messages = Messages(this)
134+
open fun messages(): Messages = Messages(this)
135135

136136
/**
137137
* Access the Threads API
138138
* @return The Threads API
139139
*/
140-
fun threads(): Threads = Threads(this)
140+
open fun threads(): Threads = Threads(this)
141141

142142
/**
143143
* Access the Webhooks API
144144
* @return The Webhooks API
145145
*/
146-
fun webhooks(): Webhooks = Webhooks(this)
146+
open fun webhooks(): Webhooks = Webhooks(this)
147147

148148
/**
149149
* Access the Contacts API
150150
* @return The Contacts API
151151
*/
152-
fun contacts(): Contacts = Contacts(this)
152+
open fun contacts(): Contacts = Contacts(this)
153153

154154
/**
155155
* Access the Scheduler API
@@ -160,7 +160,7 @@ class NylasClient(
160160
/**
161161
* Get a URL builder instance for the Nylas API.
162162
*/
163-
fun newUrlBuilder(): HttpUrl.Builder = apiUri.newBuilder()
163+
open fun newUrlBuilder(): HttpUrl.Builder = apiUri.newBuilder()
164164

165165
/**
166166
* Execute a GET request to the Nylas API.
@@ -171,7 +171,7 @@ class NylasClient(
171171
* @suppress Not for public use.
172172
*/
173173
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
174-
fun <T> executeGet(
174+
open fun <T> executeGet(
175175
path: String,
176176
resultType: Type,
177177
queryParams: IQueryParams? = null,
@@ -191,7 +191,7 @@ class NylasClient(
191191
* @suppress Not for public use.
192192
*/
193193
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
194-
fun <T> executePut(
194+
open fun <T> executePut(
195195
path: String,
196196
resultType: Type,
197197
requestBody: String? = null,
@@ -213,7 +213,7 @@ class NylasClient(
213213
* @suppress Not for public use.
214214
*/
215215
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
216-
fun <T> executePatch(
216+
open fun <T> executePatch(
217217
path: String,
218218
resultType: Type,
219219
requestBody: String? = null,
@@ -235,7 +235,7 @@ class NylasClient(
235235
* @suppress Not for public use.
236236
*/
237237
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
238-
fun <T> executePost(
238+
open fun <T> executePost(
239239
path: String,
240240
resultType: Type,
241241
requestBody: String? = null,
@@ -259,7 +259,7 @@ class NylasClient(
259259
* @suppress Not for public use.
260260
*/
261261
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
262-
fun <T> executeDelete(
262+
open fun <T> executeDelete(
263263
path: String,
264264
resultType: Type,
265265
queryParams: IQueryParams? = null,
@@ -280,7 +280,7 @@ class NylasClient(
280280
* @suppress Not for public use.
281281
*/
282282
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
283-
fun <T> executeFormRequest(
283+
open fun <T> executeFormRequest(
284284
path: String,
285285
method: HttpMethod,
286286
requestBody: RequestBody,
@@ -324,7 +324,7 @@ class NylasClient(
324324
* @suppress Not for public use.
325325
*/
326326
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
327-
fun <T> executeRequest(
327+
open fun <T> executeRequest(
328328
url: HttpUrl.Builder,
329329
method: HttpMethod,
330330
body: RequestBody?,
@@ -339,7 +339,7 @@ class NylasClient(
339339
}
340340

341341
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
342-
fun downloadResponse(
342+
open fun downloadResponse(
343343
path: String,
344344
queryParams: IQueryParams? = null,
345345
overrides: RequestOverrides? = null,

0 commit comments

Comments
 (0)