Skip to content

Commit

Permalink
Update folders: pagination added
Browse files Browse the repository at this point in the history
  • Loading branch information
alan committed Dec 19, 2024
1 parent 4be4cad commit fab3773
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 3 deletions.
65 changes: 65 additions & 0 deletions src/main/kotlin/com/nylas/models/ListFoldersQueryParams.kt
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
5 changes: 3 additions & 2 deletions src/main/kotlin/com/nylas/resources/Folders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ class Folders(client: NylasClient) : Resource<Folder>(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<Folder> {
fun list(identifier: String, queryParams: ListFoldersQueryParams? = null, overrides: RequestOverrides? = null): ListResponse<Folder> {
val path = String.format("v3/grants/%s/folders", identifier)
return listResource(path, overrides = overrides)
return listResource(path, queryParams, overrides)
}

/**
Expand Down
8 changes: 7 additions & 1 deletion src/test/kotlin/com/nylas/resources/FoldersTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()
val typeCaptor = argumentCaptor<Type>()
Expand Down

0 comments on commit fab3773

Please sign in to comment.