Skip to content

Commit

Permalink
Merge branch 'AV-1451-3-0-part-2' of https://github.com/nylas/nylas-java
Browse files Browse the repository at this point in the history
 into AV-1451-3-0-part-2
  • Loading branch information
atejada committed Jan 18, 2024
2 parents 33f0665 + 631e686 commit 6d011b8
Show file tree
Hide file tree
Showing 25 changed files with 2,085 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
* Added support for sending drafts
* Added support for the contacts API
* Added enum support for OAuth prompt
* Added additional enum support for Grants

### Changed
* Fixed issue with sending scheduled messages
* Fixed incorrect PKCE code challenge generation
* Fixed provider detect endpoint path
* Fixed scope encoding for OAuth URL
* Fixed typo in 'EventVisibility' enum
* Fixed various issues with the connector API
* Fixed response type for smart compose methods
* Fixed inaccuracies with webhook related models

## [2.0.0-beta.3] - Released 2023-12-18

Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/models/Connector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sealed class Connector(
* The Google OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>?,
val scope: List<String>? = null,
) : Connector(AuthProvider.GOOGLE)

/**
Expand All @@ -42,7 +42,7 @@ sealed class Connector(
* The Microsoft OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>?,
val scope: List<String>? = null,
) : Connector(AuthProvider.MICROSOFT)

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/models/CreateConnectorRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ sealed class CreateConnectorRequest(
* The Google OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>?,
val scope: List<String>? = null,
) : CreateConnectorRequest(AuthProvider.GOOGLE) {
/**
* Builder for Google connector creation requests.
Expand Down Expand Up @@ -65,7 +65,7 @@ sealed class CreateConnectorRequest(
* The Microsoft OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>?,
val scope: List<String>? = null,
) : CreateConnectorRequest(AuthProvider.MICROSOFT) {
/**
* Builder for Microsoft connector creation requests.
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/com/nylas/models/CreateWebhookRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ data class CreateWebhookRequest(
/**
* The url to send webhooks to.
*/
@Json(name = "callback_url")
val callbackUrl: String,
@Json(name = "webhook_url")
val webhookUrl: String,
/**
* A human-readable description of the webhook destination.
*/
Expand All @@ -24,20 +24,20 @@ data class CreateWebhookRequest(
/**
* The email addresses that Nylas notifies when a webhook is down for a while.
*/
@Json(name = "notification_email_address")
val notificationEmailAddress: String? = null,
@Json(name = "notification_email_addresses")
val notificationEmailAddresses: List<String>? = null,
) {
/**
* A builder for creating a [CreateWebhookRequest].
* @param triggerTypes Select the event that triggers the webhook.
* @param callbackUrl The url to send webhooks to.
* @param webhookUrl The url to send webhooks to.
*/
data class Builder(
private val triggerTypes: List<WebhookTriggers>,
private val callbackUrl: String,
private val webhookUrl: String,
) {
private var description: String? = null
private var notificationEmailAddress: String? = null
private var notificationEmailAddresses: List<String>? = null

/**
* Set a human-readable description of the webhook destination.
Expand All @@ -48,15 +48,15 @@ data class CreateWebhookRequest(

/**
* Set the email addresses that Nylas notifies when a webhook is down for a while.
* @param notificationEmailAddress The email addresses that Nylas notifies when a webhook is down for a while.
* @param notificationEmailAddresses The email addresses that Nylas notifies when a webhook is down for a while.
* @return The builder.
*/
fun notificationEmailAddress(notificationEmailAddress: String?) = apply { this.notificationEmailAddress = notificationEmailAddress }
fun notificationEmailAddresses(notificationEmailAddresses: List<String>?) = apply { this.notificationEmailAddresses = notificationEmailAddresses }

/**
* Build the [CreateWebhookRequest].
* @return The created [CreateWebhookRequest].
*/
fun build() = CreateWebhookRequest(triggerTypes, callbackUrl, description, notificationEmailAddress)
fun build() = CreateWebhookRequest(triggerTypes, webhookUrl, description, notificationEmailAddresses)
}
}
8 changes: 4 additions & 4 deletions src/main/kotlin/com/nylas/models/Credential.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ data class Credential(
* The type of credential
*/
@Json(name = "credential_type")
val credentialType: CredentialType?,
val credentialType: CredentialType? = null,
/**
* Hashed value of the credential that you created
*/
@Json(name = "hashed_data")
val hashedData: String?,
val hashedData: String? = null,
/**
* Timestamp of when the credential was created
*/
@Json(name = "created_at")
val createdAt: Long?,
val createdAt: Long? = null,
/**
* Timestamp of when the credential was updated
*/
@Json(name = "updated_at")
val updatedAt: Long?,
val updatedAt: Long? = null,
)
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/models/Grant.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class Grant(
* OAuth provider that the user authenticated with.
*/
@Json(name = "provider")
val provider: String,
val provider: AuthProvider,
/**
* Scopes specified for the grant.
*/
Expand All @@ -30,7 +30,7 @@ data class Grant(
* Status of the grant, if it is still valid or if the user needs to re-authenticate.
*/
@Json(name = "grant_status")
val grantStatus: String? = null,
val grantStatus: GrantStatus? = null,
/**
* Email address associated with the grant.
*/
Expand Down
11 changes: 11 additions & 0 deletions src/main/kotlin/com/nylas/models/GrantStatus.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.nylas.models

import com.squareup.moshi.Json

enum class GrantStatus {
@Json(name = "valid")
VALID,

@Json(name = "invalid")
INVALID,
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/ScheduledMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ data class ScheduledMessage(
* The time the message was sent or failed to send, in epoch time.
*/
@Json(name = "close_time")
val closeTime: Int?,
val closeTime: Int? = null,
)
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/models/UpdateCredentialRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ data class UpdateCredentialRequest(
* Unique name of this credential
*/
@Json(name = "name")
val name: String?,
val name: String? = null,
/**
* Data that specifies some special data required for this credential
*/
@Json(name = "credential_data")
val credentialData: CredentialData?,
val credentialData: CredentialData? = null,
) {
/**
* Builder for [UpdateCredentialRequest]
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/com/nylas/models/UpdateThreadRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ data class UpdateThreadRequest(
* Sets all messages in the thread as starred or unstarred.
*/
@Json(name = "starred")
val starred: Boolean?,
val starred: Boolean? = null,
/**
* Sets all messages in the thread as read or unread.
*/
@Json(name = "unread")
val unread: Boolean?,
val unread: Boolean? = null,
/**
* The IDs of the folders to apply, overwriting all previous folders for all messages in the thread.
*/
@Json(name = "folders")
val folders: List<String>?,
val folders: List<String>? = null,
) {
/**
* Builder for [UpdateThreadRequest].
Expand Down
20 changes: 10 additions & 10 deletions src/main/kotlin/com/nylas/models/UpdateWebhookRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ data class UpdateWebhookRequest(
/**
* The url to send webhooks to.
*/
@Json(name = "callback_url")
val callbackUrl: String? = null,
@Json(name = "webhook_url")
val webhookUrl: String? = null,
/**
* A human-readable description of the webhook destination.
*/
Expand All @@ -24,17 +24,17 @@ data class UpdateWebhookRequest(
/**
* The email addresses that Nylas notifies when a webhook is down for a while.
*/
@Json(name = "notification_email_address")
val notificationEmailAddress: String? = null,
@Json(name = "notification_email_addresses")
val notificationEmailAddresses: List<String>? = null,
) {
/**
* A builder for creating a [UpdateWebhookRequest].
*/
class Builder {
private var triggerTypes: List<WebhookTriggers>? = null
private var callbackUrl: String? = null
private var webhookUrl: String? = null
private var description: String? = null
private var notificationEmailAddress: String? = null
private var notificationEmailAddresses: List<String>? = null

/**
* Set the event that triggers the webhook.
Expand All @@ -48,7 +48,7 @@ data class UpdateWebhookRequest(
* @param callbackUrl The url to send webhooks to.
* @return The builder.
*/
fun callbackUrl(callbackUrl: String?) = apply { this.callbackUrl = callbackUrl }
fun webhookUrl(webhookUrl: String?) = apply { this.webhookUrl = webhookUrl }

/**
* Set a human-readable description of the webhook destination.
Expand All @@ -59,15 +59,15 @@ data class UpdateWebhookRequest(

/**
* Set the email addresses that Nylas notifies when a webhook is down for a while.
* @param notificationEmailAddress The email addresses that Nylas notifies when a webhook is down for a while.
* @param notificationEmailAddresses The email addresses that Nylas notifies when a webhook is down for a while.
* @return The builder.
*/
fun notificationEmailAddress(notificationEmailAddress: String?) = apply { this.notificationEmailAddress = notificationEmailAddress }
fun notificationEmailAddresses(notificationEmailAddresses: List<String>?) = apply { this.notificationEmailAddresses = notificationEmailAddresses }

/**
* Build the [UpdateWebhookRequest].
* @return The created [UpdateWebhookRequest].
*/
fun build() = UpdateWebhookRequest(triggerTypes, callbackUrl, description, notificationEmailAddress)
fun build() = UpdateWebhookRequest(triggerTypes, webhookUrl, description, notificationEmailAddresses)
}
}
10 changes: 5 additions & 5 deletions src/main/kotlin/com/nylas/models/Webhook.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ data class Webhook(
/**
* The url to send webhooks to.
*/
@Json(name = "callback_url")
val callbackUrl: String,
@Json(name = "webhook_url")
val webhookUrl: String,
/**
* Select the event that triggers the webhook.
*/
Expand All @@ -40,7 +40,7 @@ data class Webhook(
* The time the status field was last updated, represented as a Unix timestamp in seconds.
*/
@Json(name = "updated_at")
val updatedAt: String,
val updatedAt: Long,
/**
* A human-readable description of the webhook destination.
*/
Expand All @@ -49,6 +49,6 @@ data class Webhook(
/**
* The email addresses that Nylas notifies when a webhook is down for a while.
*/
@Json(name = "notification_email_address")
val notificationEmailAddress: String? = null,
@Json(name = "notification_email_addresses")
val notificationEmailAddresses: List<String>? = null,
)
10 changes: 5 additions & 5 deletions src/main/kotlin/com/nylas/models/WebhookWithSecret.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ data class WebhookWithSecret(
/**
* The url to send webhooks to.
*/
@Json(name = "callback_url")
val callbackUrl: String,
@Json(name = "webhook_url")
val webhookUrl: String,
/**
* A secret value used to encode the X-Nylas-Signature header on webhook requests.
*/
Expand Down Expand Up @@ -45,7 +45,7 @@ data class WebhookWithSecret(
* The time the status field was last updated, represented as a Unix timestamp in seconds.
*/
@Json(name = "updated_at")
val updatedAt: String,
val updatedAt: Long,
/**
* A human-readable description of the webhook destination.
*/
Expand All @@ -54,6 +54,6 @@ data class WebhookWithSecret(
/**
* The email addresses that Nylas notifies when a webhook is down for a while.
*/
@Json(name = "notification_email_address")
val notificationEmailAddress: String? = null,
@Json(name = "notification_email_addresses")
val notificationEmailAddresses: List<String>? = null,
)
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/resources/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Contacts(client: NylasClient) : Resource<Contact>(client, Contact::class.j
@JvmOverloads
fun find(identifier: String, contactId: String, queryParams: FindContactQueryParams? = null): Response<Contact> {
val path = String.format("v3/grants/%s/contacts/%s", identifier, contactId)
return findResource(path)
return findResource(path, queryParams)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/resources/Grants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Grants(client: NylasClient) : Resource<Grant>(client, Grant::class.java) {
.adapter(UpdateGrantRequest::class.java)
.toJson(requestBody)

return updateResource(path, serializedRequestBody)
return patchResource(path, serializedRequestBody)
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/com/nylas/resources/SmartCompose.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.nylas.models.ComposeMessageRequest
import com.nylas.models.ComposeMessageResponse
import com.nylas.models.Response
import com.nylas.util.JsonHelper
import com.squareup.moshi.Types

/**
* A collection of Smart Compose related API endpoints.
Expand All @@ -26,8 +27,9 @@ class SmartCompose(private val client: NylasClient) {
val serializedRequestBody = JsonHelper.moshi()
.adapter(ComposeMessageRequest::class.java)
.toJson(requestBody)
val responseType = Types.newParameterizedType(Response::class.java, ComposeMessageResponse::class.java)

return client.executePost(path, ComposeMessageResponse::class.java, serializedRequestBody)
return client.executePost(path, responseType, serializedRequestBody)
}

/**
Expand All @@ -43,7 +45,8 @@ class SmartCompose(private val client: NylasClient) {
val serializedRequestBody = JsonHelper.moshi()
.adapter(ComposeMessageRequest::class.java)
.toJson(requestBody)
val responseType = Types.newParameterizedType(Response::class.java, ComposeMessageResponse::class.java)

return client.executePost(path, ComposeMessageResponse::class.java, serializedRequestBody)
return client.executePost(path, responseType, serializedRequestBody)
}
}
Loading

0 comments on commit 6d011b8

Please sign in to comment.