Skip to content

Commit 1aba5c8

Browse files
alanschneggalanschnegg-lyaAaronDDM
authored
Update folders: pagination added (#259)
This update addresses a client requirement where the current folder fetch limit of 50 elements is insufficient due to their large number of folders. The changes include: - Adding the pagination system like the others entities This enhancement improves usability for clients with extensive folder structures, enabling them to efficiently access and manage their data. # 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. --------- Co-authored-by: alan <[email protected]> Co-authored-by: Aaron de Mello <[email protected]>
1 parent 4be4cad commit 1aba5c8

File tree

4 files changed

+96
-4
lines changed

4 files changed

+96
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Nylas Java SDK Changelog
22

3+
### Unreleased
4+
* Added pagination support for folders
5+
36
### [2.5.2] - Released 2024-12-02
47
* Added support for `skypeForConsumer` as conferencing provider
58

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.nylas.models
2+
3+
import com.squareup.moshi.Json
4+
5+
/**
6+
* Class representing the query parameters for listing messages.
7+
*/
8+
data class ListFoldersQueryParams(
9+
/**
10+
* The maximum number of objects to return.
11+
* This field defaults to 50. The maximum allowed value is 200.
12+
*/
13+
@Json(name = "limit")
14+
val limit: Int? = null,
15+
/**
16+
* An identifier that specifies which page of data to return.
17+
* This value should be taken from the [ListResponse.nextCursor] response field.
18+
*/
19+
@Json(name = "page_token")
20+
val pageToken: String? = null,
21+
/**
22+
* (Microsoft and EWS only.) Use the ID of a folder to find all child folders it contains.
23+
*/
24+
@Json(name = "parent_id")
25+
val parentId: String? = null,
26+
/**
27+
* Specify fields that you want Nylas to return, as a comma-separated list (for example, select=id,updated_at).
28+
* This allows you to receive only the portion of object data that you're interested in.
29+
* You can use select to optimize response size and reduce latency by limiting queries to only the information that you need
30+
*/
31+
@Json(name = "select")
32+
var select: String? = null,
33+
) : IQueryParams {
34+
class Builder {
35+
private var limit: Int? = null
36+
private var pageToken: String? = null
37+
private var parentId: String? = null
38+
private var select: String? = null
39+
40+
/**
41+
* Sets the maximum number of objects to return.
42+
* This field defaults to 10. The maximum allowed value is 200.
43+
* @param limit The maximum number of objects to return.
44+
* @return The builder.
45+
*/
46+
fun limit(limit: Int?) = apply { this.limit = limit }
47+
48+
/**
49+
* Sets the identifier that specifies which page of data to return.
50+
* This value should be taken from the next_cursor response field.
51+
* @param pageToken The identifier that specifies which page of data to return.
52+
* @return The builder.
53+
*/
54+
fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken }
55+
56+
/**
57+
* Sets the parent id of the folders to return.
58+
* @param parentId The parent id of the folder to return.
59+
* @return The builder.
60+
*/
61+
fun parentId(parentId: String?) = apply { this.parentId = parentId }
62+
63+
/**
64+
* Sets the fields to return in the response.
65+
* @param select List of field names to return (e.g. "id,updated_at")
66+
* @return The builder.
67+
*/
68+
fun select(select: String?) = apply { this.select = select }
69+
70+
/**
71+
* Builds the [ListFoldersQueryParams] object.
72+
* @return The [ListFoldersQueryParams] object.
73+
*/
74+
fun build() = ListFoldersQueryParams(
75+
limit = limit,
76+
pageToken = pageToken,
77+
parentId = parentId,
78+
select = select,
79+
)
80+
}
81+
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ class Folders(client: NylasClient) : Resource<Folder>(client, Folder::class.java
88
/**
99
* Return all Folders
1010
* @param identifier Grant ID or email account to query.
11+
* @param queryParams The query parameters to include in the request
1112
* @param overrides Optional request overrides to apply
1213
* @return The list of Folders
1314
*/
1415
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
1516
@JvmOverloads
16-
fun list(identifier: String, overrides: RequestOverrides? = null): ListResponse<Folder> {
17+
fun list(identifier: String, queryParams: ListFoldersQueryParams? = null, overrides: RequestOverrides? = null): ListResponse<Folder> {
1718
val path = String.format("v3/grants/%s/folders", identifier)
18-
return listResource(path, overrides = overrides)
19+
return listResource(path, queryParams, overrides)
1920
}
2021

2122
/**

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ class FoldersTests {
9292

9393
@Test
9494
fun `listing folders calls requests with the correct params`() {
95-
folders.list(grantId)
95+
val queryParams =
96+
ListFoldersQueryParams(
97+
limit = 10,
98+
pageToken = "abc-123",
99+
select = "id,updated_at",
100+
)
101+
102+
folders.list(grantId, queryParams)
96103

97104
val pathCaptor = argumentCaptor<String>()
98105
val typeCaptor = argumentCaptor<Type>()
@@ -107,7 +114,7 @@ class FoldersTests {
107114

108115
assertEquals("v3/grants/$grantId/folders", pathCaptor.firstValue)
109116
assertEquals(Types.newParameterizedType(ListResponse::class.java, Folder::class.java), typeCaptor.firstValue)
110-
assertNull(queryParamCaptor.firstValue)
117+
assertEquals(queryParams, queryParamCaptor.firstValue)
111118
}
112119

113120
@Test

0 commit comments

Comments
 (0)