Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python: Replace OpenAPI generator http code with out own #1654

Merged
merged 41 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
cbd1f89
python: Add new low-level http client
svix-mman Jan 20, 2025
cca4e24
python: Migrate `Application` to new HTTP client
svix-mman Jan 20, 2025
14e8d0f
python: Sort `dashboard_access` in the correct order
svix-mman Jan 20, 2025
97893a3
python: Rename query_params/header_params to an internal method
svix-mman Jan 20, 2025
8255e3a
python: Add `sanitize_field` and `str().lower()` in `*Options._query_…
svix-mman Jan 20, 2025
f4bb9c5
python: For now we only need 1 exception type for HTTP errors
svix-mman Jan 21, 2025
60750da
python: rename `_execute_request` to `_request`
svix-mman Jan 21, 2025
67155e6
python: Add `serialize_params` to `_query_params`/`_header_params`
svix-mman Jan 21, 2025
be34bba
python: Simplify path param url formatting
svix-mman Jan 21, 2025
f0c4a6c
python: Explicit boolean serialization
svix-mman Jan 21, 2025
7de109c
python: Don't generate `_query_params`/`_header_params` if there are …
svix-mman Jan 21, 2025
c93c0d1
python: Implement a default `_header_params` and `_query_params` for …
svix-mman Jan 21, 2025
04ec169
python: `_query_params` and `_header_params` need self (:
svix-mman Jan 21, 2025
ddc30ad
python: Switch `Authentication` to new HTTP client
svix-mman Jan 21, 2025
a4970e3
python: Switch `BackgroundTask` to new codegen
svix-mman Jan 21, 2025
072091f
python: Switch `Endpoint` resource to new HTTP client
svix-mman Jan 21, 2025
6e23c1f
python: Switch `EventType` resource to new HTTP client
svix-mman Jan 21, 2025
1d4c76a
python: Mark `Integration(A)sync`.`get_key` as deprecated
svix-mman Jan 21, 2025
e992a60
python: Switch the `Integration` resource to new HTTP client
svix-mman Jan 21, 2025
ec8092e
python(**Breaking change**): Remove `list` and `list_attempts_for_end…
svix-mman Jan 21, 2025
6374d5c
python: Add `list_by_msg_deprecated` and `list_by_endpoint_deprecated…
svix-mman Jan 21, 2025
743345e
python: (**breaking change**) Remove `MessageListAttemptsForEndpointO…
svix-mman Jan 21, 2025
35b36da
python: Switch `MessageAttempt` to new HTTP client
svix-mman Jan 21, 2025
3e0a99f
python: Switch `Message` resource to use new HTTP client
svix-mman Jan 21, 2025
cd36ffb
python: Switch `Statistics` to new HTTP client
svix-mman Jan 21, 2025
f9b9d16
python: remove `PostOptions` from `OperationalWebhook`
svix-mman Jan 21, 2025
da78242
python: Rename `operational_webhook` to `operational_webhook_endpoint`
svix-mman Jan 21, 2025
6b7ca26
python: (breaking change) Rename these arguments to be inline with th…
svix-mman Jan 21, 2025
2018317
python: Switch `OperationalWebhookEndpoint` to new HTTP client
svix-mman Jan 21, 2025
0071e10
python: Codegen is smart enough to not need to leave `noqa: F841` eve…
svix-mman Jan 22, 2025
03a6f7b
python: Better codegen does not need to ignore unused variable warnings
svix-mman Jan 23, 2025
ecb9202
python: This is the correct way to handel class properties doc comments
svix-mman Jan 23, 2025
1c05e65
python: Document breaking changes
svix-mman Jan 23, 2025
1b5545e
python: Remove these deprecated operations.
svix-mman Jan 23, 2025
ea02fe7
python: Update generated files to use correct doc string format
svix-mman Jan 23, 2025
10942df
This was not really a breaking change
svix-mman Jan 23, 2025
348fcc1
English: Correct syntax error...
svix-mman Jan 23, 2025
db7adbe
python: Move `OperationalWebhook` to new codegen (#1656)
svix-mman Jan 23, 2025
0277b9f
Merge branch 'main' into mendy/add-python-low-level-http-client
svix-mman Jan 23, 2025
f165777
python: Sort these method inline with the codegen
svix-mman Jan 23, 2025
8f204c7
python: Serialize list/set params as a comma separated list
svix-mman Jan 23, 2025
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
202 changes: 155 additions & 47 deletions python/svix/api/application.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# This file is @generated
import typing as t
from dataclasses import dataclass

from .common import ApiBase, BaseOptions
from ..internal.openapi_client import models


from ..internal.openapi_client.api.application import (
v1_application_list,
v1_application_create,
v1_application_get,
v1_application_update,
v1_application_delete,
v1_application_patch,
)

from ..internal.openapi_client.models.list_response_application_out import (
ListResponseApplicationOut,
)
from ..internal.openapi_client.models.application_in import ApplicationIn
from ..internal.openapi_client.models.application_out import ApplicationOut
from ..internal.openapi_client.models.application_patch import ApplicationPatch
from ..internal.openapi_client.models.list_response_application_out import (
ListResponseApplicationOut,
)
from .common import ApiBase, BaseOptions, sanitize_field


@dataclass
Expand All @@ -31,124 +21,242 @@ class ApplicationListOptions(BaseOptions):
# The sorting order of the returned items
order: t.Optional[models.Ordering] = None

def _query_params(self) -> t.Optional[t.Dict[str, str]]:
d = {
"limit": self.limit,
"iterator": self.iterator,
"order": self.order,
}
return {
k: str(sanitize_field(v)).lower() for k, v in d.items() if v is not None
svix-mman marked this conversation as resolved.
Show resolved Hide resolved
}

def _header_params(self) -> t.Optional[t.Dict[str, str]]:
return None


@dataclass
class ApplicationCreateOptions(BaseOptions):
idempotency_key: t.Optional[str] = None

def _query_params(self) -> t.Optional[t.Dict[str, str]]:
return None

def _header_params(self) -> t.Optional[t.Dict[str, str]]:
d = {
"idempotency-key": self.idempotency_key,
}
return {k: v for k, v in d.items() if v is not None}


@dataclass
class ApplicationGetOrCreateOptions(BaseOptions):
idempotency_key: t.Optional[str] = None

def _query_params(self) -> t.Optional[t.Dict[str, str]]:
return None

def _header_params(self) -> t.Optional[t.Dict[str, str]]:
d = {
"idempotency-key": self.idempotency_key,
}
return {k: v for k, v in d.items() if v is not None}


class ApplicationAsync(ApiBase):
async def list(
self, options: ApplicationListOptions = ApplicationListOptions()
) -> ListResponseApplicationOut:
"""List of all the organization's applications."""
return await v1_application_list.request_asyncio(
client=self._client, **options.to_dict()
# ruff: noqa: F841
response = await self._request_asyncio(
method="get",
path="/api/v1/app",
path_params={},
query_params=options._query_params(),
header_params=options._header_params(),
)
return ListResponseApplicationOut.from_dict(response.json())

async def create(
self,
application_in: ApplicationIn,
options: ApplicationCreateOptions = ApplicationCreateOptions(),
) -> ApplicationOut:
"""Create a new application."""
return await v1_application_create.request_asyncio(
client=self._client, json_body=application_in, **options.to_dict()
# ruff: noqa: F841
response = await self._request_asyncio(
method="post",
path="/api/v1/app",
path_params={},
query_params=options._query_params(),
header_params=options._header_params(),
json_body=application_in.to_dict(),
)
return ApplicationOut.from_dict(response.json())

async def get(self, app_id: str) -> ApplicationOut:
"""Get an application."""
return await v1_application_get.request_asyncio(
client=self._client, app_id=app_id
# ruff: noqa: F841
response = await self._request_asyncio(
method="get",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
)
return ApplicationOut.from_dict(response.json())

async def get_or_create(
self,
application_in: ApplicationIn,
options: ApplicationGetOrCreateOptions = ApplicationGetOrCreateOptions(),
) -> ApplicationOut:
return await v1_application_create.request_asyncio(
client=self._client,
json_body=application_in,
get_if_exists=True,
**options.to_dict(),
response = await self._request_asyncio(
method="post",
path="/api/v1/app",
path_params={},
query_params={"get_if_exists": "true"},
header_params=options._header_params(),
json_body=application_in.to_dict(),
)
return ApplicationOut.from_dict(response.json())

async def update(
self, app_id: str, application_in: ApplicationIn
) -> ApplicationOut:
"""Update an application."""
return await v1_application_update.request_asyncio(
client=self._client, app_id=app_id, json_body=application_in
# ruff: noqa: F841
response = await self._request_asyncio(
method="put",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
json_body=application_in.to_dict(),
)
return ApplicationOut.from_dict(response.json())

async def delete(self, app_id: str) -> None:
"""Delete an application."""
return await v1_application_delete.request_asyncio(
client=self._client, app_id=app_id
# ruff: noqa: F841
response = await self._request_asyncio(
method="delete",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
)

async def patch(
self, app_id: str, application_patch: ApplicationPatch
) -> ApplicationOut:
"""Partially update an application."""
return await v1_application_patch.request_asyncio(
client=self._client, app_id=app_id, json_body=application_patch
# ruff: noqa: F841
response = await self._request_asyncio(
method="patch",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
json_body=application_patch.to_dict(),
)
return ApplicationOut.from_dict(response.json())


class Application(ApiBase):
def list(
self, options: ApplicationListOptions = ApplicationListOptions()
) -> ListResponseApplicationOut:
"""List of all the organization's applications."""
return v1_application_list.request_sync(
client=self._client, **options.to_dict()
# ruff: noqa: F841
response = self._request_sync(
method="get",
path="/api/v1/app",
path_params={},
query_params=options._query_params(),
header_params=options._header_params(),
)
return ListResponseApplicationOut.from_dict(response.json())

def create(
self,
application_in: ApplicationIn,
options: ApplicationCreateOptions = ApplicationCreateOptions(),
) -> ApplicationOut:
"""Create a new application."""
return v1_application_create.request_sync(
client=self._client, json_body=application_in, **options.to_dict()
# ruff: noqa: F841
response = self._request_sync(
method="post",
path="/api/v1/app",
path_params={},
query_params=options._query_params(),
header_params=options._header_params(),
json_body=application_in.to_dict(),
)
return ApplicationOut.from_dict(response.json())

def get(self, app_id: str) -> ApplicationOut:
"""Get an application."""
return v1_application_get.request_sync(client=self._client, app_id=app_id)
# ruff: noqa: F841
response = self._request_sync(
method="get",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
)
return ApplicationOut.from_dict(response.json())

def get_or_create(
self,
application_in: ApplicationIn,
options: ApplicationGetOrCreateOptions = ApplicationGetOrCreateOptions(),
) -> ApplicationOut:
return v1_application_create.request_sync(
client=self._client,
json_body=application_in,
get_if_exists=True,
**options.to_dict(),
# ruff: noqa: F841
response = self._request_sync(
method="post",
path="/api/v1/app",
path_params={},
query_params={"get_if_exists": "true"},
header_params=options._header_params(),
json_body=application_in.to_dict(),
)
return ApplicationOut.from_dict(response.json())

def update(self, app_id: str, application_in: ApplicationIn) -> ApplicationOut:
"""Update an application."""
return v1_application_update.request_sync(
client=self._client, app_id=app_id, json_body=application_in
# ruff: noqa: F841
response = self._request_sync(
method="put",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
json_body=application_in.to_dict(),
)
return ApplicationOut.from_dict(response.json())

def delete(self, app_id: str) -> None:
"""Delete an application."""
return v1_application_delete.request_sync(client=self._client, app_id=app_id)
# ruff: noqa: F841
response = self._request_sync(
method="delete",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
)

def patch(self, app_id: str, application_patch: ApplicationPatch) -> ApplicationOut:
"""Partially update an application."""
return v1_application_patch.request_sync(
client=self._client, app_id=app_id, json_body=application_patch
# ruff: noqa: F841
response = self._request_sync(
method="patch",
path="/api/v1/app/{app_id}",
path_params={
"app_id": app_id,
},
json_body=application_patch.to_dict(),
)
return ApplicationOut.from_dict(response.json())
24 changes: 12 additions & 12 deletions python/svix/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ class AuthenticationAppPortalAccessOptions(BaseOptions):


@dataclass
class AuthenticationDashboardAccessOptions(BaseOptions):
class AuthenticationExpireAllOptions(BaseOptions):
idempotency_key: t.Optional[str] = None


@dataclass
class AuthenticationExpireAllOptions(BaseOptions):
class AuthenticationDashboardAccessOptions(BaseOptions):
idempotency_key: t.Optional[str] = None


Expand All @@ -55,16 +55,6 @@ async def app_portal_access(
**options.to_dict(),
)

@deprecated
async def dashboard_access(
self,
app_id: str,
options: AuthenticationDashboardAccessOptions = AuthenticationDashboardAccessOptions(),
) -> DashboardAccessOut:
return await v1_authentication_dashboard_access.request_asyncio(
client=self._client, app_id=app_id, **options.to_dict()
)

async def expire_all(
self,
app_id: str,
Expand All @@ -79,6 +69,16 @@ async def expire_all(
**options.to_dict(),
)

@deprecated
async def dashboard_access(
self,
app_id: str,
options: AuthenticationDashboardAccessOptions = AuthenticationDashboardAccessOptions(),
) -> DashboardAccessOut:
return await v1_authentication_dashboard_access.request_asyncio(
client=self._client, app_id=app_id, **options.to_dict()
)

async def logout(
self, options: AuthenticationLogoutOptions = AuthenticationLogoutOptions()
) -> None:
Expand Down
Loading