Skip to content

Commit

Permalink
Merge branch 'v2.0.0-beta' into AV-1451-3-0-beta-java-sdk-beta-test-c…
Browse files Browse the repository at this point in the history
…overage
  • Loading branch information
mrashed-dev committed Jan 5, 2024
2 parents f95fa01 + c5d5d4f commit 45bd2d3
Show file tree
Hide file tree
Showing 34 changed files with 984 additions and 51 deletions.
27 changes: 26 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Nylas Java SDK Changelog

## [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
* Added support for the contacts API

### Changed
* Fixed issue with sending scheduled messages
* Fixed incorrect PKCE code challenge generation

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

### Added
* Added support for event send RSVP

### Changed
* Fixed int type being serialized to double sometimes
* Fixed `Auth.exchangeCodeForToken` always returning 401
* Fixed error when sending message or updating draft

## [2.0.0-beta.2] - Released 2023-11-21

### Added
Expand Down Expand Up @@ -413,7 +437,8 @@ This second release aims toward API stability so that we can get to v1.0.0.

Initial preview release

[Unreleased]: https://github.com/nylas/nylas-java/compare/v2.0.0-beta.2...HEAD
[Unreleased]: https://github.com/nylas/nylas-java/compare/v2.0.0-beta.3...HEAD
[2.0.0-beta.3]: https://github.com/nylas/nylas-java/releases/tag/v2.0.0-beta.3
[2.0.0-beta.2]: https://github.com/nylas/nylas-java/releases/tag/v2.0.0-beta.2
[2.0.0-beta.1]: https://github.com/nylas/nylas-java/releases/tag/v2.0.0-beta.1
[1.21.0]: https://github.com/nylas/nylas-java/releases/tag/v1.21.0
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group=com.nylas.sdk
version=2.0.0-beta.2
version=2.0.0-beta.3

# Override and set these in ~/.gradle/gradle.properties
ossrhUser=
Expand Down
19 changes: 19 additions & 0 deletions src/main/kotlin/com/nylas/NylasClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,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 All @@ -160,6 +168,14 @@ class NylasClient(
return Webhooks(this)
}

/**
* Access the Contacts API
* @return The Contacts API
*/
fun contacts(): Contacts {
return Contacts(this)
}

