From c8ae748a2261ac60e765a888e4720780f8a25759 Mon Sep 17 00:00:00 2001 From: TShapinsky Date: Mon, 11 Dec 2023 15:37:04 -0700 Subject: [PATCH] update client in accordance with API updates --- alfalfa_client/alfalfa_client.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/alfalfa_client/alfalfa_client.py b/alfalfa_client/alfalfa_client.py index 6edca4d..199ce37 100644 --- a/alfalfa_client/alfalfa_client.py +++ b/alfalfa_client/alfalfa_client.py @@ -81,7 +81,7 @@ def _request(self, endpoint: str, method="POST", parameters=None) -> requests.Re else: response = requests.request(method=method, url=self.url + endpoint) - if response.status_code == 400: + if response.status_code == 400 or response.status_code == 500: try: body = response.json() raise AlfalfaAPIException(body["error"]) @@ -270,11 +270,11 @@ def set_inputs(self, run_id: str, inputs: dict) -> None: :param run_id: id of run :param inputs: dictionary of point names and input values""" - point_writes = [] + point_writes = {} for name, value in inputs.items(): id = self._get_point_translation(run_id, name) if id: - point_writes.append({'id': id, 'value': value}) + point_writes[id] = value self._request(f"runs/{run_id}/points/values", method="PUT", parameters={'points': point_writes}) def get_outputs(self, run_id: str) -> dict: @@ -286,12 +286,9 @@ def get_outputs(self, run_id: str) -> dict: parameters={ "pointTypes": ["OUTPUT", "BIDIRECTIONAL"]}) response_body = response.json()["payload"] outputs = {} - for point in response_body: - name = self._get_point_translation(run_id, point["id"]) - if "value" in point.keys(): - outputs[name] = point["value"] - else: - outputs[name] = None + for point, value in response_body.items(): + name = self._get_point_translation(run_id, point) + outputs[name] = value return outputs