Skip to content

Commit

Permalink
Fixes for contacts api support (#185)
Browse files Browse the repository at this point in the history
This PR add some fixed and contact creation.

https://nylas.atlassian.net/browse/TW-2468

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
atejada authored Jan 3, 2024
1 parent 43da3ba commit de6b593
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 12 deletions.
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 @@ -167,6 +167,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
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/Contact.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ data class Contact(
val groups: List<ContactGroupId>? = null,
) {
fun getObject() = obj
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/ContactEmail.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ data class ContactEmail(
fun type(type: ContactType) = apply { this.type = type }
fun build() = ContactEmail(email, type)
}
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/ContactGroup.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ data class ContactGroup(
private val obj: String = "contact_group",
) {
fun getObject() = obj
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/ContactGroupId.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ package com.nylas.models
*/
data class ContactGroupId(
val id: String,
)
)
5 changes: 4 additions & 1 deletion src/main/kotlin/com/nylas/models/ContactType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ enum class ContactType {

@Json(name = "other")
OTHER,
}

@Json(name = "mobile")
MOBILE,
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/nylas/models/FindContactQueryParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ import com.squareup.moshi.Json
data class FindContactQueryParams(
@Json(name = "profile_picture")
val profilePicture: Boolean? = null,
): IQueryParams
) : IQueryParams
6 changes: 4 additions & 2 deletions src/main/kotlin/com/nylas/models/GroupType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.squareup.moshi.Json
enum class GroupType {
@Json(name = "user")
USER,

@Json(name = "system")
SYSTEM,

@Json(name = "other")
OTHER
}
OTHER,
}
4 changes: 2 additions & 2 deletions src/main/kotlin/com/nylas/models/ListContactsQueryParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ data class ListContactsQueryParams(
*/
@Json(name = "recurse")
val recurse: Boolean? = null,
): IQueryParams {
) : IQueryParams {
class Builder {
private var limit: Int? = null
private var pageToken: String? = null
Expand Down Expand Up @@ -120,4 +120,4 @@ data class ListContactsQueryParams(
recurse = recurse,
)
}
}
}
6 changes: 4 additions & 2 deletions src/main/kotlin/com/nylas/models/SourceType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import com.squareup.moshi.Json
enum class SourceType {
@Json(name = "address_book")
ADDRESS_BOOK,

@Json(name = "inbox")
INBOX,

@Json(name = "domain")
DOMAIN
}
DOMAIN,
}
14 changes: 14 additions & 0 deletions src/main/kotlin/com/nylas/resources/Contacts.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ class Contacts(client: NylasClient) : Resource<Contact>(client, Contact::class.j
return findResource(path)
}

/**
* Create a Contact
* @param identifier Grant ID or email account in which to create the object
* @param requestBody The values to create the event with
* @return The created contact
*/
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
fun create(identifier: String, requestBody: CreateContactRequest): Response<Contact> {
val path = String.format("v3/grants/%s/contacts", identifier)
val adapter = JsonHelper.moshi().adapter(CreateContactRequest::class.java)
val serializedRequestBody = adapter.toJson(requestBody)
return createResource(path, serializedRequestBody)
}

/**
* Update a Contact
* @param identifier The identifier of the grant to act upon
Expand Down

0 comments on commit de6b593

Please sign in to comment.