Skip to content

Commit 4345f79

Browse files
TW-4624: Add specific_time_availability to AvailabilityParticipant
Add support for specific_time_availability field in the /calendars/availability POST API. This allows overriding open_hours for specific dates. Changes: - Added SpecificTimeAvailability TypedDict with date, start, and end fields - Added specific_time_availability field to AvailabilityParticipant - Updated and added unit tests for availability endpoint Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 2deab36 commit 4345f79

File tree

2 files changed

+78
-18
lines changed

2 files changed

+78
-18
lines changed

nylas/models/availability.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ class OpenHours(TypedDict):
7777
exdates: NotRequired[List[str]]
7878

7979

80+
class SpecificTimeAvailability(TypedDict):
81+
"""
82+
Interface of a participant's availability for specific dates.
83+
Overrides open_hours for the specified dates.
84+
85+
Attributes:
86+
dates: The date in ISO 8601 format.
87+
start: Start time in 24-hour time format. Leading 0's are left off.
88+
end: End time in 24-hour time format. Leading 0's are left off.
89+
"""
90+
91+
date: str
92+
start: str
93+
end: str
94+
95+
8096
class AvailabilityRules(TypedDict):
8197
"""
8298
Interface for the availability rules for a Nylas calendar.
@@ -111,11 +127,14 @@ class AvailabilityParticipant(TypedDict):
111127
calendar_ids: An optional list of the calendar IDs associated with each participant's email address.
112128
If not provided, Nylas uses the primary calendar ID.
113129
open_hours: Open hours for this participant. The endpoint searches for free time slots during these open hours.
130+
specific_time_availability: Specific availability for this participant that overrides open_hours
131+
for the specified dates.
114132
"""
115133

116134
email: str
117135
calendar_ids: NotRequired[List[str]]
118136
open_hours: NotRequired[List[OpenHours]]
137+
specific_time_availability: NotRequired[List[SpecificTimeAvailability]]
119138

120139

121140
class GetAvailabilityRequest(TypedDict):

tests/resources/test_calendars.py

Lines changed: 59 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -320,31 +320,23 @@ def test_get_availability(self, http_client_response):
320320
request_body = {
321321
"start_time": 1497916800,
322322
"end_time": 1498003200,
323-
"duration_minutes": 30,
323+
"duration_minutes": 60,
324324
"interval_minutes": 30,
325-
"free_busy": [
325+
"round_to_30_minutes": True,
326+
"participants": [
326327
{
327328
"email": "test@gmail.com",
328-
}
329-
],
330-
"open_hours": [
331-
{
332-
"days": ["monday", "wednesday"],
333-
"timezone": "America/New_York",
334-
"start": "08:00",
335-
"end": "18:00",
336-
"restrictions": [
329+
"calendar_ids": ["primary"],
330+
"open_hours": [
337331
{
338-
"days": ["monday"],
339-
"start": "12:00",
340-
"end": "13:00",
332+
"days": [1, 3],
333+
"timezone": "America/New_York",
334+
"start": "08:00",
335+
"end": "18:00",
341336
}
342337
],
343338
}
344339
],
345-
"duration_minutes": 60,
346-
"interval_minutes": 30,
347-
"round_to_30_minutes": True,
348340
"availability_rules": {
349341
"availability_method": "max-availability",
350342
"buffer": {"before": 10, "after": 10},
@@ -362,7 +354,56 @@ def test_get_availability(self, http_client_response):
362354
},
363355
}
364356

365-
calendars.get_availability(request_body,overrides=None,)
357+
calendars.get_availability(request_body, overrides=None)
358+
359+
http_client_response._execute.assert_called_once_with(
360+
"POST",
361+
"/v3/calendars/availability",
362+
None,
363+
None,
364+
request_body,
365+
overrides=None,
366+
)
367+
368+
def test_get_availability_with_specific_time_availability(self, http_client_response):
369+
calendars = Calendars(http_client_response)
370+
request_body = {
371+
"start_time": 1497916800,
372+
"end_time": 1498003200,
373+
"duration_minutes": 60,
374+
"interval_minutes": 30,
375+
"participants": [
376+
{
377+
"email": "test@gmail.com",
378+
"calendar_ids": ["primary"],
379+
"open_hours": [
380+
{
381+
"days": [1, 2, 3, 4, 5],
382+
"timezone": "America/New_York",
383+
"start": "9:00",
384+
"end": "17:00",
385+
}
386+
],
387+
"specific_time_availability": [
388+
{
389+
"date": "2024-03-15",
390+
"start": "10:00",
391+
"end": "14:00",
392+
},
393+
{
394+
"date": "2024-03-16",
395+
"start": "10:00",
396+
"end": "14:00",
397+
}
398+
],
399+
}
400+
],
401+
"availability_rules": {
402+
"availability_method": "max-availability",
403+
},
404+
}
405+
406+
calendars.get_availability(request_body, overrides=None)
366407

367408
http_client_response._execute.assert_called_once_with(
368409
"POST",

0 commit comments

Comments
 (0)