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 support for custom headers field for drafts and messages #223

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Nylas Java SDK Changelog

## Unreleased
### [Unreleased]

### Added
* Added support for custom headers field for Drafts and Messages
* Added support for overriding various fields of outgoing requests

## [2.2.1] - Released 2024-03-05
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nylas/models/CreateDraftRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ data class CreateDraftRequest(
*/
@Json(name = "tracking_options")
val trackingOptions: TrackingOptions? = null,
/**
* A list of custom headers to add to the message.
*/
@Json(name = "custom_headers")
val customHeaders: List<CustomHeader>? = null,
) : IMessageAttachmentRequest {
/**
* Builder for [CreateDraftRequest].
Expand All @@ -78,6 +83,7 @@ data class CreateDraftRequest(
private var sendAt: Int? = null
private var replyToMessageId: String? = null
private var trackingOptions: TrackingOptions? = null
private var customHeaders: List<CustomHeader>? = null

/**
* Sets the recipients.
Expand Down Expand Up @@ -157,6 +163,13 @@ data class CreateDraftRequest(
*/
fun trackingOptions(trackingOptions: TrackingOptions?) = apply { this.trackingOptions = trackingOptions }

/**
* Sets the custom headers to add to the message.
* @param customHeaders The custom headers to add to the message.
* @return The builder.
*/
fun customHeaders(customHeaders: List<CustomHeader>?) = apply { this.customHeaders = customHeaders }

/**
* Builds a [SendMessageRequest] instance.
* @return The [SendMessageRequest] instance.
Expand All @@ -174,6 +187,7 @@ data class CreateDraftRequest(
sendAt,
replyToMessageId,
trackingOptions,
customHeaders,
)
}
}
36 changes: 36 additions & 0 deletions src/main/kotlin/com/nylas/models/CustomHeader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Custom headers to be used when drafting or sending an email.
*/
data class CustomHeader(
/**
* The name of the custom header.
*/
@Json(name = "name")
val name: String,
/**
* The value of the custom header.
*/
@Json(name = "value")
val value: String,
) {
/**
* Builder for [CustomHeader].
* @property name The name of the custom header.
* @property value The value of the custom header.
*/
data class Builder(
private val name: String,
private val value: String,
) {
/**
* Build the [CustomHeader] object.
*/
fun build(): CustomHeader {
return CustomHeader(name, value)
}
}
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nylas/models/SendMessageRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ data class SendMessageRequest(
*/
@Json(name = "use_draft")
val useDraft: Boolean? = null,
/**
* A list of custom headers to add to the message.
*/
@Json(name = "custom_headers")
val customHeaders: List<CustomHeader>? = null,
) : IMessageAttachmentRequest {
/**
* Builder for [SendMessageRequest].
Expand All @@ -87,6 +92,7 @@ data class SendMessageRequest(
private var replyToMessageId: String? = null
private var trackingOptions: TrackingOptions? = null
private var useDraft: Boolean? = null
private var customHeaders: List<CustomHeader>? = null

/**
* Sets the bcc recipients.
Expand Down Expand Up @@ -167,6 +173,13 @@ data class SendMessageRequest(
*/
fun useDraft(useDraft: Boolean?) = apply { this.useDraft = useDraft }

/**
* Sets the custom headers to add to the message.
* @param customHeaders The custom headers to add to the message.
* @return The builder.
*/
fun customHeaders(customHeaders: List<CustomHeader>?) = apply { this.customHeaders = customHeaders }

/**
* Builds a [SendMessageRequest] instance.
* @return The [SendMessageRequest] instance.
Expand All @@ -185,6 +198,7 @@ data class SendMessageRequest(
replyToMessageId,
trackingOptions,
useDraft,
customHeaders,
)
}
}
3 changes: 3 additions & 0 deletions src/test/kotlin/com/nylas/resources/DraftsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class DraftsTests {
sendAt = 1620000000,
replyToMessageId = "reply-to-message-id",
trackingOptions = TrackingOptions(label = "label", links = true, opens = true, threadReplies = true),
customHeaders = listOf(CustomHeader(name = "header", value = "value")),
)

drafts.create(grantId, createDraftRequest)
Expand Down Expand Up @@ -275,6 +276,7 @@ class DraftsTests {
size = 100,
),
),
customHeaders = listOf(CustomHeader(name = "header", value = "value")),
)

drafts.create(grantId, createDraftRequest)
Expand Down Expand Up @@ -320,6 +322,7 @@ class DraftsTests {
size = 3 * 1024 * 1024,
),
),
customHeaders = listOf(CustomHeader(name = "header", value = "value")),
)

drafts.create(grantId, createDraftRequest)
Expand Down
3 changes: 3 additions & 0 deletions src/test/kotlin/com/nylas/resources/MessagesTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ class MessagesTests {
sendAt = 1620000000,
replyToMessageId = "reply-to-message-id",
trackingOptions = TrackingOptions(label = "label", links = true, opens = true, threadReplies = true),
customHeaders = listOf(CustomHeader(name = "header-name", value = "header-value")),
)

messages.send(grantId, sendMessageRequest)
Expand Down Expand Up @@ -430,6 +431,7 @@ class MessagesTests {
size = 100,
),
),
customHeaders = listOf(CustomHeader(name = "header-name", value = "header-value")),
)

messages.send(grantId, sendMessageRequest)
Expand Down Expand Up @@ -476,6 +478,7 @@ class MessagesTests {
size = 3 * 1024 * 1024,
),
),
customHeaders = listOf(CustomHeader(name = "header-name", value = "header-value")),
)

messages.send(grantId, sendMessageRequest)
Expand Down
Loading