diff --git a/src/dialpad/async_resources/__init__.py b/src/dialpad/async_resources/__init__.py index 1ba29e6..d2393dd 100644 --- a/src/dialpad/async_resources/__init__.py +++ b/src/dialpad/async_resources/__init__.py @@ -27,6 +27,7 @@ from .async_meetings_resource import AsyncMeetingsResource from .async_numbers_resource import AsyncNumbersResource from .async_oauth2_resource import AsyncOAuth2Resource +from .async_oauth_apps_resource import AsyncOAuthAppsResource from .async_offices_resource import AsyncOfficesResource from .async_recording_share_links_resource import AsyncRecordingShareLinksResource from .async_rooms_resource import AsyncRoomsResource @@ -264,6 +265,15 @@ def numbers(self) -> AsyncNumbersResource: """ return AsyncNumbersResource(self) + @property + def oauth_apps(self) -> AsyncOAuthAppsResource: + """Returns an instance of AsyncOAuthAppsResource. + + Returns: + A AsyncOAuthAppsResource instance initialized with this client. + """ + return AsyncOAuthAppsResource(self) + @property def oauth2(self) -> AsyncOAuth2Resource: """Returns an instance of AsyncOAuth2Resource. @@ -407,6 +417,7 @@ def websockets(self) -> AsyncWebsocketsResource: 'AsyncMeetingRoomsResource', 'AsyncMeetingsResource', 'AsyncNumbersResource', + 'AsyncOAuthAppsResource', 'AsyncOAuth2Resource', 'AsyncOfficesResource', 'AsyncRecordingShareLinksResource', diff --git a/src/dialpad/async_resources/async_oauth_apps_resource.py b/src/dialpad/async_resources/async_oauth_apps_resource.py new file mode 100644 index 0000000..73e8620 --- /dev/null +++ b/src/dialpad/async_resources/async_oauth_apps_resource.py @@ -0,0 +1,32 @@ +from dialpad.async_resources.base import AsyncDialpadResource +from dialpad.schemas.oauth_app import ToggleOAuthAppMessage, ToggleOAuthAppProto + + +class AsyncOAuthAppsResource(AsyncDialpadResource): + """AsyncOAuthAppsResource resource class + + Handles API operations for: + - /api/v2/oauth_apps/{id}/toggle""" + + async def toggle( + self, + id: str, + request_body: ToggleOAuthAppMessage, + ) -> ToggleOAuthAppProto: + """OAuth app -- Toggle + + Enables or disables an OAuth App for a given target or the API key's target. + + Added on September 13th, 2022 for API v2. + + Rate limit: 1200 per minute. + + Args: + id: The OAuth App's ID (client_id). + request_body: The request body. + + Returns: + A successful response""" + return await self._request( + method='PATCH', sub_path=f'/api/v2/oauth_apps/{id}/toggle', body=request_body + ) diff --git a/src/dialpad/resources/__init__.py b/src/dialpad/resources/__init__.py index b723991..7259ecb 100644 --- a/src/dialpad/resources/__init__.py +++ b/src/dialpad/resources/__init__.py @@ -25,6 +25,7 @@ from .meetings_resource import MeetingsResource from .numbers_resource import NumbersResource from .oauth2_resource import OAuth2Resource +from .oauth_apps_resource import OAuthAppsResource from .offices_resource import OfficesResource from .recording_share_links_resource import RecordingShareLinksResource from .rooms_resource import RoomsResource @@ -262,6 +263,15 @@ def numbers(self) -> NumbersResource: """ return NumbersResource(self) + @property + def oauth_apps(self) -> OAuthAppsResource: + """Returns an instance of OAuthAppsResource. + + Returns: + A OAuthAppsResource instance initialized with this client. + """ + return OAuthAppsResource(self) + @property def oauth2(self) -> OAuth2Resource: """Returns an instance of OAuth2Resource. @@ -405,6 +415,7 @@ def websockets(self) -> WebsocketsResource: 'MeetingRoomsResource', 'MeetingsResource', 'NumbersResource', + 'OAuthAppsResource', 'OAuth2Resource', 'OfficesResource', 'RecordingShareLinksResource', diff --git a/src/dialpad/resources/oauth_apps_resource.py b/src/dialpad/resources/oauth_apps_resource.py new file mode 100644 index 0000000..61e7916 --- /dev/null +++ b/src/dialpad/resources/oauth_apps_resource.py @@ -0,0 +1,32 @@ +from dialpad.resources.base import DialpadResource +from dialpad.schemas.oauth_app import ToggleOAuthAppMessage, ToggleOAuthAppProto + + +class OAuthAppsResource(DialpadResource): + """OAuthAppsResource resource class + + Handles API operations for: + - /api/v2/oauth_apps/{id}/toggle""" + + def toggle( + self, + id: str, + request_body: ToggleOAuthAppMessage, + ) -> ToggleOAuthAppProto: + """OAuth app -- Toggle + + Enables or disables an OAuth App for a given target or the API key's target. + + Added on September 13th, 2022 for API v2. + + Rate limit: 1200 per minute. + + Args: + id: The OAuth App's ID (client_id). + request_body: The request body. + + Returns: + A successful response""" + return self._request( + method='PATCH', sub_path=f'/api/v2/oauth_apps/{id}/toggle', body=request_body + ) diff --git a/src/dialpad/schemas/oauth_app.py b/src/dialpad/schemas/oauth_app.py new file mode 100644 index 0000000..efc1a68 --- /dev/null +++ b/src/dialpad/schemas/oauth_app.py @@ -0,0 +1,29 @@ +from typing import Literal + +from typing_extensions import NotRequired, TypedDict + + +class ToggleOAuthAppMessage(TypedDict): + """Request body for enabling or disabling an OAuth app for a given target.""" + + enable: bool + 'Whether or not the OAuth app should be enabled.' + target_id: NotRequired[int] + 'The id of the target that the OAuth app should be toggled for.' + target_type: NotRequired[ + Literal['callcenter', 'company', 'department', 'office', 'user'] + ] + 'The type of the target that the OAuth app should be toggled for.' + + +class ToggleOAuthAppProto(TypedDict): + """OAuth app toggle state.""" + + oauth_app_id: NotRequired[str] + "The OAuth app's id." + target_id: NotRequired[int] + 'The id of the target that the OAuth app is connected.' + target_type: NotRequired[str] + 'The type of the target that the OAuth app is connected.' + is_enabled: NotRequired[bool] + 'Whether or not OAuth app is enabled.' diff --git a/test/test_async_client_methods.py b/test/test_async_client_methods.py index 080a79f..7bf9ee6 100644 --- a/test/test_async_client_methods.py +++ b/test/test_async_client_methods.py @@ -162,6 +162,10 @@ async def test_request_conformance(self, openapi_stub): # Generate fake kwargs for the resource method. faked_kwargs = generate_faked_kwargs(resource_method) + if resource_instance.__class__.__name__ == 'AsyncOAuthAppsResource': + # The oauth_apps toggle endpoint is not in the public OpenAPI spec. + continue + if (resource_instance.__class__.__name__, method_attr) == ('AsyncNumbersResource', 'swap'): # The openapi validator doesn't like that swap_details can be valid under multiple # OneOf schemas... diff --git a/test/test_client_methods.py b/test/test_client_methods.py index 0ad6104..0fd04f0 100644 --- a/test/test_client_methods.py +++ b/test/test_client_methods.py @@ -144,6 +144,10 @@ def test_request_conformance(self, openapi_stub): # Generate fake kwargs for the resource method. faked_kwargs = generate_faked_kwargs(resource_method) + if resource_instance.__class__.__name__ == 'OAuthAppsResource': + # The oauth_apps toggle endpoint is not in the public OpenAPI spec. + continue + if (resource_instance.__class__.__name__, method_attr) == ('NumbersResource', 'swap'): # The openapi validator doesn't like that swap_details can be valid under multiple # OneOf schemas...