Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion examples/workspaces/create_workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def main():
created_workspace = await sdk.workspaces.create(data=workspace_data)

print("\n--- Details of successfully created workspace ---")
pprint.pprint(created_workspace.model_dump())
pprint.pprint(created_workspace.model_dump_json())


if __name__ == "__main__":
Expand Down
12 changes: 12 additions & 0 deletions examples/workspaces/get_workspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import asyncio
from codesphere import CodesphereSDK


async def main():
"""Fetches a workspace within a Team."""
async with CodesphereSDK() as sdk:
pass


if __name__ == "__main__":
asyncio.run(main())
36 changes: 22 additions & 14 deletions src/codesphere/resources/team/resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from asyncio import Protocol
from typing import Awaitable, Callable, List
from typing import Awaitable, Callable, List, Protocol
from ..base import ResourceBase, APIOperation
from .models import Team, TeamCreate

Expand All @@ -12,14 +11,13 @@ class CreateTeamCallable(Protocol):
async def __call__(self, *, data: TeamCreate) -> Team: ...


class DeleteTeamCallable(Protocol):
async def __call__(self, *, team_id: int) -> None: ...


class TeamsResource(ResourceBase):
"""Contains all API operations for team ressources."""

list: Callable[[], Awaitable[List[Team]]]
"""
Fetches all teams.
"""
list = APIOperation(
method="GET",
endpoint_template="/teams",
Expand All @@ -28,6 +26,15 @@ class TeamsResource(ResourceBase):
)

get: GetTeamCallable
"""
Fetches a single team by its ID.

Args:
team_id (int): The unique identifier for the team.

Returns:
Team: The requested Team object.
"""
get = APIOperation(
method="GET",
endpoint_template="/teams/{team_id}",
Expand All @@ -36,17 +43,18 @@ class TeamsResource(ResourceBase):
)

create: CreateTeamCallable
"""
Creates a new team.

Args:
data (TeamCreate): The data payload for the new team.

Returns:
Team: The newly created Team object.
"""
create = APIOperation(
method="POST",
endpoint_template="/teams",
input_model=TeamCreate,
response_model=Team,
)

delete: DeleteTeamCallable
delete = APIOperation(
method="DELETE",
endpoint_template="/teams/{team_id}",
input_model=None,
response_model=None,
)
9 changes: 9 additions & 0 deletions src/codesphere/resources/workspace/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,12 @@ async def delete_env_vars(
payload = var_names

await self._http_client.delete(f"/workspaces/{self.id}/env-vars", json=payload)

async def execute_command():
pass

async def git_pull():
pass

async def git_head():
pass
59 changes: 44 additions & 15 deletions src/codesphere/resources/workspace/resources.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,68 @@
from typing import List
from typing import List, Protocol
from ..base import ResourceBase, APIOperation
from .models import Workspace, WorkspaceCreate, WorkspaceUpdate
from .models import Workspace, WorkspaceCreate


class ListWorkspacesCallable(Protocol):
async def __call__(self, *, team_id: int) -> List[Workspace]: ...


class GetWorkspaceCallable(Protocol):
async def __call__(self, *, workspace_id: int) -> Workspace: ...


class CreateWorkspaceCallable(Protocol):
async def __call__(self, *, data: WorkspaceCreate) -> Workspace: ...


class WorkspacesResource(ResourceBase):
"""Manages all API operations for the Workspace resource."""

list_by_team: ListWorkspacesCallable
"""
Lists all workspaces for a specific team.

Args:
team_id (int): The unique identifier for the team.

Returns:
List[Workspace]: A list of Workspace objects associated with the team.
"""
list_by_team = APIOperation(
method="GET",
endpoint_template="/workspaces/team/{team_id}",
response_model=List[Workspace],
)

get: GetWorkspaceCallable
"""
Fetches a single workspace by its ID.

Args:
workspace_id (int): The unique identifier for the workspace.

Returns:
Workspace: The requested Workspace object.
"""
get = APIOperation(
method="GET",
endpoint_template="/workspaces/{workspace_id}",
response_model=Workspace,
)

create: CreateWorkspaceCallable
"""
Creates a new workspace.

Args:
data (WorkspaceCreate): The data payload for the new workspace.

Returns:
Workspace: The newly created Workspace object.
"""
create = APIOperation(
method="POST",
endpoint_template="/workspaces",
input_model=WorkspaceCreate,
response_model=Workspace,
)

update = APIOperation(
method="PATCH",
endpoint_template="/workspaces/{workspace_id}",
input_model=WorkspaceUpdate,
response_model=None,
)

delete = APIOperation(
method="DELETE",
endpoint_template="/workspaces/{workspace_id}",
response_model=None,
)
Loading