|
| 1 | +from typing import Any, Dict, List, Optional, cast |
| 2 | + |
| 3 | +from typing_extensions import NotRequired, TypedDict |
| 4 | + |
| 5 | +from resend import request |
| 6 | +from resend._base_response import BaseResponse |
| 7 | +from resend.oauth_grants._oauth_grant import OAuthGrant |
| 8 | +from resend.pagination_helper import PaginationHelper |
| 9 | + |
| 10 | +# Async imports (optional - only available with pip install resend[async]) |
| 11 | +try: |
| 12 | + from resend.async_request import AsyncRequest |
| 13 | +except ImportError: |
| 14 | + pass |
| 15 | + |
| 16 | + |
| 17 | +class OAuthGrants: |
| 18 | + |
| 19 | + class ListResponse(BaseResponse): |
| 20 | + """ |
| 21 | + ListResponse type that wraps a list of OAuth grant objects with pagination metadata |
| 22 | +
|
| 23 | + Attributes: |
| 24 | + object (str): The object type, always "list" |
| 25 | + data (List[OAuthGrant]): A list of OAuth grant objects |
| 26 | + has_more (bool): Whether there are more results available |
| 27 | + """ |
| 28 | + |
| 29 | + object: str |
| 30 | + """ |
| 31 | + The object type, always "list" |
| 32 | + """ |
| 33 | + data: List[OAuthGrant] |
| 34 | + """ |
| 35 | + A list of OAuth grant objects |
| 36 | + """ |
| 37 | + has_more: bool |
| 38 | + """ |
| 39 | + Whether there are more results available for pagination |
| 40 | + """ |
| 41 | + |
| 42 | + class RevokeOAuthGrantResponse(BaseResponse): |
| 43 | + """ |
| 44 | + RevokeOAuthGrantResponse is the type that wraps the revoked OAuth grant response. |
| 45 | +
|
| 46 | + Attributes: |
| 47 | + object (str): The object type, always "oauth_grant" |
| 48 | + id (str): The ID of the revoked OAuth grant |
| 49 | + revoked_at (str): The date and time the grant was revoked |
| 50 | + revoked_reason (str): The reason the grant was revoked |
| 51 | + """ |
| 52 | + |
| 53 | + object: str |
| 54 | + """ |
| 55 | + The object type, always "oauth_grant" |
| 56 | + """ |
| 57 | + id: str |
| 58 | + """ |
| 59 | + The ID of the revoked OAuth grant |
| 60 | + """ |
| 61 | + revoked_at: str |
| 62 | + """ |
| 63 | + The date and time the grant was revoked |
| 64 | + """ |
| 65 | + revoked_reason: str |
| 66 | + """ |
| 67 | + The reason the grant was revoked |
| 68 | + """ |
| 69 | + |
| 70 | + class ListParams(TypedDict): |
| 71 | + limit: NotRequired[int] |
| 72 | + """ |
| 73 | + Number of OAuth grants to retrieve. Maximum is 100, and minimum is 1. |
| 74 | + """ |
| 75 | + after: NotRequired[str] |
| 76 | + """ |
| 77 | + The ID after which we'll retrieve more OAuth grants (for pagination). |
| 78 | + This ID will not be included in the returned list. |
| 79 | + Cannot be used with the before parameter. |
| 80 | + """ |
| 81 | + before: NotRequired[str] |
| 82 | + """ |
| 83 | + The ID before which we'll retrieve more OAuth grants (for pagination). |
| 84 | + This ID will not be included in the returned list. |
| 85 | + Cannot be used with the after parameter. |
| 86 | + """ |
| 87 | + |
| 88 | + @classmethod |
| 89 | + def list(cls, params: Optional[ListParams] = None) -> ListResponse: |
| 90 | + """ |
| 91 | + Retrieve a list of OAuth grants for the authenticated user. |
| 92 | + see more: https://resend.com/docs/api-reference/oauth/list-grants |
| 93 | +
|
| 94 | + Args: |
| 95 | + params (Optional[ListParams]): Optional pagination parameters |
| 96 | + - limit: Number of OAuth grants to retrieve (max 100, min 1) |
| 97 | + - after: ID after which to retrieve more OAuth grants |
| 98 | + - before: ID before which to retrieve more OAuth grants |
| 99 | +
|
| 100 | + Returns: |
| 101 | + ListResponse: A list of OAuth grant objects |
| 102 | + """ |
| 103 | + base_path = "/oauth/grants" |
| 104 | + query_params = cast(Dict[Any, Any], params) if params else None |
| 105 | + path = PaginationHelper.build_paginated_path(base_path, query_params) |
| 106 | + resp = request.Request[OAuthGrants.ListResponse]( |
| 107 | + path=path, params={}, verb="get" |
| 108 | + ).perform_with_content() |
| 109 | + return resp |
| 110 | + |
| 111 | + @classmethod |
| 112 | + def revoke(cls, oauth_grant_id: str) -> RevokeOAuthGrantResponse: |
| 113 | + """ |
| 114 | + Revoke an existing OAuth grant. |
| 115 | + see more: https://resend.com/docs/api-reference/oauth/revoke-grant |
| 116 | +
|
| 117 | + Args: |
| 118 | + oauth_grant_id (str): The ID of the OAuth grant to revoke |
| 119 | +
|
| 120 | + Returns: |
| 121 | + RevokeOAuthGrantResponse: The revoked OAuth grant response |
| 122 | + """ |
| 123 | + path = f"/oauth/grants/{oauth_grant_id}" |
| 124 | + resp = request.Request[OAuthGrants.RevokeOAuthGrantResponse]( |
| 125 | + path=path, params={}, verb="delete" |
| 126 | + ).perform_with_content() |
| 127 | + return resp |
| 128 | + |
| 129 | + @classmethod |
| 130 | + async def list_async(cls, params: Optional[ListParams] = None) -> ListResponse: |
| 131 | + """ |
| 132 | + Retrieve a list of OAuth grants for the authenticated user (async). |
| 133 | + see more: https://resend.com/docs/api-reference/oauth/list-grants |
| 134 | +
|
| 135 | + Args: |
| 136 | + params (Optional[ListParams]): Optional pagination parameters |
| 137 | +
|
| 138 | + Returns: |
| 139 | + ListResponse: A list of OAuth grant objects |
| 140 | + """ |
| 141 | + base_path = "/oauth/grants" |
| 142 | + query_params = cast(Dict[Any, Any], params) if params else None |
| 143 | + path = PaginationHelper.build_paginated_path(base_path, query_params) |
| 144 | + resp = await AsyncRequest[OAuthGrants.ListResponse]( |
| 145 | + path=path, params={}, verb="get" |
| 146 | + ).perform_with_content() |
| 147 | + return resp |
| 148 | + |
| 149 | + @classmethod |
| 150 | + async def revoke_async(cls, oauth_grant_id: str) -> RevokeOAuthGrantResponse: |
| 151 | + """ |
| 152 | + Revoke an existing OAuth grant (async). |
| 153 | + see more: https://resend.com/docs/api-reference/oauth/revoke-grant |
| 154 | +
|
| 155 | + Args: |
| 156 | + oauth_grant_id (str): The ID of the OAuth grant to revoke |
| 157 | +
|
| 158 | + Returns: |
| 159 | + RevokeOAuthGrantResponse: The revoked OAuth grant response |
| 160 | + """ |
| 161 | + path = f"/oauth/grants/{oauth_grant_id}" |
| 162 | + resp = await AsyncRequest[OAuthGrants.RevokeOAuthGrantResponse]( |
| 163 | + path=path, params={}, verb="delete" |
| 164 | + ).perform_with_content() |
| 165 | + return resp |
0 commit comments