/**
* Get a URL builder instance for the Nylas API.
*/
Expand Down Expand Up @@ -427,6 +443,9 @@ class NylasClient(
url.addQueryParameter(key, "$k:$v")
}
}
is Double -> {
url.addQueryParameter(key, value.toInt().toString())
}
else -> {
url.addQueryParameter(key, value.toString())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,21 @@ class ContentHeadersInterceptor : Interceptor {
val path = request.url().encodedPath()
val contentHeader = request.header(NylasClient.HttpHeaders.CONTENT_TYPE.headerName)
if (contentHeader == null && !isDownloadablePath(path)) {
val enhancedRequest = request
.newBuilder()
.header(
val enhancedRequest = request.newBuilder()
if (request.body() != null && request.body()!!.contentType() != null) {
enhancedRequest.header(
NylasClient.HttpHeaders.CONTENT_TYPE.headerName,
request.body()!!.contentType()!!.toString(),
)
} else if (request.body() != null) {
enhancedRequest.header(
NylasClient.HttpHeaders.CONTENT_TYPE.headerName,
NylasClient.MediaType.APPLICATION_JSON.mediaType,
)
.header(NylasClient.HttpHeaders.ACCEPT.headerName, NylasClient.MediaType.APPLICATION_JSON.mediaType)
.build()
return chain.proceed(enhancedRequest)
}

enhancedRequest.header(NylasClient.HttpHeaders.ACCEPT.headerName, NylasClient.MediaType.APPLICATION_JSON.mediaType)
return chain.proceed(enhancedRequest.build())
}
return chain.proceed(request)
}
Expand Down
59 changes: 59 additions & 0 deletions src/main/kotlin/com/nylas/models/Contact.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.nylas.models

import com.squareup.moshi.Json

/**
* Class representation of a Nylas contact object
*/
data class Contact(
@Json(name = "id")
val id: String = "",
@Json(name = "grant_id")
val grantId: String = "",
@Json(name = "object")
private val obj: String = "contact",
@Json(name = "birthday")
val birthday: String? = null,
@Json(name = "company_name")
val companyName: String? = null,
@Json(name = "display_name")
val displayName: String = "",
@Json(name = "emails")
val emails: List<ContactEmail>? = null,
@Json(name = "im_addresses")
val imAddresses: List<InstantMessagingAddress>? = null,
@Json(name = "given_name")
val givenName: String? = null,
@Json(name = "job_title")
val jobTitle: String? = null,
@Json(name = "manager_name")
val managerName: String? = null,
@Json(name = "middle_name")
val middleName: String? = null,
@Json(name = "nickname")
val nickname: String? = null,
@Json(name = "notes")
val notes: String? = null,
@Json(name = "office_location")
val officeLocation: String? = null,
@Json(name = "picture_url")
val pictureUrl: String? = null,
@Json(name = "picture")
val picture: String? = null,
@Json(name = "suffix")
val suffix: String? = null,
@Json(name = "surname")
val surname: String? = null,
@Json(name = "source")
val source: SourceType? = null,
@Json(name = "phone_numbers")
val phoneNumbers: List<PhoneNumber>? = null,
@Json(name = "physical_addresses")
val physicalAddresses: List<PhysicalAddress>? = null,
@Json(name = "web_pages")
val webPages: List<WebPage>? = null,
@Json(name = "groups")
val groups: List<ContactGroupId>? = null,
) {
fun getObject() = obj
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactEmail.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nylas.models

/**
* Interface for email addresses in a contact.
*/
data class ContactEmail(
val email: String? = null,
val type: ContactType? = null,
) {
class Builder {
private var email: String? = null
private var type: ContactType? = null

fun email(email: String) = apply { this.email = email }
fun type(type: ContactType) = apply { this.type = type }
fun build() = ContactEmail(email, type)
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactGroup.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.nylas.models

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

/**
* Class representing an object that points to a contact group ID.
*/
data class ContactGroupId(
val id: String,
)
17 changes: 17 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.nylas.models

import com.squareup.moshi.Json

enum class ContactType {
@Json(name = "work")
WORK,

@Json(name = "home")
HOME,

@Json(name = "other")
OTHER,

@Json(name = "mobile")
MOBILE,
}
113 changes: 113 additions & 0 deletions src/main/kotlin/com/nylas/models/CreateContactRequest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package com.nylas.models

import com.squareup.moshi.Json

data class CreateContactRequest(
@Json(name = "display_name")
val displayName: String? = null,
@Json(name = "birthday")
val birthday: String? = null,
@Json(name = "company_name")
val companyName: String? = null,
@Json(name = "emails")
val emails: List<ContactEmail>? = null,
@Json(name = "given_name")
val givenName: String? = null,
@Json(name = "im_addresses")
val imAddresses: List<InstantMessagingAddress>? = null,
@Json(name = "job_title")
val jobTitle: String? = null,
@Json(name = "manager_name")
val managerName: String? = null,
@Json(name = "middle_name")
val middleName: String? = null,
@Json(name = "nickname")
val nickname: String? = null,
@Json(name = "notes")
val notes: String? = null,
@Json(name = "office_location")
val officeLocation: String? = null,
@Json(name = "phone_numbers")
val phoneNumbers: List<PhoneNumber>? = null,
@Json(name = "physical_addresses")
val physicalAddresses: List<PhysicalAddress>? = null,
@Json(name = "suffix")
val suffix: String? = null,
@Json(name = "surname")
val surname: String? = null,
@Json(name = "web_pages")
val webPages: List<WebPage>? = null,
@Json(name = "picture")
val picture: String? = null,
@Json(name = "source")
val source: SourceType? = null,
@Json(name = "groups")
val groups: List<ContactGroupId>? = null,
) {
class Builder {
private var displayName: String? = null
private var birthday: String? = null
private var companyName: String? = null
private var emails: List<ContactEmail>? = null
private var givenName: String? = null
private var imAddresses: List<InstantMessagingAddress>? = null
private var jobTitle: String? = null
private var managerName: String? = null
private var middleName: String? = null
private var nickname: String? = null
private var notes: String? = null
private var officeLocation: String? = null
private var phoneNumbers: List<PhoneNumber>? = null
private var physicalAddresses: List<PhysicalAddress>? = null
private var suffix: String? = null
private var surname: String? = null
private var webPages: List<WebPage>? = null
private var picture: String? = null
private var source: SourceType? = null
private var groups: List<ContactGroupId>? = null

fun displayName(displayName: String?) = apply { this.displayName = displayName }
fun birthday(birthday: String?) = apply { this.birthday = birthday }
fun companyName(companyName: String?) = apply { this.companyName = companyName }
fun emails(emails: List<ContactEmail>?) = apply { this.emails = emails }
fun givenName(givenName: String?) = apply { this.givenName = givenName }
fun imAddresses(imAddresses: List<InstantMessagingAddress>?) = apply { this.imAddresses = imAddresses }
fun jobTitle(jobTitle: String?) = apply { this.jobTitle = jobTitle }
fun managerName(managerName: String?) = apply { this.managerName = managerName }
fun middleName(middleName: String?) = apply { this.middleName = middleName }
fun nickname(nickname: String?) = apply { this.nickname = nickname }
fun notes(notes: String?) = apply { this.notes = notes }
fun officeLocation(officeLocation: String?) = apply { this.officeLocation = officeLocation }
fun phoneNumbers(phoneNumbers: List<PhoneNumber>?) = apply { this.phoneNumbers = phoneNumbers }
fun physicalAddresses(physicalAddresses: List<PhysicalAddress>?) = apply { this.physicalAddresses = physicalAddresses }
fun suffix(suffix: String?) = apply { this.suffix = suffix }
fun surname(surname: String?) = apply { this.surname = surname }
fun webPages(webPages: List<WebPage>?) = apply { this.webPages = webPages }
fun picture(picture: String?) = apply { this.picture = picture }
fun source(source: SourceType?) = apply { this.source = source }
fun groups(groups: List<ContactGroupId>?) = apply { this.groups = groups }

fun build() = CreateContactRequest(
displayName = displayName,
birthday = birthday,
companyName = companyName,
emails = emails,
givenName = givenName,
imAddresses = imAddresses,
jobTitle = jobTitle,
managerName = managerName,
middleName = middleName,
nickname = nickname,
notes = notes,
officeLocation = officeLocation,
phoneNumbers = phoneNumbers,
physicalAddresses = physicalAddresses,
suffix = suffix,
surname = surname,
webPages = webPages,
picture = picture,
source = source,
groups = groups,
)
}
}
8 changes: 8 additions & 0 deletions src/main/kotlin/com/nylas/models/FindContactQueryParams.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nylas.models

import com.squareup.moshi.Json

data class FindContactQueryParams(
@Json(name = "profile_picture")
val profilePicture: Boolean? = null,
) : IQueryParams
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nylas/models/GroupType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.nylas.models

import com.squareup.moshi.Json

enum class GroupType {
@Json(name = "user")
USER,

@Json(name = "system")
SYSTEM,

@Json(name = "other")
OTHER,
}
18 changes: 18 additions & 0 deletions src/main/kotlin/com/nylas/models/InstantMessagingAddress.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.nylas.models

/**
* Class representation for an IM address in a contact.
*/
data class InstantMessagingAddress(
val imAddress: String? = null,
val type: ContactType? = null,
) {
class Builder {
private var imAddress: String? = null
private var type: ContactType? = null

fun imAddress(imAddress: String) = apply { this.imAddress = imAddress }
fun type(type: ContactType) = apply { this.type = type }
fun build() = InstantMessagingAddress(imAddress, type)
}
}
Loading

0 comments on commit 45bd2d3

Please sign in to comment.