Skip to content

Commit cb934cd

Browse files
authored
feat: add support for listing import events via events.listImportEvents() (#266)
# Background Adding support for the `GET /v3/grants/{grant_id}/events/import` endpoint (https://developer.nylas.com/docs/api/v3/ecc/#get-/v3/grants/-grant_id-/events/import) # 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.
1 parent 5d0a7fd commit cb934cd

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Nylas Java SDK Changelog
22

3+
### [Unreleased]
4+
* Added support for listing import events via `events.listImportEvents()`
5+
36
### [2.6.0] - Released 2025-01-24
47
* Made `NylasClient` and its methods open to enable mocking in tests
58
* Added pagination support for folders
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package com.nylas.models
2+
3+
import com.squareup.moshi.Json
4+
5+
/**
6+
* Class representation of the query parameters for listing import events.
7+
*/
8+
data class ListImportEventQueryParams(
9+
/**
10+
* Filter for the specified calendar ID.
11+
* (Not supported for iCloud) You can use primary to query the end user's primary calendar.
12+
* This is a required parameter.
13+
*/
14+
@Json(name = "calendar_id")
15+
val calendarId: String,
16+
/**
17+
* The maximum number of objects to return.
18+
* This field defaults to 50. The maximum allowed value is 500.
19+
*/
20+
@Json(name = "limit")
21+
val limit: Int? = null,
22+
/**
23+
* An identifier that specifies which page of data to return.
24+
* This value should be taken from the [ListResponse.nextCursor] response field.
25+
*/
26+
@Json(name = "page_token")
27+
val pageToken: String? = null,
28+
/**
29+
* Filter for events that start at or after the specified time, in Unix timestamp format.
30+
* Defaults to the time that you make the request.
31+
*/
32+
@Json(name = "start")
33+
val start: Int? = null,
34+
/**
35+
* Filter for events that end at or before the specified time, in Unix timestamp format.
36+
* Defaults to one month from the time you make the request.
37+
*/
38+
@Json(name = "end")
39+
val end: Int? = null,
40+
/**
41+
* Specify fields that you want Nylas to return, as a comma-separated list.
42+
* This allows you to receive only the portion of object data that you're interested in.
43+
*/
44+
@Json(name = "select")
45+
val select: String? = null,
46+
) : IQueryParams {
47+
/**
48+
* Builder for [ListImportEventQueryParams].
49+
*/
50+
data class Builder(
51+
/**
52+
* Filter for the specified calendar ID.
53+
* (Not supported for iCloud) You can use primary to query the end user's primary calendar.
54+
* This is a required parameter.
55+
*/
56+
private val calendarId: String,
57+
) {
58+
private var limit: Int? = null
59+
private var pageToken: String? = null
60+
private var start: Int? = null
61+
private var end: Int? = null
62+
private var select: String? = null
63+
64+
/**
65+
* Sets the maximum number of objects to return.
66+
* This field defaults to 50. The maximum allowed value is 500.
67+
* @param limit The maximum number of objects to return.
68+
* @return The builder.
69+
*/
70+
fun limit(limit: Int?) = apply { this.limit = limit }
71+
72+
/**
73+
* Sets the identifier that specifies which page of data to return.
74+
* This value should be taken from the [ListResponse.nextCursor] response field.
75+
* @param pageToken The identifier that specifies which page of data to return.
76+
* @return The builder.
77+
*/
78+
fun pageToken(pageToken: String?) = apply { this.pageToken = pageToken }
79+
80+
/**
81+
* Sets the start time to filter events by.
82+
* Filter for events that start at or after the specified time, in Unix timestamp format.
83+
* @param start The start time to filter events by.
84+
* @return The builder.
85+
*/
86+
fun start(start: Int?) = apply { this.start = start }
87+
88+
/**
89+
* Sets the end time to filter events by.
90+
* Filter for events that end at or before the specified time, in Unix timestamp format.
91+
* @param end The end time to filter events by.
92+
* @return The builder.
93+
*/
94+
fun end(end: Int?) = apply { this.end = end }
95+
96+
/**
97+
* Sets the fields to return in the response.
98+
* Specify fields that you want Nylas to return, as a comma-separated list.
99+
* @param select The fields to return in the response.
100+
* @return The builder.
101+
*/
102+
fun select(select: String?) = apply { this.select = select }
103+
104+
/**
105+
* Builds a [ListImportEventQueryParams] instance.
106+
* @return The [ListImportEventQueryParams] instance.
107+
*/
108+
fun build() = ListImportEventQueryParams(
109+
calendarId,
110+
limit,
111+
pageToken,
112+
start,
113+
end,
114+
select,
115+
)
116+
}
117+
}

src/main/kotlin/com/nylas/resources/Events.kt

+17
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ class Events(client: NylasClient) : Resource<Event>(client, Event::class.java) {
2626
return listResource(path, queryParams, overrides)
2727
}
2828

29+
/**
30+
* Returns a list of recurring events, recurring event exceptions,
31+
* and single events from the specified calendar within a given time frame.
32+
* This is useful when you want to import, store, and synchronize events
33+
* from the time frame to your application
34+
* @param identifier Grant ID or email account to query
35+
* @param queryParams The query parameters to include in the request (must include calendar_id)
36+
* @param overrides Optional request overrides to apply
37+
* @return The list of import events
38+
*/
39+
@Throws(NylasApiError::class, NylasSdkTimeoutError::class)
40+
@JvmOverloads
41+
fun listImportEvents(identifier: String, queryParams: ListImportEventQueryParams, overrides: RequestOverrides? = null): ListResponse<Event> {
42+
val path = String.format("v3/grants/%s/events/import", identifier)
43+
return listResource(path, queryParams, overrides)
44+
}
45+
2946
/**
3047
* Return an Event
3148
* @param identifier Grant ID or email account to query

src/test/kotlin/com/nylas/resources/EventsTests.kt

+29
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,35 @@ class EventsTests {
245245
assertEquals(Types.newParameterizedType(ListResponse::class.java, Event::class.java), typeCaptor.firstValue)
246246
}
247247

248+
@Test
249+
fun `listing import events calls requests with the correct params`() {
250+
val listImportEventQueryParams =
251+
ListImportEventQueryParams.Builder("calendar-id")
252+
.limit(50)
253+
.pageToken("next-page-token")
254+
.start(1620000000)
255+
.end(1620100000)
256+
.select("id,title,when")
257+
.build()
258+
259+
events.listImportEvents(grantId, listImportEventQueryParams)
260+
261+
val pathCaptor = argumentCaptor<String>()
262+
val typeCaptor = argumentCaptor<Type>()
263+
val queryParamCaptor = argumentCaptor<ListImportEventQueryParams>()
264+
val overrideParamCaptor = argumentCaptor<RequestOverrides>()
265+
verify(mockNylasClient).executeGet<ListResponse<Event>>(
266+
pathCaptor.capture(),
267+
typeCaptor.capture(),
268+
queryParamCaptor.capture(),
269+
overrideParamCaptor.capture(),
270+
)
271+
272+
assertEquals("v3/grants/$grantId/events/import", pathCaptor.firstValue)
273+
assertEquals(Types.newParameterizedType(ListResponse::class.java, Event::class.java), typeCaptor.firstValue)
274+
assertEquals(listImportEventQueryParams, queryParamCaptor.firstValue)
275+
}
276+
248277
@Test
249278
fun `finding a event calls requests with the correct params`() {
250279
val eventId = "event-123"

0 commit comments

Comments
 (0)