diff --git a/seamapi/types.py b/seamapi/types.py index dd692e8..5f73b63 100644 --- a/seamapi/types.py +++ b/seamapi/types.py @@ -151,6 +151,9 @@ class Workspace: workspace_id: str name: str is_sandbox: bool + connect_partner_name: str = None + webview_primary_button_color: str = None + webview_logo_shape: str = None @dataclass_json @@ -581,6 +584,17 @@ def list(self) -> List[Workspace]: def get(self, workspace_id: Optional[str] = None) -> Workspace: raise NotImplementedError + @abc.abstractmethod + def create( + self, + name: str, + connect_partner_name: str, + is_sandbox: Optional[bool] = None, + webview_primary_button_color: Optional[str] = None, + webview_logo_shape: Optional[str] = None, + ) -> Workspace: + raise NotImplementedError + @abc.abstractmethod def reset_sandbox(self) -> None: raise NotImplementedError diff --git a/seamapi/workspaces.py b/seamapi/workspaces.py index 408020c..ae337c9 100644 --- a/seamapi/workspaces.py +++ b/seamapi/workspaces.py @@ -131,3 +131,65 @@ def reset_sandbox(self) -> None: message="Successfully reset workspace sandbox", ok=True, ) + + @report_error + def create( + self, + name: str, + connect_partner_name: str, + is_sandbox: Optional[bool] = None, + webview_primary_button_color: Optional[str] = None, + webview_logo_shape: Optional[str] = None, + ) -> Workspace: + """Creates a workspace. + + Parameters + ---------- + name : string + Workspace name + connect_partner_name : string + Name shown on the connect webview + is_sandbox : string, optional + If true, creates a sandbox workspace; if false, creates a production workspace. Defaults to false. + webview_primary_button_color : string, optional + The color of the primary button in the webview, represented in hex format (e.g., "#RRGGBB"). + webview_logo_shape : string, optional + The shape of the logo in the webview: "circle" or "square". + + + Raises + ------ + Exception + If the API request wasn't successful. + + Returns + ------ + Workspace + """ + + create_payload = { + "workspace_name": name, + "name": name, + "connect_partner_name": connect_partner_name + } + + if is_sandbox is not None: + create_payload["is_sandbox"] = is_sandbox + if webview_primary_button_color is not None: + create_payload["webview_primary_button_color"] = webview_primary_button_color + if webview_logo_shape is not None: + create_payload["webview_logo_shape"] = webview_logo_shape + + res = self.seam.make_request( + "POST", + "/workspaces/create", + json=create_payload, + ) + return Workspace( + workspace_id=res["workspace"]["workspace_id"], + name=res["workspace"]["name"], + is_sandbox=res["workspace"]["is_sandbox"], + connect_partner_name=res["workspace"]["connect_partner_name"], + webview_primary_button_color=res["workspace"]["webview_primary_button_color"], + webview_logo_shape=res["workspace"]["webview_logo_shape"], + ) diff --git a/tests/workspaces/test_workspaces_create.py b/tests/workspaces/test_workspaces_create.py new file mode 100644 index 0000000..565d99e --- /dev/null +++ b/tests/workspaces/test_workspaces_create.py @@ -0,0 +1,9 @@ +from seamapi import Seam + + +def test_workspaces_create(seam: Seam): + workspace = seam.workspaces.create( + workspace_name="Test Workspace", connect_partner_name="Example Partner" + ) + + assert workspace.workspace_id