Skip to content

Commit

Permalink
Contacts API support (#183)
Browse files Browse the repository at this point in the history
# Description
This PR adds support for the contacts API.

# 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 Jan 3, 2024
1 parent db64b95 commit 43da3ba
Show file tree
Hide file tree
Showing 18 changed files with 720 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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

0 comments on commit 43da3ba

Please sign in to comment.