diff --git a/examples/workspaces/create_workspace.py b/examples/workspaces/create_workspace.py index c8b19d6..53c9ce8 100644 --- a/examples/workspaces/create_workspace.py +++ b/examples/workspaces/create_workspace.py @@ -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__": diff --git a/examples/workspaces/get_workspace.py b/examples/workspaces/get_workspace.py new file mode 100644 index 0000000..e950243 --- /dev/null +++ b/examples/workspaces/get_workspace.py @@ -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()) diff --git a/src/codesphere/resources/team/resources.py b/src/codesphere/resources/team/resources.py index 1452ab4..a40a7e8 100644 --- a/src/codesphere/resources/team/resources.py +++ b/src/codesphere/resources/team/resources.py @@ -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 @@ -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", @@ -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}", @@ -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, - ) diff --git a/src/codesphere/resources/workspace/models.py b/src/codesphere/resources/workspace/models.py index 93e75fd..563453e 100644 --- a/src/codesphere/resources/workspace/models.py +++ b/src/codesphere/resources/workspace/models.py @@ -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 diff --git a/src/codesphere/resources/workspace/resources.py b/src/codesphere/resources/workspace/resources.py index 58f640a..f31fdef 100644 --- a/src/codesphere/resources/workspace/resources.py +++ b/src/codesphere/resources/workspace/resources.py @@ -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, - )