Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions nylas/models/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,3 +530,30 @@ class FindBookingQueryParams:
ConfirmBookingQueryParams = FindBookingQueryParams
RescheduleBookingQueryParams = FindBookingQueryParams
DestroyBookingQueryParams = FindBookingQueryParams


class GetAvailabilityQueryParams(TypedDict):
"""
Class representation of query parameters for getting the availability for a Scheduler Configuration.

Attributes:
start_time: The time from which to check availability, in seconds using the Unix timestamp format.
end_time: The time until which to check availability, in seconds using the Unix timestamp format.
configuration_id: The ID of the Configuration object used for calculating availability.
If you're using session authentication (requires_session_auth: true), the configuration_id isn't required.
slug: The Configuration object slug. You can use this with the client_id instead of using the configuration_id.
If you're using session authentication (requires_session_auth: true) or using the configuration_id,
slug isn't required.
client_id: The client ID that was used to create the Configuration object.
Required only if you're using slug.
booking_id: The ID of the booking to reschedule, if you're checking availability to reschedule a round-robin
booking.Required only if availability_method is max-fairness or max-availability.

"""

start_time: int
end_time: int
configuration_id: NotRequired[str]
slug: NotRequired[str]
client_id: NotRequired[str]
booking_id: NotRequired[str]
28 changes: 28 additions & 0 deletions nylas/resources/scheduler.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
from nylas.config import RequestOverrides
from nylas.models.availability import GetAvailabilityResponse
from nylas.models.response import Response
from nylas.models.scheduler import GetAvailabilityQueryParams
from nylas.resources.bookings import Bookings
from nylas.resources.configurations import Configurations
from nylas.resources.sessions import Sessions
Expand Down Expand Up @@ -40,3 +44,27 @@ def sessions(self) -> Sessions:
The Sessions API.
"""
return Sessions(self.http_client)

def get_availability(
self,
query_params: GetAvailabilityQueryParams,
overrides: RequestOverrides = None,
) -> Response[GetAvailabilityResponse]:
"""
Get availability for a Configuration.

Args:
query_params: The query parameters to include in the request.
overrides: The request overrides to use for the request.

Returns:
Response: The availability response from the API.
"""
json_response, headers = self.http_client._execute(
"GET",
"/v3/scheduling/availability",
query_params=query_params,
overrides=overrides,
)

return Response.from_dict(json_response, GetAvailabilityResponse, headers)
20 changes: 20 additions & 0 deletions tests/resources/test_scheduler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from nylas.resources.scheduler import Scheduler


class TestScheduler:
def test_get_availability(self, http_client_response):
scheduler = Scheduler(http_client_response)
query_params = {
"start_time": 1730725200,
"end_time": 1730727000,
"configuration_id": "configuration-123",
}

scheduler.get_availability(query_params=query_params)

http_client_response._execute.assert_called_once_with(
"GET",
"/v3/scheduling/availability",
query_params=query_params,
overrides=None,
)