-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapps.py
More file actions
85 lines (68 loc) · 2.72 KB
/
apps.py
File metadata and controls
85 lines (68 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from __future__ import annotations
from typing import cast
from typing_extensions import Optional
from .api_types_generated import (
App,
AppListOptions,
AppInit,
AppUpdate,
)
from .utils import convert_to_snake_case
from .console import (
PaginatedList,
ConsoleClient,
AsyncConsoleClient,
AsyncPaginatedList,
)
class AsyncApps:
def __init__(self, client: AsyncConsoleClient):
self._client = client
async def get(self, id_or_slug: str) -> App | None:
"""Get an app by its ID or slug."""
result = await self._client.get_or_none(f"/api/v2/apps/{id_or_slug}")
if result is None:
return None
raw_result = convert_to_snake_case(result)
return cast(App, raw_result)
async def list(
self, options: Optional[AppListOptions] = None
) -> AsyncPaginatedList[App, AppListOptions]:
"""List apps of an org."""
return await self._client.get_paginated(
"/api/v2/apps", cursor=None, params=options
)
async def create(self, options: Optional[AppInit] = None) -> App:
"""Create a new app."""
result = await self._client.post("/api/v2/apps", options or {})
raw_result = convert_to_snake_case(result)
return cast(App, raw_result)
async def update(self, app: str, update: AppUpdate) -> App:
"""Update an existing app."""
result = await self._client.patch(f"/api/v2/apps/{app}", update)
raw_result = convert_to_snake_case(result)
return cast(App, raw_result)
async def delete(self, app: str) -> None:
"""Delete an app by its ID or slug."""
await self._client.delete(f"/api/v2/apps/{app}")
class Apps:
def __init__(self, client: ConsoleClient):
self._client = client
self._async = AsyncApps(client._async)
def get(self, id_or_slug: str) -> App | None:
"""Get an app by its ID or slug."""
return self._client._bridge.run(self._async.get(id_or_slug))
def list(
self, options: Optional[AppListOptions] = None
) -> PaginatedList[App, AppListOptions]:
"""List apps of an org."""
paginated = self._client._bridge.run(self._async.list(options))
return PaginatedList(self._client._bridge, paginated)
def create(self, options: Optional[AppInit] = None) -> App:
"""Create a new app."""
return self._client._bridge.run(self._async.create(options))
def update(self, app: str, update: AppUpdate) -> App:
"""Update an existing app."""
return self._client._bridge.run(self._async.update(app, update))
def delete(self, app: str) -> None:
"""Delete an app by its ID or slug."""
self._client._bridge.run(self._async.delete(app))