Skip to content

Commit

Permalink
update types and API interface to foxops version 2.2 (#34)
Browse files Browse the repository at this point in the history
update types and API interface to foxops version 2.2
  • Loading branch information
defreng authored Nov 23, 2023
1 parent 4853104 commit baf9f38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/foxops_client/client_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
IncarnationDoesNotExistError,
)
from foxops_client.retries import default_retry
from foxops_client.types import Incarnation, IncarnationWithDetails
from foxops_client.types import Incarnation, IncarnationWithDetails, TemplateData


class AsyncFoxopsClient:
Expand Down Expand Up @@ -103,7 +103,7 @@ async def patch_incarnation(
incarnation_id: int,
automerge: bool,
requested_version: str | None = None,
requested_data: dict[str, Any] | None = None,
requested_data: TemplateData | None = None,
):
data: dict[str, Any] = {
"automerge": automerge,
Expand Down Expand Up @@ -132,15 +132,15 @@ async def put_incarnation(
incarnation_id: int,
automerge: bool,
template_repository_version: str,
template_data: dict[str, Any],
template_data: TemplateData,
) -> IncarnationWithDetails:
data: dict[str, Any] = {
request: dict[str, Any] = {
"automerge": automerge,
"template_repository_version": template_repository_version,
"template_data": template_data,
}

resp = await self.retry_function(self.client.put)(f"/api/incarnations/{incarnation_id}", json=data)
resp = await self.retry_function(self.client.put)(f"/api/incarnations/{incarnation_id}", json=request)

match resp.status_code:
case httpx.codes.OK:
Expand All @@ -159,7 +159,7 @@ async def create_incarnation(
incarnation_repository: str,
template_repository: str,
template_repository_version: str,
template_data: dict[str, Any],
template_data: TemplateData,
target_directory: str | None = None,
automerge: bool | None = None,
) -> IncarnationWithDetails:
Expand Down
9 changes: 4 additions & 5 deletions src/foxops_client/client_sync.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import asyncio
from typing import Any

from foxops_client.client_async import AsyncFoxopsClient
from foxops_client.types import Incarnation, IncarnationWithDetails
from foxops_client.types import Incarnation, IncarnationWithDetails, TemplateData


class FoxopsClient:
Expand Down Expand Up @@ -41,7 +40,7 @@ def patch_incarnation(
incarnation_id: int,
automerge: bool,
requested_version: str | None = None,
requested_data: dict[str, Any] | None = None,
requested_data: TemplateData | None = None,
):
return self.loop.run_until_complete(
self.client.patch_incarnation(
Expand All @@ -57,7 +56,7 @@ def put_incarnation(
incarnation_id: int,
automerge: bool,
template_repository_version: str,
template_data: dict[str, Any],
template_data: TemplateData,
) -> IncarnationWithDetails:
return self.loop.run_until_complete(
self.client.put_incarnation(
Expand All @@ -73,7 +72,7 @@ def create_incarnation(
incarnation_repository: str,
template_repository: str,
template_repository_version: str,
template_data: dict[str, Any],
template_data: TemplateData,
target_directory: str | None = None,
automerge: bool | None = None,
) -> IncarnationWithDetails:
Expand Down
6 changes: 5 additions & 1 deletion src/foxops_client/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from enum import Enum
from typing import Any, Self

TemplateData = dict[str, Any]


class MergeRequestStatus(Enum):
OPEN = "open"
Expand Down Expand Up @@ -42,7 +44,8 @@ class IncarnationWithDetails(Incarnation):
template_repository: str | None
template_repository_version: str | None
template_repository_version_hash: str | None
template_data: dict[str, Any] | None
template_data: TemplateData | None
template_data_full: TemplateData | None

@classmethod
def from_dict(cls, data: dict[str, Any]) -> Self:
Expand All @@ -56,5 +59,6 @@ def from_dict(cls, data: dict[str, Any]) -> Self:
template_repository_version=data["template_repository_version"],
template_repository_version_hash=data["template_repository_version_hash"],
template_data=data["template_data"],
template_data_full=data["template_data_full"],
**asdict(Incarnation.from_dict(data)),
)

0 comments on commit baf9f38

Please sign in to comment.