-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description This PR adds support for folders # License <!-- Your PR comment must contain the following line for us to merge the PR. --> 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.
- Loading branch information
1 parent
d5532ef
commit 3c610d3
Showing
5 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.nylas.models | ||
|
||
/** | ||
* Class representation of the Nylas folder creation request. | ||
*/ | ||
data class CreateFolderRequest( | ||
/** | ||
* The name of the folder. | ||
*/ | ||
val name: String, | ||
/** | ||
* The parent ID of the folder. (Microsoft only) | ||
*/ | ||
val parentId: String? = null, | ||
/** | ||
* The background color of the folder. (Google only) | ||
*/ | ||
val backgroundColor: String? = null, | ||
/** | ||
* The text color of the folder. (Google only) | ||
*/ | ||
val textColor: String? = null, | ||
) { | ||
/** | ||
* Builder for [CreateFolderRequest]. | ||
* @param name The name of the folder. | ||
*/ | ||
data class Builder( | ||
private val name: String, | ||
) { | ||
private var parentId: String? = null | ||
private var backgroundColor: String? = null | ||
private var textColor: String? = null | ||
|
||
/** | ||
* Set the parent ID of the folder. (Microsoft only) | ||
* @param parentId The parent ID of the folder. | ||
* @return The builder. | ||
*/ | ||
fun parentId(parentId: String) = apply { this.parentId = parentId } | ||
|
||
/** | ||
* Set the background color of the folder. (Google only) | ||
* | ||
* The background color of the folder in the hexadecimal format `#0099EE`. | ||
* See Google Defined Values for more information. | ||
* | ||
* @param backgroundColor The background color of the folder. | ||
* @return The builder. | ||
*/ | ||
fun backgroundColor(backgroundColor: String) = apply { this.backgroundColor = backgroundColor } | ||
|
||
/** | ||
* Set the text color of the folder. (Google only) | ||
* | ||
* The text color of the folder in the hexadecimal format `#0099EE`. | ||
* See Google Defined Values for more information. | ||
* | ||
* @param textColor The text color of the folder. | ||
* @return The builder. | ||
*/ | ||
fun textColor(textColor: String) = apply { this.textColor = textColor } | ||
|
||
/** | ||
* Build the [CreateFolderRequest]. | ||
* @return The [CreateFolderRequest]. | ||
*/ | ||
fun build() = CreateFolderRequest( | ||
name = name, | ||
parentId = parentId, | ||
backgroundColor = backgroundColor, | ||
textColor = textColor, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.nylas.models | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* Class representation of the Nylas folder response. | ||
*/ | ||
data class Folder( | ||
/** | ||
* A globally unique object identifier. | ||
*/ | ||
@Json(name = "id") | ||
val id: String, | ||
/** | ||
* A Grant ID of the Nylas account. | ||
*/ | ||
@Json(name = "grant_id") | ||
val grantId: String, | ||
/** | ||
* Folder name | ||
*/ | ||
@Json(name = "name") | ||
val name: String? = null, | ||
/** | ||
* The type of object. | ||
*/ | ||
@Json(name = "object") | ||
val obj: String = "folder", | ||
/** | ||
* ID of the parent folder. (Microsoft only) | ||
*/ | ||
@Json(name = "parent_id") | ||
val parentId: String? = null, | ||
/** | ||
* Folder background color. (Google only) | ||
*/ | ||
@Json(name = "background_color") | ||
val backgroundColor: String? = null, | ||
/** | ||
* Folder text color. (Google only) | ||
*/ | ||
@Json(name = "text_color") | ||
val textColor: String? = null, | ||
/** | ||
* Indicates if the folder is user created or system created. (Google Only) | ||
*/ | ||
@Json(name = "system_folder") | ||
val systemFolder: Boolean? = null, | ||
/** | ||
* The number of immediate child folders in the current folder. (Microsoft only) | ||
*/ | ||
@Json(name = "child_count") | ||
val childCount: Int? = null, | ||
/** | ||
* The number of unread items inside of a folder. | ||
*/ | ||
@Json(name = "unread_count") | ||
val unreadCount: Int? = null, | ||
/** | ||
* The number of items inside of a folder. | ||
*/ | ||
@Json(name = "total_count") | ||
val totalCount: Int? = null, | ||
) { | ||
/** | ||
* Get the type of object. | ||
* @return The type of object. | ||
*/ | ||
fun getObject() = obj | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.nylas.models | ||
|
||
/** | ||
* Class representation of the Nylas folder update request. | ||
*/ | ||
data class UpdateFolderRequest( | ||
/** | ||
* The name of the folder. | ||
*/ | ||
val name: String? = null, | ||
/** | ||
* The parent ID of the folder. (Microsoft only) | ||
*/ | ||
val parentId: String? = null, | ||
/** | ||
* The background color of the folder. (Google only) | ||
*/ | ||
val backgroundColor: String? = null, | ||
/** | ||
* The text color of the folder. (Google only) | ||
*/ | ||
val textColor: String? = null, | ||
) { | ||
/** | ||
* Builder for [UpdateFolderRequest]. | ||
*/ | ||
class Builder { | ||
private var name: String? = null | ||
private var parentId: String? = null | ||
private var backgroundColor: String? = null | ||
private var textColor: String? = null | ||
|
||
/** | ||
* Set the name of the folder. | ||
* @param name The name of the folder. | ||
* @return The builder. | ||
*/ | ||
fun name(name: String) = apply { this.name = name } | ||
|
||
/** | ||
* Set the parent ID of the folder. (Microsoft only) | ||
* @param parentId The parent ID of the folder. | ||
* @return The builder. | ||
*/ | ||
fun parentId(parentId: String) = apply { this.parentId = parentId } | ||
|
||
/** | ||
* Set the background color of the folder. (Google only) | ||
* | ||
* The background color of the folder in the hexadecimal format `#0099EE`. | ||
* See Google Defined Values for more information. | ||
* | ||
* @param backgroundColor The background color of the folder. | ||
* @return The builder. | ||
*/ | ||
fun backgroundColor(backgroundColor: String) = apply { this.backgroundColor = backgroundColor } | ||
|
||
/** | ||
* Set the text color of the folder. (Google only) | ||
* | ||
* The text color of the folder in the hexadecimal format `#0099EE`. | ||
* See Google Defined Values for more information. | ||
* | ||
* @param textColor The text color of the folder. | ||
* @return The builder. | ||
*/ | ||
fun textColor(textColor: String) = apply { this.textColor = textColor } | ||
|
||
/** | ||
* Build the [UpdateFolderRequest]. | ||
* @return The [UpdateFolderRequest]. | ||
*/ | ||
fun build() = UpdateFolderRequest( | ||
name = name, | ||
parentId = parentId, | ||
backgroundColor = backgroundColor, | ||
textColor = textColor, | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.nylas.resources | ||
|
||
import com.nylas.NylasClient | ||
import com.nylas.models.* | ||
import com.nylas.util.JsonHelper | ||
|
||
class Folders(client: NylasClient) : Resource<Folder>(client, Folder::class.java) { | ||
/** | ||
* Return all Folders | ||
* @param identifier Grant ID or email account to query. | ||
* @return The list of Folders | ||
*/ | ||
@Throws(NylasApiError::class, NylasSdkTimeoutError::class) | ||
fun list(identifier: String): ListResponse<Folder> { | ||
val path = String.format("v3/grants/%s/folders", identifier) | ||
return listResource(path) | ||
} | ||
|
||
/** | ||
* Return a Folder | ||
* @param identifier Grant ID or email account to query. | ||
* @param folderId The id of the folder to retrieve. | ||
* @return The folder | ||
*/ | ||
@Throws(NylasApiError::class, NylasSdkTimeoutError::class) | ||
fun find(identifier: String, folderId: String): Response<Folder> { | ||
val path = String.format("v3/grants/%s/folders/%s", identifier, folderId) | ||
return findResource(path) | ||
} | ||
|
||
/** | ||
* Create a Folder | ||
* @param identifier Grant ID or email account in which to create the object. | ||
* @param requestBody The values to create the folder with | ||
* @return The created folder | ||
*/ | ||
@Throws(NylasApiError::class, NylasSdkTimeoutError::class) | ||
fun create(identifier: String, requestBody: CreateFolderRequest): Response<Folder> { | ||
val path = String.format("v3/grants/%s/folders", identifier) | ||
val adapter = JsonHelper.moshi().adapter(CreateFolderRequest::class.java) | ||
val serializedRequestBody = adapter.toJson(requestBody) | ||
return createResource(path, serializedRequestBody) | ||
} | ||
|
||
/** | ||
* Update a Folder | ||
* @param identifier Grant ID or email account in which to update an object. | ||
* @param folderId The id of the folder to update. | ||
* @param requestBody The values to update the folder with | ||
* @return The updated folder | ||
*/ | ||
@Throws(NylasApiError::class, NylasSdkTimeoutError::class) | ||
fun update(identifier: String, folderId: String, requestBody: UpdateFolderRequest): Response<Folder> { | ||
val path = String.format("v3/grants/%s/folders/%s", identifier, folderId) | ||
val adapter = JsonHelper.moshi().adapter(UpdateFolderRequest::class.java) | ||
val serializedRequestBody = adapter.toJson(requestBody) | ||
return updateResource(path, serializedRequestBody) | ||
} | ||
|
||
/** | ||
* Delete a Folder | ||
* @param identifier Grant ID or email account from which to delete an object. | ||
* @param folderId The id of the folder to delete. | ||
* @return The deletion response | ||
*/ | ||
@Throws(NylasApiError::class, NylasSdkTimeoutError::class) | ||
fun destroy(identifier: String, folderId: String): DeleteResponse { | ||
val path = String.format("v3/grants/%s/folders/%s", identifier, folderId) | ||
return destroyResource(path) | ||
} | ||
} |