-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
python: Split generated code into seperate files (#1634)
- Loading branch information
Showing
13 changed files
with
1,899 additions
and
1,750 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,281 @@ | ||
import typing as t | ||
from dataclasses import dataclass, field | ||
|
||
from .application import ( | ||
ApplicationAsync, | ||
Application, | ||
ApplicationIn, | ||
ApplicationOut, | ||
ApplicationPatch, | ||
ApplicationListOptions, | ||
) | ||
from .authentication import AuthenticationAsync, Authentication | ||
from .endpoint import EndpointAsync, Endpoint, EndpointListOptions | ||
from .event_type import EventTypeAsync, EventType, EventTypeListOptions | ||
from .integration import IntegrationAsync, Integration | ||
from .message import MessageAsync, Message | ||
from .message_attempt import ( | ||
MessageAttemptAsync, | ||
MessageAttempt, | ||
MessageAttemptListOptions, | ||
) | ||
from .operational_webhook import ( | ||
OperationalWebhookEndpointAsync, | ||
OperationalWebhookEndpoint, | ||
) | ||
from .statistics import StatisticsAsync, Statistics | ||
|
||
|
||
from svix.internal.openapi_client.client import AuthenticatedClient | ||
from svix.internal.openapi_client.models.dashboard_access_out import DashboardAccessOut | ||
from svix.internal.openapi_client.models.endpoint_headers_in import EndpointHeadersIn | ||
from svix.internal.openapi_client.models.endpoint_headers_out import EndpointHeadersOut | ||
from svix.internal.openapi_client.models.endpoint_headers_patch_in import ( | ||
EndpointHeadersPatchIn, | ||
) | ||
from svix.internal.openapi_client.models.endpoint_in import EndpointIn | ||
from svix.internal.openapi_client.models.endpoint_message_out_payload import ( | ||
EndpointMessageOutPayload, | ||
) | ||
from svix.internal.openapi_client.models.endpoint_out import EndpointOut | ||
from svix.internal.openapi_client.models.endpoint_patch import EndpointPatch | ||
from svix.internal.openapi_client.models.endpoint_secret_out import EndpointSecretOut | ||
from svix.internal.openapi_client.models.endpoint_secret_rotate_in import ( | ||
EndpointSecretRotateIn, | ||
) | ||
from svix.internal.openapi_client.models.event_type_import_open_api_in import ( | ||
EventTypeImportOpenApiIn, | ||
) | ||
from svix.internal.openapi_client.models.event_type_import_open_api_out import ( | ||
EventTypeImportOpenApiOut, | ||
) | ||
|
||
|
||
from svix.internal.openapi_client.models.event_type_in import EventTypeIn | ||
from svix.internal.openapi_client.models.event_type_out import EventTypeOut | ||
from svix.internal.openapi_client.models.event_type_patch import EventTypePatch | ||
from svix.internal.openapi_client.models.event_type_update import EventTypeUpdate | ||
from svix.internal.openapi_client.models.integration_in import IntegrationIn | ||
from svix.internal.openapi_client.models.integration_key_out import IntegrationKeyOut | ||
from svix.internal.openapi_client.models.integration_out import IntegrationOut | ||
from svix.internal.openapi_client.models.integration_update import IntegrationUpdate | ||
from svix.internal.openapi_client.models.list_response_application_out import ( | ||
ListResponseApplicationOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_endpoint_message_out import ( | ||
ListResponseEndpointMessageOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_endpoint_out import ( | ||
ListResponseEndpointOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_event_type_out import ( | ||
ListResponseEventTypeOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_integration_out import ( | ||
ListResponseIntegrationOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_message_attempt_endpoint_out import ( | ||
ListResponseMessageAttemptEndpointOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_message_attempt_out import ( | ||
ListResponseMessageAttemptOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_message_endpoint_out import ( | ||
ListResponseMessageEndpointOut, | ||
) | ||
from svix.internal.openapi_client.models.list_response_message_out import ( | ||
ListResponseMessageOut, | ||
) | ||
from svix.internal.openapi_client.models.message_attempt_out import MessageAttemptOut | ||
from svix.internal.openapi_client.models.message_in import MessageIn | ||
from svix.internal.openapi_client.models.message_in_payload import MessageInPayload | ||
from svix.internal.openapi_client.models.message_out import MessageOut | ||
from svix.internal.openapi_client.models.message_out_payload import MessageOutPayload | ||
from svix.internal.openapi_client.models.message_status import MessageStatus | ||
from svix.internal.openapi_client.models.recover_in import RecoverIn | ||
from svix.internal.openapi_client.models.status_code_class import StatusCodeClass | ||
|
||
DEFAULT_SERVER_URL = "https://api.svix.com" | ||
|
||
|
||
@dataclass | ||
class SvixOptions: | ||
debug: bool = False | ||
server_url: t.Optional[str] = None | ||
""" | ||
The retry schedule, as seconds to wait after each failed request. | ||
The first entry is the time in seconds to wait between the first request | ||
failing and the first retry, and so on. | ||
Up to five retries are supported, passing a retry schedule with more than | ||
five entries will raise a `ValueError`. | ||
Defaults to [0.05, 0.1, 0.2] | ||
""" | ||
retry_schedule: t.List[float] = field(default_factory=lambda: [0.05, 0.1, 0.2]) | ||
|
||
""" | ||
The maximum amount of time in seconds a request can take. | ||
Request methods will raise httpx.TimeoutException if this is exceeded. | ||
""" | ||
timeout: float = 15.0 | ||
|
||
|
||
class ClientBase: | ||
_client: AuthenticatedClient | ||
|
||
def __init__(self, auth_token: str, options: SvixOptions = SvixOptions()) -> None: | ||
from .. import __version__ | ||
|
||
if len(options.retry_schedule) > 5: | ||
raise ValueError("number of retries must not exceed 5") | ||
|
||
regional_url = None | ||
region = auth_token.split(".")[-1] | ||
if region == "us": | ||
regional_url = "https://api.us.svix.com" | ||
elif region == "eu": | ||
regional_url = "https://api.eu.svix.com" | ||
elif region == "in": | ||
regional_url = "https://api.in.svix.com" | ||
|
||
host = options.server_url or regional_url or DEFAULT_SERVER_URL | ||
client = AuthenticatedClient( | ||
base_url=host, | ||
token=auth_token, | ||
headers={"user-agent": f"svix-libs/{__version__}/python"}, | ||
verify_ssl=True, | ||
retry_schedule=options.retry_schedule, | ||
timeout=options.timeout, | ||
follow_redirects=False, | ||
raise_on_unexpected_status=True, | ||
) | ||
self._client = client | ||
|
||
|
||
class SvixAsync(ClientBase): | ||
@property | ||
def authentication(self) -> AuthenticationAsync: | ||
return AuthenticationAsync(self._client) | ||
|
||
@property | ||
def application(self) -> ApplicationAsync: | ||
return ApplicationAsync(self._client) | ||
|
||
@property | ||
def endpoint(self) -> EndpointAsync: | ||
return EndpointAsync(self._client) | ||
|
||
@property | ||
def event_type(self) -> EventTypeAsync: | ||
return EventTypeAsync(self._client) | ||
|
||
@property | ||
def integration(self) -> IntegrationAsync: | ||
return IntegrationAsync(self._client) | ||
|
||
@property | ||
def message(self) -> MessageAsync: | ||
return MessageAsync(self._client) | ||
|
||
@property | ||
def message_attempt(self) -> MessageAttemptAsync: | ||
return MessageAttemptAsync(self._client) | ||
|
||
@property | ||
def statistics(self) -> StatisticsAsync: | ||
return StatisticsAsync(self._client) | ||
|
||
@property | ||
def operational_webhook_endpoint(self) -> OperationalWebhookEndpointAsync: | ||
return OperationalWebhookEndpointAsync(self._client) | ||
|
||
|
||
class Svix(ClientBase): | ||
@property | ||
def authentication(self) -> Authentication: | ||
return Authentication(self._client) | ||
|
||
@property | ||
def application(self) -> Application: | ||
return Application(self._client) | ||
|
||
@property | ||
def endpoint(self) -> Endpoint: | ||
return Endpoint(self._client) | ||
|
||
@property | ||
def event_type(self) -> EventType: | ||
return EventType(self._client) | ||
|
||
@property | ||
def integration(self) -> Integration: | ||
return Integration(self._client) | ||
|
||
@property | ||
def message(self) -> Message: | ||
return Message(self._client) | ||
|
||
@property | ||
def message_attempt(self) -> MessageAttempt: | ||
return MessageAttempt(self._client) | ||
|
||
@property | ||
def statistics(self) -> Statistics: | ||
return Statistics(self._client) | ||
|
||
@property | ||
def operational_webhook_endpoint(self) -> OperationalWebhookEndpoint: | ||
return OperationalWebhookEndpoint(self._client) | ||
|
||
|
||
__all__ = [ | ||
"ApplicationIn", | ||
"ApplicationOut", | ||
"ApplicationPatch", | ||
"ListResponseApplicationOut", | ||
"DashboardAccessOut", | ||
"EndpointHeadersIn", | ||
"EndpointHeadersPatchIn", | ||
"EndpointHeadersOut", | ||
"EndpointIn", | ||
"EndpointOut", | ||
"EndpointPatch", | ||
"EndpointSecretOut", | ||
"EndpointSecretRotateIn", | ||
"ListResponseEndpointOut", | ||
"EventTypeImportOpenApiIn", | ||
"EventTypeImportOpenApiOut", | ||
"EventTypeIn", | ||
"EventTypeOut", | ||
"EventTypePatch", | ||
"EventTypeUpdate", | ||
"ListResponseEventTypeOut", | ||
"ListResponseMessageOut", | ||
"MessageIn", | ||
"MessageInPayload", | ||
"MessageOut", | ||
"MessageOutPayload", | ||
"EndpointMessageOutPayload", | ||
"ListResponseMessageAttemptOut", | ||
"ListResponseEndpointMessageOut", | ||
"ListResponseMessageEndpointOut", | ||
"ListResponseMessageAttemptEndpointOut", | ||
"MessageAttemptOut", | ||
"MessageStatus", | ||
"SvixOptions", | ||
"ApplicationListOptions", | ||
"EventTypeListOptions", | ||
"EndpointListOptions", | ||
"MessageAttemptListOptions", | ||
"RecoverIn", | ||
"StatusCodeClass", | ||
"Svix", | ||
"SvixAsync", | ||
"IntegrationKeyOut", | ||
"IntegrationIn", | ||
"IntegrationOut", | ||
"IntegrationUpdate", | ||
"ListResponseIntegrationOut", | ||
] |
Oops, something went wrong.