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

Commit 4bc4c92

Browse files
fix: Allow setting workspace_id on seam client (#131)
* Use from_dict method when returning workspace resource * Update workspace type * Allow passing workspace_id to seam client * Initialize workspace_id unconditionally in the seam client * Fix assigning api url to workspace id
1 parent 1caa500 commit 4bc4c92

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

seamapi/seam.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class Seam(AbstractSeam):
4545
def __init__(
4646
self,
4747
api_key: Optional[str] = None,
48+
workspace_id: Optional[str] = None,
4849
api_url: Optional[str] = None,
4950
should_report_exceptions: Optional[bool] = False,
5051
):
@@ -53,6 +54,8 @@ def __init__(
5354
----------
5455
api_key : str, optional
5556
API key
57+
workspace_id : str, optional
58+
Workspace id
5659
api_url : str, optional
5760
API url
5861
should_report_exceptions : bool, optional
@@ -66,9 +69,10 @@ def __init__(
6669
raise Exception(
6770
"SEAM_API_KEY not found in environment, and api_key not provided"
6871
)
69-
if api_url is None:
70-
api_url = os.environ.get("SEAM_API_URL", self.api_url)
72+
if workspace_id is None:
73+
workspace_id = os.environ.get("SEAM_WORKSPACE_ID", None)
7174
self.api_key = api_key
75+
self.workspace_id = workspace_id
7276
self.api_url = cast(str, api_url)
7377
self.should_report_exceptions = should_report_exceptions
7478

@@ -102,6 +106,8 @@ def make_request(self, method: str, path: str, **kwargs):
102106
"Content-Type": "application/json",
103107
"User-Agent": "Python SDK v" + pkg_resources.get_distribution("seamapi").version + " (https://github.com/seamapi/python)",
104108
}
109+
if self.workspace_id is not None:
110+
headers["seam-workspace"] = self.workspace_id
105111
response = requests.request(method, url, headers=headers, **kwargs)
106112

107113
if self.should_report_exceptions and response.status_code:

seamapi/types.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ class Workspace:
152152
name: str
153153
is_sandbox: bool
154154
connect_partner_name: str = None
155-
webview_primary_button_color: str = None
156-
webview_logo_shape: str = None
157155

158156

159157
@dataclass_json
@@ -797,10 +795,17 @@ def make_request(self, method: str, path: str, **kwargs) -> Any:
797795
@dataclass
798796
class AbstractSeam(AbstractRoutes):
799797
api_key: str
798+
workspace_id: str
800799
api_url: str
801800

802801
@abc.abstractmethod
803-
def __init__(self, api_key: Optional[str] = None):
802+
def __init__(
803+
self,
804+
api_key: Optional[str] = None,
805+
workspace_id: Optional[str] = None,
806+
api_url: Optional[str] = None,
807+
should_report_exceptions: Optional[bool] = False,
808+
):
804809
raise NotImplementedError
805810

806811

seamapi/workspaces.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def list(
7575
"/workspaces/list",
7676
params={"workspace_id": workspace_id},
7777
)
78-
return res["workspaces"]
78+
return [Workspace.from_dict(w) for w in res['workspaces']]
7979

8080
@report_error
8181
def get(
@@ -103,11 +103,7 @@ def get(
103103
"GET",
104104
"/workspaces/get",
105105
)
106-
return Workspace(
107-
workspace_id=res["workspace"]["workspace_id"],
108-
name=res["workspace"]["name"],
109-
is_sandbox=res["workspace"]["is_sandbox"],
110-
)
106+
return Workspace.from_dict(res["workspace"])
111107

112108
@report_error
113109
def reset_sandbox(self) -> None:
@@ -185,11 +181,4 @@ def create(
185181
"/workspaces/create",
186182
json=create_payload,
187183
)
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-
)
184+
return Workspace.from_dict(res["workspace"])

0 commit comments

Comments
 (0)