From fab37732bbf5591768c1373c9c8b9d46ce415203 Mon Sep 17 00:00:00 2001 From: alan Date: Thu, 19 Dec 2024 19:01:42 +0100 Subject: [PATCH 1/2] Update folders: pagination added --- .../nylas/models/ListFoldersQueryParams.kt | 65 +++++++++++++++++++ .../kotlin/com/nylas/resources/Folders.kt | 5 +- .../com/nylas/resources/FoldersTests.kt | 8 ++- 3 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt diff --git a/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt b/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt new file mode 100644 index 00000000..73d90f06 --- /dev/null +++ b/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt @@ -0,0 +1,65 @@ +package com.nylas.models + +import com.squareup.moshi.Json + +/** + * Class representing the query parameters for listing messages. + */ +data class ListFoldersQueryParams( + /** + * The maximum number of objects to return. + * This field defaults to 50. The maximum allowed value is 200. + */ + @Json(name = "limit") + val limit: Int? = null, + /** + * An identifier that specifies which page of data to return. + * This value should be taken from the [ListResponse.nextCursor] response field. + */ + @Json(name = "page_token") + val pageToken: String? = null, + /** + * (Microsoft and EWS only.) Use the ID of a folder to find all child folders it contains. + */ + @Json(name = " parent_id") + val parentId: String? = null, +) : IQueryParams { + class Builder { + private var limit: Int? = null + private var pageToken: String? = null + private var parentId: String? = null + + /** + * Sets the maximum number of objects to return. + * This field defaults to 10. The maximum allowed value is 200. + * @param limit The maximum number of objects to return. + * @return The builder. + */ + fun limit(limit: Int?) = apply { this.limit = limit } + + /** + * Sets the identifier that specifies which page of data to return. + * This value should be taken from the next_cursor response field. + * @param pageToken The identifier that specifies which page of data to return. + * @return The builder. + */ + fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken } + + /** + * Sets the parent id of the folders to return. + * @param parentId The parent id of the folder to return. + * @return The builder. + */ + fun parentId(parentId: String?) = apply { this.parentId = parentId } + + /** + * Builds the [ListFoldersQueryParams] object. + * @return The [ListFoldersQueryParams] object. + */ + fun build() = ListFoldersQueryParams( + limit = limit, + pageToken = pageToken, + parentId = parentId, + ) + } +} diff --git a/src/main/kotlin/com/nylas/resources/Folders.kt b/src/main/kotlin/com/nylas/resources/Folders.kt index 4e280da8..31bfae3b 100644 --- a/src/main/kotlin/com/nylas/resources/Folders.kt +++ b/src/main/kotlin/com/nylas/resources/Folders.kt @@ -8,14 +8,15 @@ class Folders(client: NylasClient) : Resource(client, Folder::class.java /** * Return all Folders * @param identifier Grant ID or email account to query. + * @param queryParams The query parameters to include in the request * @param overrides Optional request overrides to apply * @return The list of Folders */ @Throws(NylasApiError::class, NylasSdkTimeoutError::class) @JvmOverloads - fun list(identifier: String, overrides: RequestOverrides? = null): ListResponse { + fun list(identifier: String, queryParams: ListFoldersQueryParams? = null, overrides: RequestOverrides? = null): ListResponse { val path = String.format("v3/grants/%s/folders", identifier) - return listResource(path, overrides = overrides) + return listResource(path, queryParams, overrides) } /** diff --git a/src/test/kotlin/com/nylas/resources/FoldersTests.kt b/src/test/kotlin/com/nylas/resources/FoldersTests.kt index 827f1d05..e706e77b 100644 --- a/src/test/kotlin/com/nylas/resources/FoldersTests.kt +++ b/src/test/kotlin/com/nylas/resources/FoldersTests.kt @@ -92,7 +92,13 @@ class FoldersTests { @Test fun `listing folders calls requests with the correct params`() { - folders.list(grantId) + val queryParams = + ListFoldersQueryParams( + limit = 10, + pageToken = "abc-123", + ) + + folders.list(grantId, queryParams) val pathCaptor = argumentCaptor() val typeCaptor = argumentCaptor() From c0939e8849ed8c7e8877d736121ba4329302fbe9 Mon Sep 17 00:00:00 2001 From: Aaron de Mello Date: Fri, 17 Jan 2025 14:52:22 -0500 Subject: [PATCH 2/2] added support for the select query param to list folders --- CHANGELOG.md | 3 +++ .../com/nylas/models/ListFoldersQueryParams.kt | 18 +++++++++++++++++- .../kotlin/com/nylas/resources/FoldersTests.kt | 3 ++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d8dc500..e9cf24ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Nylas Java SDK Changelog +### Unreleased +* Added pagination support for folders + ### [2.5.2] - Released 2024-12-02 * Added support for `skypeForConsumer` as conferencing provider diff --git a/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt b/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt index 73d90f06..05b6017a 100644 --- a/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt +++ b/src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt @@ -21,13 +21,21 @@ data class ListFoldersQueryParams( /** * (Microsoft and EWS only.) Use the ID of a folder to find all child folders it contains. */ - @Json(name = " parent_id") + @Json(name = "parent_id") val parentId: String? = null, + /** + * Specify fields that you want Nylas to return, as a comma-separated list (for example, select=id,updated_at). + * This allows you to receive only the portion of object data that you're interested in. + * You can use select to optimize response size and reduce latency by limiting queries to only the information that you need + */ + @Json(name = "select") + var select: String? = null, ) : IQueryParams { class Builder { private var limit: Int? = null private var pageToken: String? = null private var parentId: String? = null + private var select: String? = null /** * Sets the maximum number of objects to return. @@ -52,6 +60,13 @@ data class ListFoldersQueryParams( */ fun parentId(parentId: String?) = apply { this.parentId = parentId } + /** + * Sets the fields to return in the response. + * @param select List of field names to return (e.g. "id,updated_at") + * @return The builder. + */ + fun select(select: String?) = apply { this.select = select } + /** * Builds the [ListFoldersQueryParams] object. * @return The [ListFoldersQueryParams] object. @@ -60,6 +75,7 @@ data class ListFoldersQueryParams( limit = limit, pageToken = pageToken, parentId = parentId, + select = select, ) } } diff --git a/src/test/kotlin/com/nylas/resources/FoldersTests.kt b/src/test/kotlin/com/nylas/resources/FoldersTests.kt index e706e77b..fe0823fb 100644 --- a/src/test/kotlin/com/nylas/resources/FoldersTests.kt +++ b/src/test/kotlin/com/nylas/resources/FoldersTests.kt @@ -96,6 +96,7 @@ class FoldersTests { ListFoldersQueryParams( limit = 10, pageToken = "abc-123", + select = "id,updated_at", ) folders.list(grantId, queryParams) @@ -113,7 +114,7 @@ class FoldersTests { assertEquals("v3/grants/$grantId/folders", pathCaptor.firstValue) assertEquals(Types.newParameterizedType(ListResponse::class.java, Folder::class.java), typeCaptor.firstValue) - assertNull(queryParamCaptor.firstValue) + assertEquals(queryParams, queryParamCaptor.firstValue) } @Test