This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathworkspaces.py
More file actions
184 lines (154 loc) · 4.53 KB
/
workspaces.py
File metadata and controls
184 lines (154 loc) · 4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
from seamapi.types import (
AbstractSeam as Seam,
AbstractWorkspaces,
Workspace,
WorkspaceId,
ResetSandBoxResponse,
)
from typing import Optional, List, Union
from seamapi.utils.convert_to_id import to_workspace_id
from seamapi.utils.report_error import report_error
class Workspaces(AbstractWorkspaces):
"""
A class used to retrieve workspace data
through interaction with Seam API
...
Attributes
----------
seam : Seam
Initial seam class
Methods
-------
list(workspace=None)
Gets a list of workspaces
get(workspace=None)
Gets a workspace
reset_sandbox()
Resets workspace sandbox
"""
seam: Seam
def __init__(self, seam: Seam):
"""
Parameters
----------
seam : Seam
Initial seam class
"""
self.seam = seam
@report_error
def list(
self,
workspace: Optional[Union[WorkspaceId, Workspace]] = None,
) -> List[Workspace]:
"""Gets a list of workspaces.
Parameters
----------
workspace : WorkspaceId or Workspace, optional
Workspace id or Workspace to get latest version of
Raises
------
Exception
If workspaces weren't found.
Exception
If the API request wasn't successful.
Returns
------
Workspace
"""
workspace_id = None if workspace is None else to_workspace_id(workspace)
res = self.seam.make_request(
"GET",
"/workspaces/list",
params={"workspace_id": workspace_id},
)
return [Workspace.from_dict(w) for w in res['workspaces']]
@report_error
def get(
self
) -> Workspace:
"""Gets a workspace.
Parameters
----------
workspace : WorkspaceId or Workspace, optional
Workspace id or Workspace to get latest version of
Raises
------
Exception
If the workspace wasn't found.
Exception
If the API request wasn't successful.
Returns
------
Workspace
"""
res = self.seam.make_request(
"GET",
"/workspaces/get",
)
return Workspace.from_dict(res["workspace"])
@report_error
def reset_sandbox(self) -> None:
"""Resets workspace sandbox.
Raises
------
Exception
If the API request wasn't successful.
Returns
------
ResetSandBoxResponse
"""
self.seam.make_request(
"POST",
"/workspaces/reset_sandbox",
)
return ResetSandBoxResponse(
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.from_dict(res["workspace"])