Skip to content

Commit

Permalink
Complete resources testing + fixes (#192)
Browse files Browse the repository at this point in the history
# Description
This PR brings the test coverage of the resources module to 100%. Fixes
include:
* Added additional enum support for Grants
* Fixed various issues with the connector API
* Fixed response type for smart compose methods
* Fixed inaccuracies with webhook related models

# 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.

---------

Co-authored-by: Blag <[email protected]>
  • Loading branch information
mrashed-dev and atejada authored Jan 30, 2024
1 parent 2d19f3c commit 3f18ace
Show file tree
Hide file tree
Showing 62 changed files with 3,843 additions and 145 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,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
6 changes: 3 additions & 3 deletions src/main/kotlin/com/nylas/models/ApplicationDetails.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ data class ApplicationDetails(
@Json(name = "hosted_authentication")
val hostedAuthentication: HostedAuthentication? = null,
/**
* List of redirect URIs
* List of callback URIs
*/
@Json(name = "redirect_uris")
val redirectUris: List<RedirectUri>? = null,
@Json(name = "callback_uris")
val callbackUris: List<RedirectUri>? = null,
) {
/**
* Class representation of branding details for the application
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/nylas/models/ComposeMessageRequest.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.nylas.models

import com.squareup.moshi.Json

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

import com.squareup.moshi.Json

/**
* Class representing a response to a message composition request.
*/
data class ComposeMessageResponse(
/**
* The message suggestion generated by smart compose.
*/
@Json(name = "suggestion")
val suggestion: String,
)
63 changes: 50 additions & 13 deletions src/main/kotlin/com/nylas/models/Connector.kt
Original file line number Diff line number Diff line change
@@ -1,29 +1,66 @@
package com.nylas.models

import com.squareup.moshi.Json
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory

/**
* Class representation of the Nylas connector response.
*/
data class Connector(
/**
* Custom name of the connector
*/
@Json(name = "name")
val name: String,
sealed class Connector(
/**
* The provider type
*/
@Json(name = "provider")
val provider: AuthProvider,
) {
/**
* Class representing a Google connector creation request.
*/
data class Google(
/**
* The Google OAuth provider credentials and settings
*/
@Json(name = "settings")
val settings: GoogleConnectorSettings,
/**
* The Google OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>? = null,
) : Connector(AuthProvider.GOOGLE)

/**
* Optional settings from provider
* Class representing a Microsoft connector creation request.
*/
@Json(name = "settings")
val settings: Map<String, Any>? = null,
data class Microsoft(
/**
* The Microsoft OAuth provider credentials and settings
*/
@Json(name = "settings")
val settings: MicrosoftConnectorSettings,
/**
* The Microsoft OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>? = null,
) : Connector(AuthProvider.MICROSOFT)

/**
* Default scopes for the connector
* Class representing an IMAP connector creation request.
*/
@Json(name = "scope")
val scope: List<String>? = null,
)
class Imap : Connector(AuthProvider.IMAP)

/**
* Class representing a virtual calendar connector creation request.
*/
class VirtualCalendar : Connector(AuthProvider.VIRTUAL_CALENDAR)

companion object {
@JvmStatic
val CONNECTOR_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory<Connector> = PolymorphicJsonAdapterFactory.of(Connector::class.java, "provider")
.withSubtype(Google::class.java, AuthProvider.GOOGLE.value)
.withSubtype(Microsoft::class.java, AuthProvider.MICROSOFT.value)
.withSubtype(Imap::class.java, AuthProvider.IMAP.value)
.withSubtype(VirtualCalendar::class.java, AuthProvider.VIRTUAL_CALENDAR.value)
}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactEmail.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Interface for email addresses in a contact.
*/
data class ContactEmail(
@Json(name = "email")
val email: String? = null,
@Json(name = "type")
val type: ContactType? = null,
) {
class Builder {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactGroup.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Class representing a contact group.
*/
data class ContactGroup(
@Json(name = "id")
val id: String,
@Json(name = "grant_id")
val grantId: String? = null,
@Json(name = "group_type")
val groupType: GroupType? = null,
@Json(name = "name")
val name: String? = null,
@Json(name = "path")
val path: String? = null,
@Json(name = "object")
private val obj: String = "contact_group",
) {
fun getObject() = obj
Expand Down
6 changes: 6 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactGroupId.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Class representing an object that points to a contact group ID.
*/
data class ContactGroupId(
/**
* The ID of the contact group.
*/
@Json(name = "id")
val id: String,
)
95 changes: 62 additions & 33 deletions src/main/kotlin/com/nylas/models/CreateConnectorRequest.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.nylas.models

import com.squareup.moshi.Json
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory

/**
* This sealed class represents the base Nylas connector creation request.
*/
sealed class CreateConnectorRequest(
/**
* Custom name of the connector
*/
@Json(name = "name")
open val name: String,
/**
* The provider type
*/
Expand All @@ -21,11 +17,6 @@ sealed class CreateConnectorRequest(
* Class representing a Google connector creation request.
*/
data class Google(
/**
* Custom name of the connector
*/
@Json(name = "name")
override val name: String,
/**
* The Google OAuth provider credentials and settings
*/
Expand All @@ -35,18 +26,36 @@ sealed class CreateConnectorRequest(
* The Google OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>?,
) : CreateConnectorRequest(name, AuthProvider.GOOGLE)
val scope: List<String>? = null,
) : CreateConnectorRequest(AuthProvider.GOOGLE) {
/**
* Builder for Google connector creation requests.
* @param settings The Google OAuth provider credentials and settings
*/
data class Builder(
private val settings: GoogleCreateConnectorSettings,
) {
private var scope: List<String>? = null

/**
* Set the Google OAuth scopes
* @param scope The Google OAuth scopes
* @return The builder
*/
fun scope(scope: List<String>) = apply { this.scope = scope }

/**
* Build the Google connector creation request
* @return The Google connector creation request
*/
fun build() = Google(settings, scope)
}
}

/**
* Class representing a Microsoft connector creation request.
*/
data class Microsoft(
/**
* Custom name of the connector
*/
@Json(name = "name")
override val name: String,
/**
* The Microsoft OAuth provider credentials and settings
*/
Expand All @@ -56,28 +65,48 @@ sealed class CreateConnectorRequest(
* The Microsoft OAuth scopes
*/
@Json(name = "scope")
val scope: List<String>?,
) : CreateConnectorRequest(name, AuthProvider.MICROSOFT)
val scope: List<String>? = null,
) : CreateConnectorRequest(AuthProvider.MICROSOFT) {
/**
* Builder for Microsoft connector creation requests.
* @param settings The Microsoft OAuth provider credentials and settings
*/
data class Builder(
private val settings: MicrosoftCreateConnectorSettings,
) {
private var scope: List<String>? = null

/**
* Set the Microsoft OAuth scopes
* @param scope The Microsoft OAuth scopes
* @return The builder
*/
fun scope(scope: List<String>) = apply { this.scope = scope }

/**
* Build the Microsoft connector creation request
* @return The Microsoft connector creation request
*/
fun build() = Microsoft(settings, scope)
}
}

/**
* Class representing an IMAP connector creation request.
*/
data class Imap(
/**
* Custom name of the connector
*/
@Json(name = "name")
override val name: String,
) : CreateConnectorRequest(name, AuthProvider.IMAP)
class Imap : CreateConnectorRequest(AuthProvider.IMAP)

/**
* Class representing a virtual calendar connector creation request.
*/
data class VirtualCalendar(
/**
* Custom name of the connector
*/
@Json(name = "name")
override val name: String,
) : CreateConnectorRequest(name, AuthProvider.VIRTUAL_CALENDAR)
class VirtualCalendar : CreateConnectorRequest(AuthProvider.VIRTUAL_CALENDAR)

companion object {
@JvmStatic
val CREATE_CONNECTOR_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory<CreateConnectorRequest> = PolymorphicJsonAdapterFactory.of(CreateConnectorRequest::class.java, "provider")
.withSubtype(Google::class.java, AuthProvider.GOOGLE.value)
.withSubtype(Microsoft::class.java, AuthProvider.MICROSOFT.value)
.withSubtype(Imap::class.java, AuthProvider.IMAP.value)
.withSubtype(VirtualCalendar::class.java, AuthProvider.VIRTUAL_CALENDAR.value)
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/com/nylas/models/CreateCredentialRequest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.nylas.models

import com.squareup.moshi.Json
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory

/**
* Class representing a request to create a credential
Expand Down Expand Up @@ -69,4 +70,12 @@ sealed class CreateCredentialRequest(
@Json(name = "credential_data")
override val credentialData: CredentialData.ConnectorOverride,
) : CreateCredentialRequest(name, credentialData, CredentialType.CONNECTOR)

companion object {
@JvmStatic
val CREATE_CREDENTIAL_JSON_ADAPTER_FACTORY: PolymorphicJsonAdapterFactory<CreateCredentialRequest> = PolymorphicJsonAdapterFactory.of(CreateCredentialRequest::class.java, "credential_type")
.withSubtype(Microsoft::class.java, CredentialType.ADMINCONSENT.value)
.withSubtype(Google::class.java, CredentialType.SERVICEACCOUNT.value)
.withSubtype(Override::class.java, CredentialType.CONNECTOR.value)
}
}
6 changes: 6 additions & 0 deletions src/main/kotlin/com/nylas/models/CreateFolderRequest.kt
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Class representation of the Nylas folder creation request.
*/
data class CreateFolderRequest(
/**
* The name of the folder.
*/
@Json(name = "name")
val name: String,
/**
* The parent ID of the folder. (Microsoft only)
*/
@Json(name = "parent_id")
val parentId: String? = null,
/**
* The background color of the folder. (Google only)
*/
@Json(name = "background_color")
val backgroundColor: String? = null,
/**
* The text color of the folder. (Google only)
*/
@Json(name = "text_color")
val textColor: String? = null,
) {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/models/CreateGrantRequest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ data class CreateGrantRequest(
/**
* Optional list of scopes to request. If not specified it will use the integration default scopes.
*/
@Json(name = "scopes")
val scopes: List<String>? = null,
@Json(name = "scope")
val scope: List<String>? = null,
) {
/**
* Builder for [CreateGrantRequest].
Expand Down
Loading

0 comments on commit 3f18ace

Please sign in to comment.