Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 75713b1

Browse files
fix: Add workspaces.create method (#130)
* Add workspaces.create method * add abc for workspaces for create, add test for workspaces create * various fixes from testing * add regression --------- Co-authored-by: Severin Ibarluzea <[email protected]>
1 parent 71db16e commit 75713b1

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

seamapi/types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ class Workspace:
151151
workspace_id: str
152152
name: str
153153
is_sandbox: bool
154+
connect_partner_name: str = None
155+
webview_primary_button_color: str = None
156+
webview_logo_shape: str = None
154157

155158

156159
@dataclass_json
@@ -581,6 +584,17 @@ def list(self) -> List[Workspace]:
581584
def get(self, workspace_id: Optional[str] = None) -> Workspace:
582585
raise NotImplementedError
583586

587+
@abc.abstractmethod
588+
def create(
589+
self,
590+
name: str,
591+
connect_partner_name: str,
592+
is_sandbox: Optional[bool] = None,
593+
webview_primary_button_color: Optional[str] = None,
594+
webview_logo_shape: Optional[str] = None,
595+
) -> Workspace:
596+
raise NotImplementedError
597+
584598
@abc.abstractmethod
585599
def reset_sandbox(self) -> None:
586600
raise NotImplementedError

seamapi/workspaces.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,65 @@ def reset_sandbox(self) -> None:
131131
message="Successfully reset workspace sandbox",
132132
ok=True,
133133
)
134+
135+
@report_error
136+
def create(
137+
self,
138+
name: str,
139+
connect_partner_name: str,
140+
is_sandbox: Optional[bool] = None,
141+
webview_primary_button_color: Optional[str] = None,
142+
webview_logo_shape: Optional[str] = None,
143+
) -> Workspace:
144+
"""Creates a workspace.
145+
146+
Parameters
147+
----------
148+
name : string
149+
Workspace name
150+
connect_partner_name : string
151+
Name shown on the connect webview
152+
is_sandbox : string, optional
153+
If true, creates a sandbox workspace; if false, creates a production workspace. Defaults to false.
154+
webview_primary_button_color : string, optional
155+
The color of the primary button in the webview, represented in hex format (e.g., "#RRGGBB").
156+
webview_logo_shape : string, optional
157+
The shape of the logo in the webview: "circle" or "square".
158+
159+
160+
Raises
161+
------
162+
Exception
163+
If the API request wasn't successful.
164+
165+
Returns
166+
------
167+
Workspace
168+
"""
169+
170+
create_payload = {
171+
"workspace_name": name,
172+
"name": name,
173+
"connect_partner_name": connect_partner_name
174+
}
175+
176+
if is_sandbox is not None:
177+
create_payload["is_sandbox"] = is_sandbox
178+
if webview_primary_button_color is not None:
179+
create_payload["webview_primary_button_color"] = webview_primary_button_color
180+
if webview_logo_shape is not None:
181+
create_payload["webview_logo_shape"] = webview_logo_shape
182+
183+
res = self.seam.make_request(
184+
"POST",
185+
"/workspaces/create",
186+
json=create_payload,
187+
)
188+
return Workspace(
189+
workspace_id=res["workspace"]["workspace_id"],
190+
name=res["workspace"]["name"],
191+
is_sandbox=res["workspace"]["is_sandbox"],
192+
connect_partner_name=res["workspace"]["connect_partner_name"],
193+
webview_primary_button_color=res["workspace"]["webview_primary_button_color"],
194+
webview_logo_shape=res["workspace"]["webview_logo_shape"],
195+
)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from seamapi import Seam
2+
3+
4+
def test_workspaces_create(seam: Seam):
5+
workspace = seam.workspaces.create(
6+
workspace_name="Test Workspace", connect_partner_name="Example Partner"
7+
)
8+
9+
assert workspace.workspace_id

0 commit comments

Comments
 (0)