From 0395541cea0976a5ab3b25df15541ec643f135ea Mon Sep 17 00:00:00 2001 From: samuelsallee <76776702+samuelsallee@users.noreply.github.com> Date: Sat, 5 Sep 2026 15:38:10 +0700 Subject: [PATCH 1/2] added client.scheduler.get_availability function --- nylas/models/scheduler.py | 24 ++++++++++++++++++++++++ nylas/resources/scheduler.py | 25 +++++++++++++++++++++++++ tests/resources/test_scheduler.py | 20 ++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 tests/resources/test_scheduler.py diff --git a/nylas/models/scheduler.py b/nylas/models/scheduler.py index 155e244..09ae44c 100644 --- a/nylas/models/scheduler.py +++ b/nylas/models/scheduler.py @@ -530,3 +530,27 @@ 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..36cdddc 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,24 @@ 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..4320c40 --- /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, + ) From dac4511e57011039735527c677343b9b6e2126b8 Mon Sep 17 00:00:00 2001 From: samuelsallee <76776702+samuelsallee@users.noreply.github.com> Date: Sat, 5 Sep 2026 16:08:39 +0700 Subject: [PATCH 2/2] ran black and pylint --- nylas/models/scheduler.py | 11 +++++++---- nylas/resources/scheduler.py | 9 ++++++--- tests/resources/test_scheduler.py | 28 ++++++++++++++-------------- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/nylas/models/scheduler.py b/nylas/models/scheduler.py index 09ae44c..025a994 100644 --- a/nylas/models/scheduler.py +++ b/nylas/models/scheduler.py @@ -531,23 +531,26 @@ class 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. + 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. + 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] diff --git a/nylas/resources/scheduler.py b/nylas/resources/scheduler.py index 36cdddc..08da694 100644 --- a/nylas/resources/scheduler.py +++ b/nylas/resources/scheduler.py @@ -44,8 +44,12 @@ def sessions(self) -> Sessions: The Sessions API. """ return Sessions(self.http_client) - - def get_availability(self, query_params: GetAvailabilityQueryParams, overrides: RequestOverrides = None) -> Response[GetAvailabilityResponse]: + + def get_availability( + self, + query_params: GetAvailabilityQueryParams, + overrides: RequestOverrides = None, + ) -> Response[GetAvailabilityResponse]: """ Get availability for a Configuration. @@ -64,4 +68,3 @@ def get_availability(self, query_params: GetAvailabilityQueryParams, overrides: ) return Response.from_dict(json_response, GetAvailabilityResponse, headers) - diff --git a/tests/resources/test_scheduler.py b/tests/resources/test_scheduler.py index 4320c40..f98c88e 100644 --- a/tests/resources/test_scheduler.py +++ b/tests/resources/test_scheduler.py @@ -2,19 +2,19 @@ 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", - } + 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) + 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, - ) + http_client_response._execute.assert_called_once_with( + "GET", + "/v3/scheduling/availability", + query_params=query_params, + overrides=None, + )