@@ -174,6 +174,70 @@ def get_automations(self, workspace_id: str) -> requests.Response:
174174 )
175175 return self ._get (endpoint )
176176
177+ def get_all_metrics (self , workspace_id : str ) -> requests .Response :
178+ """Get all metrics from the specified workspace.
179+
180+ Args:
181+ workspace_id (str): The ID of the workspace to retrieve metrics from.
182+ Returns:
183+ requests.Response: The response containing the metrics.
184+ """
185+ endpoint = f"/entities/workspaces/{ workspace_id } /metrics"
186+ headers = {** self .headers , "X-GDC-VALIDATE-RELATIONS" : "true" }
187+ return self ._get (endpoint , headers = headers )
188+
189+ def get_all_visualization_objects (
190+ self , workspace_id : str
191+ ) -> requests .Response :
192+ """Get all visualizations from the specified workspace.
193+
194+ Args:
195+ workspace_id (str): The ID of the workspace to retrieve visualizations from.
196+ Returns:
197+ requests.Response: The response containing the visualizations.
198+ """
199+ endpoint = f"/entities/workspaces/{ workspace_id } /visualizationObjects"
200+ headers = {** self .headers , "X-GDC-VALIDATE-RELATIONS" : "true" }
201+ return self ._get (endpoint , headers = headers )
202+
203+ def get_all_dashboards (self , workspace_id : str ) -> requests .Response :
204+ """Get all dashboards from the specified workspace.
205+
206+ Args:
207+ workspace_id (str): The ID of the workspace to retrieve dashboards from.
208+ Returns:
209+ requests.Response: The response containing the dashboards.
210+ """
211+ endpoint = f"/entities/workspaces/{ workspace_id } /analyticalDashboards"
212+ headers = {** self .headers , "X-GDC-VALIDATE-RELATIONS" : "true" }
213+ return self ._get (endpoint , headers = headers )
214+
215+ def get_workspace_layout (self , workspace_id : str ) -> requests .Response :
216+ """Get the layout of the specified workspace.
217+
218+ Args:
219+ workspace_id (str): The ID of the workspace to retrieve the layout for.
220+ Returns:
221+ requests.Response: The response containing the workspace layout.
222+ """
223+ endpoint = f"/layout/workspaces/{ workspace_id } "
224+ return self ._get (endpoint )
225+
226+ def put_workspace_layout (
227+ self , workspace_id : str , layout : dict [str , Any ]
228+ ) -> requests .Response :
229+ """Update the layout of the specified workspace.
230+
231+ Args:
232+ workspace_id (str): The ID of the workspace to update.
233+ layout (dict[str, Any]): The new layout to set for the workspace.
234+ Returns:
235+ requests.Response: The response from the server after updating the layout.
236+ """
237+ endpoint = f"/layout/workspaces/{ workspace_id } "
238+ headers = {** self .headers , "Content-Type" : "application/json" }
239+ return self ._put (endpoint , data = layout , headers = headers )
240+
177241 def _get (
178242 self , endpoint : str , headers : dict [str , str ] | None = None
179243 ) -> requests .Response :
@@ -253,3 +317,15 @@ def _delete(
253317 url = self ._get_url (endpoint )
254318
255319 return requests .delete (url , headers = self .headers , timeout = TIMEOUT )
320+
321+ @staticmethod
322+ def raise_if_response_not_ok (* responses : requests .Response ) -> None :
323+ """Check if responses from API calls are OK.
324+
325+ Raises ValueError if any response is not OK (status code not 2xx).
326+ """
327+ for response in responses :
328+ if not response .ok :
329+ raise ValueError (
330+ f"Request to { response .url } failed with status code { response .status_code } : { response .text } "
331+ )
0 commit comments