Skip to content

Commit

Permalink
Fix names for clean messages (#228)
Browse files Browse the repository at this point in the history
# Description
Simple changes, should all be clean messages.

# 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
mrashed-dev authored Apr 30, 2024
1 parent 2f61629 commit e1a2f30
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 17 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@
### [Unreleased]

### Added
* Added missing webhook triggers
* Added provider field to token exchange response
* Added support for clean messages endpoint
* Added support for custom headers field for Drafts and Messages
* Added support for overriding various fields of outgoing requests

### Changed
* Fixed issue where attachments < 3mb were not being encoded correctly

## [2.2.1] - Released 2024-03-05

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.squareup.moshi.Json
/**
* Class representation of a Nylas clean message request
*/
data class CleanMessageRequest(
data class CleanMessagesRequest(
/**
* IDs of the email messages to clean.
*/
Expand Down Expand Up @@ -39,7 +39,7 @@ data class CleanMessageRequest(
) {

/**
* Builder for the [CleanMessageRequest] class.
* Builder for the [CleanMessagesRequest] class.
* @param messageId IDs of the email messages to clean.
*/
data class Builder(
Expand Down Expand Up @@ -87,10 +87,10 @@ data class CleanMessageRequest(
fun removeConclusionPhrases(removeConclusionPhrases: Boolean) = apply { this.removeConclusionPhrases = removeConclusionPhrases }

/**
* Builds the [CleanMessageRequest] instance.
* @return The [CleanMessageRequest] instance.
* Builds the [CleanMessagesRequest] instance.
* @return The [CleanMessagesRequest] instance.
*/
fun build() = CleanMessageRequest(
fun build() = CleanMessagesRequest(
messageId = messageId,
ignoreLinks = ignoreLinks,
ignoreImages = ignoreImages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.nylas.models

import com.squareup.moshi.Json

data class CleanMessageResponse(
data class CleanMessagesResponse(
/**
* Grant ID of the Nylas account.
*/
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/com/nylas/resources/Messages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,17 @@ class Messages(client: NylasClient) : Resource<Message>(client, Message::class.j
}

/**
* Clean messages
* Remove extra information from a list of messages
* @param identifier The identifier of the grant to act upon
* @param requestBody The values to clean the message with
* @return The list of cleaned messages
*/
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
fun cleanConversation(identifier: String, requestBody: CleanMessageRequest): ListResponse<CleanMessageResponse> {
fun cleanMessages(identifier: String, requestBody: CleanMessagesRequest): ListResponse<CleanMessagesResponse> {
val path = String.format("v3/grants/%s/messages/clean", identifier)
val adapter = JsonHelper.moshi().adapter(CleanMessageRequest::class.java)
val adapter = JsonHelper.moshi().adapter(CleanMessagesRequest::class.java)
val serializedRequestBody = adapter.toJson(requestBody)
val responseType = Types.newParameterizedType(ListResponse::class.java, CleanMessageResponse::class.java)
val responseType = Types.newParameterizedType(ListResponse::class.java, CleanMessagesResponse::class.java)
return client.executePut(path, responseType, serializedRequestBody)
}
}
14 changes: 7 additions & 7 deletions src/test/kotlin/com/nylas/resources/MessagesTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -541,24 +541,24 @@ class MessagesTests {
@Test
fun `cleaning a message calls requests with the correct params`() {
val messageId = "message-123"
val adapter = JsonHelper.moshi().adapter(CleanMessageRequest::class.java)
val cleanMessageRequest =
CleanMessageRequest.Builder(listOf(messageId))
val adapter = JsonHelper.moshi().adapter(CleanMessagesRequest::class.java)
val cleanMessagesRequest =
CleanMessagesRequest.Builder(listOf(messageId))
.ignoreLinks(true)
.ignoreImages(true)
.imagesAsMarkdown(true)
.ignoreTables(true)
.removeConclusionPhrases(true)
.build()

messages.cleanConversation(grantId, cleanMessageRequest)
messages.cleanMessages(grantId, cleanMessagesRequest)

val pathCaptor = argumentCaptor<String>()
val typeCaptor = argumentCaptor<Type>()
val requestBodyCaptor = argumentCaptor<String>()
val queryParamCaptor = argumentCaptor<IQueryParams>()
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
verify(mockNylasClient).executePut<Response<CleanMessageResponse>>(
verify(mockNylasClient).executePut<Response<CleanMessagesResponse>>(
pathCaptor.capture(),
typeCaptor.capture(),
requestBodyCaptor.capture(),
Expand All @@ -567,8 +567,8 @@ class MessagesTests {
)

assertEquals("v3/grants/$grantId/messages/clean", pathCaptor.firstValue)
assertEquals(Types.newParameterizedType(ListResponse::class.java, CleanMessageResponse::class.java), typeCaptor.firstValue)
assertEquals(adapter.toJson(cleanMessageRequest), requestBodyCaptor.firstValue)
assertEquals(Types.newParameterizedType(ListResponse::class.java, CleanMessagesResponse::class.java), typeCaptor.firstValue)
assertEquals(adapter.toJson(cleanMessagesRequest), requestBodyCaptor.firstValue)
assertNull(queryParamCaptor.firstValue)
}
}
Expand Down

0 comments on commit e1a2f30

Please sign in to comment.