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
133 lines (111 loc) · 2.91 KB
/
workspaces.py
File metadata and controls
133 lines (111 loc) · 2.91 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
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
Intial 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 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(
workspace_id=res["workspace"]["workspace_id"],
name=res["workspace"]["name"],
is_sandbox=res["workspace"]["is_sandbox"],
)
@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,
)