Skip to content

Commit 5ce8bbf

Browse files
committed
Add workspace list pagination params
1 parent 69f4a06 commit 5ce8bbf

4 files changed

Lines changed: 73 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- `Applications.update()` for `PATCH /v3/applications`
88
- Redirect URI updates use `PATCH /v3/applications/redirect-uris/{id}`
99
- Manage Domains admin CRUD and verification endpoints on `client.domains()` via `/v3/admin/domains`; these support `ServiceAccountSigner` for Nylas Service Account request-signing auth without Bearer auth and still accept manually signed headers in `RequestOverrides.headers`
10-
- `Workspaces` resource via `client.workspaces()`: CRUD, `autoGroup`, `manualAssign`, `default`, `policyId`, and `ruleIds`; `CreateWorkspaceRequest` validates that `domain` is present when `autoGroup` is true
10+
- `Workspaces` resource via `client.workspaces()`: CRUD, paginated listing with `limit` and `page_token`, `autoGroup`, `manualAssign`, `default`, `policyId`, and `ruleIds`; `CreateWorkspaceRequest` validates that `domain` is present when `autoGroup` is true
1111
* Transactional email support via `Domains.sendTransactionalEmail()`
1212
- `SendTransactionalEmailRequest` model (and fluent `Builder`) for composing transactional messages from a verified domain — supports `to`, `from`, `cc`, `bcc`, `reply_to`, `subject`, `body`, `send_at`, `reply_to_message_id`, `tracking_options`, `use_draft`, `custom_headers`, and `is_plaintext`
1313
- `NylasClient.domains()` accessor returning the new `Domains` resource
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.nylas.models
2+
3+
import com.squareup.moshi.Json
4+
5+
/**
6+
* Class representation of the query parameters for listing workspaces.
7+
*/
8+
data class ListWorkspacesQueryParams(
9+
/**
10+
* The maximum number of objects to return.
11+
*/
12+
@Json(name = "limit")
13+
val limit: Int? = null,
14+
/**
15+
* Cursor for pagination. Pass the value of [ListResponse.nextCursor] to get the next page.
16+
*/
17+
@Json(name = "page_token")
18+
val pageToken: String? = null,
19+
) : IQueryParams {
20+
/**
21+
* Builder for [ListWorkspacesQueryParams].
22+
*/
23+
class Builder {
24+
private var limit: Int? = null
25+
private var pageToken: String? = null
26+
27+
/**
28+
* Set the maximum number of objects to return.
29+
* @param limit The maximum number of objects to return.
30+
* @return The builder.
31+
*/
32+
fun limit(limit: Int) = apply { this.limit = limit }
33+
34+
/**
35+
* Set the pagination cursor.
36+
* @param pageToken Cursor for pagination. Pass the value of [ListResponse.nextCursor].
37+
* @return The builder.
38+
*/
39+
fun pageToken(pageToken: String) = apply { this.pageToken = pageToken }
40+
41+
/**
42+
* Build the [ListWorkspacesQueryParams].
43+
* @return A [ListWorkspacesQueryParams] with the provided values.
44+
*/
45+
fun build() = ListWorkspacesQueryParams(limit, pageToken)
46+
}
47+
}

src/main/kotlin/com/nylas/resources/Workspaces.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@ import com.squareup.moshi.Types
1717
class Workspaces(client: NylasClient) : Resource<Workspace>(client, Workspace::class.java) {
1818
/**
1919
* Return all workspaces for your application.
20+
* @param queryParams Optional query parameters to apply
2021
* @param overrides Optional request overrides to apply
2122
* @return The list of workspaces
2223
*/
2324
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
2425
@JvmOverloads
25-
fun list(overrides: RequestOverrides? = null): ListResponse<Workspace> {
26-
return listResource("v3/workspaces", overrides = overrides)
26+
fun list(queryParams: ListWorkspacesQueryParams? = null, overrides: RequestOverrides? = null): ListResponse<Workspace> {
27+
return listResource("v3/workspaces", queryParams, overrides)
2728
}
2829

2930
/**

src/test/kotlin/com/nylas/resources/WorkspacesTests.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,28 @@ class WorkspacesTests {
171171

172172
assertEquals("v3/workspaces", pathCaptor.firstValue)
173173
assertEquals(Types.newParameterizedType(ListResponse::class.java, Workspace::class.java), typeCaptor.firstValue)
174+
assertNull(queryParamCaptor.firstValue)
175+
}
176+
177+
@Test
178+
fun `listing workspaces with query params passes them correctly`() {
179+
val queryParams = ListWorkspacesQueryParams(limit = 5, pageToken = "cursor123")
180+
workspaces.list(queryParams)
181+
182+
val pathCaptor = argumentCaptor<String>()
183+
val typeCaptor = argumentCaptor<Type>()
184+
val queryParamCaptor = argumentCaptor<IQueryParams>()
185+
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
186+
verify(mockNylasClient).executeGet<ListResponse<Workspace>>(
187+
pathCaptor.capture(),
188+
typeCaptor.capture(),
189+
queryParamCaptor.capture(),
190+
overrideParamCaptor.capture(),
191+
)
192+
193+
assertEquals("v3/workspaces", pathCaptor.firstValue)
194+
assertEquals(Types.newParameterizedType(ListResponse::class.java, Workspace::class.java), typeCaptor.firstValue)
195+
assertEquals(queryParams, queryParamCaptor.firstValue)
174196
}
175197

176198
@Test

0 commit comments

Comments
 (0)