diff --git a/nylas/models/scheduler.py b/nylas/models/scheduler.py index 155e244..025a994 100644 --- a/nylas/models/scheduler.py +++ b/nylas/models/scheduler.py @@ -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] diff --git a/nylas/resources/scheduler.py b/nylas/resources/scheduler.py index e337de4..08da694 100644 --- a/nylas/resources/scheduler.py +++ b/nylas/resources/scheduler.py @@ -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 @@ -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) diff --git a/tests/resources/test_scheduler.py b/tests/resources/test_scheduler.py new file mode 100644 index 0000000..f98c88e --- /dev/null +++ b/tests/resources/test_scheduler.py @@ -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, + )