Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Messages, Drafts, and Smart Compose APIs support #166

Merged
merged 24 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
* Added support for the free-busy endpoint
* Add Messages, Drafts, and Smart Compose APIs support

## [2.0.0-beta.1] - Released 2023-08-16

Expand Down
45 changes: 45 additions & 0 deletions src/main/kotlin/com/nylas/NylasClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ class NylasClient(
return Calendars(this)
}

/**
* Access the Drafts API
* @return The Drafts API
*/
fun drafts(): Drafts {
return Drafts(this)
}

/**
* Access the Events API
* @return The Events API
Expand All @@ -103,6 +111,22 @@ class NylasClient(
return Events(this)
}

/**
* Access the Messages API
* @return The Messages API
*/
fun messages(): Messages {
return Messages(this)
}

/**
* Access the Threads API
* @return The Threads API
*/
fun threads(): Threads {
return Threads(this)
}

/**
* Access the Webhooks API
* @return The Webhooks API
Expand Down Expand Up @@ -215,6 +239,27 @@ class NylasClient(
return executeRequest(url, HttpMethod.DELETE, null, resultType)
}

/**
* Execute a request with a form-body payload to the Nylas API.
* @param path The path to request.
* @param method The HTTP method to use.
* @param requestBody The form-data request body.
* @param resultType The type of the response body.
* @param queryParams The query parameters.
* @suppress Not for public use.
*/
@Throws(AbstractNylasApiError::class, NylasSdkTimeoutError::class)
fun <T> executeFormRequest(
path: String,
method: HttpMethod,
requestBody: RequestBody,
resultType: Type? = null,
queryParams: IQueryParams? = null,
): T {
val url = buildUrl(path, queryParams)
return executeRequest(url, method, requestBody, resultType)
}

private fun buildRequest(
url: HttpUrl.Builder,
method: HttpMethod,
Expand Down
49 changes: 49 additions & 0 deletions src/main/kotlin/com/nylas/models/Attachment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Class representation of a Nylas attachment object
*/
data class Attachment(
/**
* Globally unique object identifier.
*/
@Json(name = "id")
val id: String? = null,
/**
* Nylas grant ID that is now successfully created.
*/
@Json(name = "grant_id")
val grantId: String? = null,
/**
* The size of the attachment in bytes.
*/
@Json(name = "size")
val size: Int? = null,
/**
* The filename of the attachment.
*/
@Json(name = "filename")
val filename: String? = null,
/**
* The content type of the attachment.
*/
@Json(name = "content_type")
val contentType: String? = null,
/**
* If it's an inline attachment.
*/
@Json(name = "is_inline")
val isInline: Boolean? = null,
/**
* The content ID of the attachment.
*/
@Json(name = "content_id")
val contentId: String? = null,
/**
* The content disposition if the attachment is located inline.
*/
@Json(name = "content_disposition")
val contentDisposition: String? = null,
)
11 changes: 11 additions & 0 deletions src/main/kotlin/com/nylas/models/ComposeMessageRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nylas.models

/**
* Class representing a request to compose a message.
*/
data class ComposeMessageRequest(
/**
* The prompt that smart compose will use to generate a message suggestion.
*/
val prompt: String,
)
11 changes: 11 additions & 0 deletions src/main/kotlin/com/nylas/models/ComposeMessageResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nylas.models

/**
* Class representing a response to a message composition request.
*/
data class ComposeMessageResponse(
/**
* The message suggestion generated by smart compose.
*/
val suggestion: String,
)
97 changes: 97 additions & 0 deletions src/main/kotlin/com/nylas/models/CreateAttachmentRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.nylas.models

import com.squareup.moshi.Json
import java.io.InputStream

/**
* Class representing a Nylas attachment object.
*/
class CreateAttachmentRequest(
/**
* The filename of the attachment.
*/
@Json(name = "filename")
val filename: String,
/**
* The content type of the attachment.
*/
@Json(name = "content_type")
val contentType: String,
/**
* The content of the attachment.
*/
@Transient
val content: InputStream,
/**
* The size of the attachment in bytes.
*/
@Json(name = "size")
val size: Int,
/**
* If it's an inline attachment.
*/
@Json(name = "is_inline")
val isInline: Boolean? = null,
/**
* The content ID of the attachment.
*/
@Json(name = "content_id")
val contentId: String? = null,
/**
* The content disposition if the attachment is located inline.
*/
@Json(name = "content_disposition")
val contentDisposition: String? = null,
) {
/**
* Builder for [CreateAttachmentRequest].
* @property filename The filename of the attachment.
* @property contentType The content type of the attachment.
* @property size The size of the attachment in bytes.
*/
data class Builder(
private val filename: String,
private val contentType: String,
private val content: InputStream,
private val size: Int,
) {
private var isInline: Boolean? = null
private var contentId: String? = null
private var contentDisposition: String? = null

/**
* Set if the attachment is inline.
* @param isInline If the attachment is inline.
* @return The builder.
*/
fun isInline(isInline: Boolean) = apply { this.isInline = isInline }

/**
* Set the content ID of the attachment.
* @param contentId The content ID of the attachment.
* @return The builder.
*/
fun contentId(contentId: String) = apply { this.contentId = contentId }

/**
* Set the content disposition of the attachment.
* @param contentDisposition The content disposition of the attachment.
* @return The builder.
*/
fun contentDisposition(contentDisposition: String) = apply { this.contentDisposition = contentDisposition }

/**
* Build the [CreateAttachmentRequest].
* @return The [CreateAttachmentRequest].
*/
fun build() = CreateAttachmentRequest(
filename = filename,
contentType = contentType,
content = content,
size = size,
isInline = isInline,
contentId = contentId,
contentDisposition = contentDisposition,
)
}
}