From 99e40718a2631644da37ade546789c22fcb6fa32 Mon Sep 17 00:00:00 2001 From: Andrii Balitskyi <10balian10@gmail.com> Date: Tue, 28 Nov 2023 15:35:19 +0100 Subject: [PATCH] Add workspaces.create method --- seamapi/types.py | 3 +++ seamapi/workspaces.py | 58 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/seamapi/types.py b/seamapi/types.py index dd692e8..3b4a15b 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 diff --git a/seamapi/workspaces.py b/seamapi/workspaces.py index 408020c..481839a 100644 --- a/seamapi/workspaces.py +++ b/seamapi/workspaces.py @@ -131,3 +131,61 @@ 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], + webview_primary_button_color: Optional[str], + webview_logo_shape: Optional[str], + ) -> 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 = {"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"], + )