Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contacts API support #183

Merged
merged 5 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Added
* Added support for sending drafts
* Added support for the contacts API

### Changed
* Fixed issue with sending scheduled messages
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,
)
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nylas/models/ContactType.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 ContactType {
@Json(name = "work")
WORK,

@Json(name = "home")
HOME,

@Json(name = "other")
OTHER,
}
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
12 changes: 12 additions & 0 deletions src/main/kotlin/com/nylas/models/GroupType.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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)
}
}
48 changes: 48 additions & 0 deletions src/main/kotlin/com/nylas/models/ListContactGroupsQueryParams.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.nylas.models

import com.squareup.moshi.Json

data class ListContactGroupsQueryParams(
/**
* The maximum number of objects to return.
* This field defaults to 50. The maximum allowed value is 200.
*/
@Json(name = "limit")
val limit: Int? = null,
/**
* An identifier that specifies which page of data to return.
* This value should be taken from the [ListResponse.nextCursor] response field.
*/
@Json(name = "page_token")
val pageToken: String? = null,
) : IQueryParams {
/**
* Builder for [ListContactGroupsQueryParams].
*/
class Builder {
private var limit: Int? = null
private var pageToken: String? = null

/**
* Set the maximum number of objects to return.
* This field defaults to 50. The maximum allowed value is 200.
* @param limit The maximum number of objects to return.
* @return The builder.
*/
fun limit(limit: Int?) = apply { this.limit = limit }

/**
* Set the identifier that specifies which page of data to return.
* This value should be taken from the [ListResponse.nextCursor] response field.
* @param pageToken The identifier that specifies which page of data to return.
* @return The builder.
*/
fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken }

/**
* Build the [ListContactGroupsQueryParams] object.
* @return The [ListContactGroupsQueryParams] object.
*/
fun build() = ListContactGroupsQueryParams(limit, pageToken)
}
}
Loading
Loading