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

Commit 3de743d

Browse files
committed
Migrate workspaces
1 parent 4dfc546 commit 3de743d

File tree

1 file changed

+15
-32
lines changed

1 file changed

+15
-32
lines changed

seamapi/workspaces.py

Lines changed: 15 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
ResetSandBoxResponse,
77
)
88
from typing import Optional, List, Union
9-
import requests
109

1110
from seamapi.utils.convert_to_id import to_workspace_id
1211

1312

1413
class Workspaces(AbstractWorkspaces):
1514
"""
16-
A class used to retreive workspace data
15+
A class used to retrieve workspace data
1716
through interaction with Seam API
1817
1918
...
@@ -69,21 +68,15 @@ def list(
6968
"""
7069

7170
workspace_id = None if workspace is None else to_workspace_id(workspace)
72-
res = requests.get(
73-
f"{self.seam.api_url}/workspaces/list",
71+
res = self.seam.make_request(
72+
"GET",
73+
"/workspaces/list",
7474
params={"workspace_id": workspace_id},
75-
headers={"Authorization": f"Bearer {self.seam.api_key}"},
7675
)
77-
if res.status_code == 404:
78-
raise Exception("workspaces not found") # TODO custom exception
79-
if res.status_code != 200:
80-
raise Exception(res.text)
81-
res_json = res.json()
82-
return res_json["workspaces"]
76+
return res["workspaces"]
8377

8478
def get(
85-
self,
86-
workspace: Optional[Union[WorkspaceId, Workspace]] = None,
79+
self
8780
) -> Workspace:
8881
"""Gets a workspace.
8982
@@ -103,21 +96,14 @@ def get(
10396
------
10497
Workspace
10598
"""
106-
workspace_id = None if workspace is None else to_workspace_id(workspace)
107-
res = requests.get(
108-
f"{self.seam.api_url}/workspaces/get",
109-
params={"workspace_id": workspace_id},
110-
headers={"Authorization": f"Bearer {self.seam.api_key}"},
99+
res = self.seam.make_request(
100+
"GET",
101+
"/workspaces/get",
111102
)
112-
if res.status_code == 404:
113-
raise Exception("workspace not found") # TODO custom exception
114-
if res.status_code != 200:
115-
raise Exception(res.text)
116-
res_json = res.json()
117103
return Workspace(
118-
workspace_id=res_json["workspace"]["workspace_id"],
119-
name=res_json["workspace"]["name"],
120-
is_sandbox=res_json["workspace"]["is_sandbox"],
104+
workspace_id=res["workspace"]["workspace_id"],
105+
name=res["workspace"]["name"],
106+
is_sandbox=res["workspace"]["is_sandbox"],
121107
)
122108

123109
def reset_sandbox(self) -> None:
@@ -132,13 +118,10 @@ def reset_sandbox(self) -> None:
132118
------
133119
ResetSandBoxResponse
134120
"""
135-
136-
res = requests.post(
137-
f"{self.seam.api_url}/workspaces/reset_sandbox",
138-
headers={"Authorization": f"Bearer {self.seam.api_key}"},
121+
res = self.seam.make_request(
122+
"POST",
123+
"/workspaces/reset_sandbox",
139124
)
140-
if not res.ok:
141-
raise Exception(res.text)
142125

143126
return ResetSandBoxResponse(
144127
message="Successfully reset workspace sandbox",

0 commit comments

Comments
 (0)