Skip to content

Commit

Permalink
Move Grants to NylasClient and custom authentication to Auth (#182
Browse files Browse the repository at this point in the history
)

# Description
⚠️ This is a breaking change ⚠️ 

This PR moves the following:
* `Auth.grants()` to `NylasClient.grants()`
* `Grants.create()` to `Auth.customAuthentication()`

Functionality remains the same.

# 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 Dec 27, 2023
1 parent 598fa65 commit db64b95
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 24 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [2.0.0-beta.4] - TBD

### BREAKING CHANGES
* Moved grants API out of `Auth` to `NylasClient`
* Moved `Grants.create()` to `Auth.customAuthentication()`

### Added
* Added support for sending drafts

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

/**
* Access the Grants API
* @return The Grants API
*/
fun grants(): Grants {
return Grants(this)
}

/**
* Access the Messages API
* @return The Messages API
Expand Down
25 changes: 16 additions & 9 deletions src/main/kotlin/com/nylas/resources/Auth.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ import java.util.*
* @param client The configured Nylas API client
*/
class Auth(private val client: NylasClient) {

/**
* Access the Grants API
* @return The Grants API
*/
fun grants(): Grants {
return Grants(client)
}

/**
* Build the URL for authenticating users to your application with OAuth 2.0
* @param config The configuration for building the URL
Expand Down Expand Up @@ -94,6 +85,22 @@ class Auth(private val client: NylasClient) {
return urlBuilder.build().toString()
}

/**
* Create a grant via custom authentication
* @param requestBody The values to create the grant with
* @return The created grant
*/
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
fun customAuthentication(requestBody: CreateGrantRequest): Response<Grant> {
val path = "v3/connect/custom"
val serializedRequestBody = JsonHelper.moshi()
.adapter(CreateGrantRequest::class.java)
.toJson(requestBody)
val responseType = Types.newParameterizedType(Response::class.java, Grant::class.java)

return client.executePost(path, responseType, serializedRequestBody)
}

/**
* Refresh an access token
* @param request The refresh token request
Expand Down
15 changes: 0 additions & 15 deletions src/main/kotlin/com/nylas/resources/Grants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ class Grants(client: NylasClient) : Resource<Grant>(client, Grant::class.java) {
return findResource(path)
}

/**
* Create a Grant via Custom Authentication
* @param requestBody The values to create the Grant with
* @return The created Grant
*/
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
fun create(requestBody: CreateGrantRequest): Response<Grant> {
val path = "v3/connect/custom"
val serializedRequestBody = JsonHelper.moshi()
.adapter(CreateGrantRequest::class.java)
.toJson(requestBody)

return createResource(path, serializedRequestBody)
}

/**
* Update a Grant
* @param grantId The id of the Grant to update.
Expand Down

0 comments on commit db64b95

Please sign in to comment.