Skip to content
Merged
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
11 changes: 11 additions & 0 deletions src/dialpad/async_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -407,6 +417,7 @@ def websockets(self) -> AsyncWebsocketsResource:
'AsyncMeetingRoomsResource',
'AsyncMeetingsResource',
'AsyncNumbersResource',
'AsyncOAuthAppsResource',
'AsyncOAuth2Resource',
'AsyncOfficesResource',
'AsyncRecordingShareLinksResource',
Expand Down
32 changes: 32 additions & 0 deletions src/dialpad/async_resources/async_oauth_apps_resource.py
Original file line number Diff line number Diff line change
@@ -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
)
11 changes: 11 additions & 0 deletions src/dialpad/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -405,6 +415,7 @@ def websockets(self) -> WebsocketsResource:
'MeetingRoomsResource',
'MeetingsResource',
'NumbersResource',
'OAuthAppsResource',
'OAuth2Resource',
'OfficesResource',
'RecordingShareLinksResource',
Expand Down
32 changes: 32 additions & 0 deletions src/dialpad/resources/oauth_apps_resource.py
Original file line number Diff line number Diff line change
@@ -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
)
29 changes: 29 additions & 0 deletions src/dialpad/schemas/oauth_app.py
Original file line number Diff line number Diff line change
@@ -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.'
4 changes: 4 additions & 0 deletions test/test_async_client_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
4 changes: 4 additions & 0 deletions test/test_client_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down
Loading