Skip to content

Commit c644264

Browse files
committed
few more docs
1 parent 3d6020b commit c644264

3 files changed

Lines changed: 67 additions & 5 deletions

File tree

metablock/orgs.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,19 @@ class Roles(MetablockComponent):
9494
class Orgs(MetablockComponent):
9595
"""Metablock organizations"""
9696

97+
async def get_list(
98+
self,
99+
*,
100+
limit: Annotated[
101+
int | None, Doc("Maximum number of organizations to return")
102+
] = None,
103+
cursor: Annotated[str | None, Doc("Cursor for pagination")] = None,
104+
) -> list[Org]:
105+
data = await self.cli.get(
106+
self.url, params=compact_dict(limit=limit, cursor=cursor)
107+
)
108+
return [Org(root=self, root_path=o["short_name"], **o) for o in data]
109+
97110
async def get(self, name_or_id: str) -> Org:
98111
"""Get an organization by name or id"""
99112
data = await self.cli.get(f"{self.url}/{name_or_id}")

metablock/spaces.py

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
from typing import TYPE_CHECKING, Any
66

77
from pydantic import BaseModel, Field
8+
from typing_extensions import Annotated, Doc
89

910
from .components import MetablockComponent, MetablockEntity
11+
from .utils import Filter, compact_dict, filter_as_tuple
1012

1113
if TYPE_CHECKING:
1214
from .client import Metablock
@@ -141,11 +143,23 @@ async def update(self, block_id: str, **kwargs: Any) -> Block:
141143
data = await self.cli.patch(f"{self.url}/{block_id}", json=kwargs)
142144
return block_from_data(self.cli, data)
143145

146+
async def delete(self, block_id: str) -> None:
147+
"""Delete a block by id"""
148+
await self.cli.delete(f"{self.url}/{block_id}")
149+
144150

145151
class SpaceBlocks(Blocks):
146-
async def get_list(self) -> list[Block]:
152+
async def get_list(
153+
self,
154+
*,
155+
name: Annotated[Filter[str] | None, Doc("Filter by block name")] = None,
156+
html: Annotated[bool | None, Doc("Filter by HTML blocks")] = None,
157+
) -> list[Block]:
147158
"""Get a list of blocks in the space"""
148-
data = await self.cli.get(self.url)
159+
data = await self.cli.get(
160+
self.url,
161+
params=compact_dict(name=filter_as_tuple(name), html=html),
162+
)
149163
return [block_from_data(self.cli, d) for d in data]
150164

151165
async def create(self, name: str, **kwargs: Any) -> Block:
@@ -196,12 +210,33 @@ async def get_list(self) -> list[SpaceExtension]:
196210
# Deployment
197211

198212

199-
class Deployment(MetablockEntity):
213+
class Deployment(BaseModel):
200214
"""Object representing a deployment"""
201215

216+
id: str = Field(description="The unique identifier of the deployment")
217+
block_id: str = Field(description="The id of the block")
218+
name: str = Field(description="The name of the deployment")
219+
env: str = Field(description="The environment of the deployment")
220+
created: datetime = Field(description="The creation date of the deployment")
221+
url: str = Field(description="The URL of the deployment")
222+
202223

203224
class Deployments(MetablockComponent):
204-
"""deployments"""
225+
"""Block deployments"""
226+
227+
async def get_list(
228+
self,
229+
*,
230+
env: Annotated[str | None, Doc("Filter by deployment environment")] = None,
231+
limit: Annotated[int | None, Doc("Maximum number of spaces to return")] = None,
232+
cursor: Annotated[str | None, Doc("Cursor for pagination")] = None,
233+
) -> list[Deployment]:
234+
"""Get a list of deployments for the block"""
235+
data = await self.cli.get(
236+
self.url,
237+
params=compact_dict(env=env, limit=limit, cursor=cursor),
238+
)
239+
return [Deployment(**d) for d in data]
205240

206241

207242
# Domain

metablock/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import zipfile
22
from contextlib import contextmanager
33
from pathlib import Path
4-
from typing import Any, Hashable, Iterable, Iterator
4+
from typing import Any, Hashable, Iterable, Iterator, TypeAlias, TypeVar
55

66
from multidict import MultiDict
77

88
DEFAULT_SKIP_VALUES = frozenset((None,))
99

10+
T = TypeVar("T")
11+
Filter: TypeAlias = T | tuple[T, ...] | list[T] | None
12+
13+
14+
def filter_as_tuple(filter_: Filter[T]) -> tuple[T, ...] | None:
15+
if isinstance(filter_, tuple):
16+
return filter_
17+
elif isinstance(filter_, list):
18+
return tuple(filter_)
19+
elif filter_ is None:
20+
return None
21+
else:
22+
return (filter_,)
23+
1024

1125
def as_dict(data: Any, key: str = "data") -> dict:
1226
return {key: data} if not isinstance(data, dict) else data

0 commit comments

Comments
 (0)