-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# Description This PR adds support for the free busy endpoint. # 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
1 parent
a4f802e
commit 0157f4b
Showing
7 changed files
with
163 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.nylas.models | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* Class representation of a Nylas free-busy time slot object. | ||
*/ | ||
data class FreeBusyTimeSlot( | ||
/** | ||
* Unix timestamp for the start of the slot. | ||
*/ | ||
@Json(name = "start_time") | ||
val startTime: Int, | ||
/** | ||
* Unix timestamp for the end of the slot. | ||
*/ | ||
@Json(name = "end_time") | ||
val endTime: Int, | ||
/** | ||
* The status of the time slot. | ||
*/ | ||
@Json(name = "status") | ||
val status: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.nylas.models | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* Enum representing the type of free/busy information returned for a calendar. | ||
*/ | ||
enum class FreeBusyType(val value: String) { | ||
@Json(name = "free_busy") | ||
FREE_BUSY("free_busy"), | ||
|
||
@Json(name = "error") | ||
ERROR("error"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.nylas.models | ||
|
||
import com.squareup.moshi.Json | ||
|
||
/** | ||
* Class representation of a Nylas get free-busy request | ||
*/ | ||
data class GetFreeBusyRequest( | ||
/** | ||
* Unix timestamp representing the start of the time block for assessing the account's free/busy schedule. | ||
*/ | ||
@Json(name = "start_time") | ||
val startTime: Int, | ||
/** | ||
* Unix timestamp representing the end of the time block for assessing the account's free/busy schedule. | ||
*/ | ||
@Json(name = "end_time") | ||
val endTime: Int, | ||
/** | ||
* A list of email addresses to check the free/busy schedules for. | ||
*/ | ||
@Json(name = "emails") | ||
val emails: List<String>, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.nylas.models | ||
|
||
import com.nylas.util.JsonHelper | ||
import com.squareup.moshi.Json | ||
import com.squareup.moshi.JsonAdapter | ||
import com.squareup.moshi.adapters.PolymorphicJsonAdapterFactory | ||
|
||
/** | ||
* Class representation of a Nylas get free busy response. | ||
* It can be either a [FreeBusy] or a [FreeBusyError]. | ||
*/ | ||
sealed class GetFreeBusyResponse { | ||
/** | ||
* The type of the response. | ||
*/ | ||
@Json(name = "object") | ||
protected open val obj: FreeBusyType? = null | ||
|
||
/** | ||
* The participant's email address. | ||
*/ | ||
@Json(name = "email") | ||
abstract val email: String | ||
|
||
/** | ||
* This class represents a successful free-busy response. | ||
*/ | ||
data class FreeBusy( | ||
/** | ||
* A list of busy time slots. | ||
*/ | ||
@Json(name = "time_slots") | ||
val timeSlots: List<FreeBusyTimeSlot>, | ||
@Json(name = "object") | ||
override val obj: FreeBusyType = FreeBusyType.FREE_BUSY, | ||
@Json(name = "email") | ||
override val email: String, | ||
) : GetFreeBusyResponse() | ||
|
||
/** | ||
* This class represents a failed free-busy response. | ||
*/ | ||
data class FreeBusyError( | ||
/** | ||
* Description of the error fetching data for this participant. | ||
*/ | ||
@Json(name = "error") | ||
val error: String, | ||
@Json(name = "object") | ||
override val obj: FreeBusyType = FreeBusyType.ERROR, | ||
@Json(name = "email") | ||
override val email: String, | ||
) : GetFreeBusyResponse() | ||
|
||
companion object { | ||
/** | ||
* A JsonAdapter factory for the [GetFreeBusyResponse] sealed class (used for deserialization). | ||
* @suppress Not for public use. | ||
*/ | ||
@JvmStatic | ||
val FREE_BUSY_JSON_FACTORY: JsonAdapter.Factory = PolymorphicJsonAdapterFactory.of(GetFreeBusyResponse::class.java, "object") | ||
.withSubtype(FreeBusy::class.java, FreeBusyType.FREE_BUSY.value) | ||
.withSubtype(FreeBusyError::class.java, FreeBusyType.ERROR.value) | ||
|
||
/** | ||
* A JsonAdapter for the [GetFreeBusyResponse] sealed class (used for serialization). | ||
* @suppress Not for public use. | ||
*/ | ||
@JvmStatic | ||
val GET_FREE_BUSY_RESPONSE_ADAPTER = JsonHelper.listTypeOf(GetFreeBusyResponse::class.java) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters