Skip to content
This repository was archived by the owner on Mar 30, 2023. It is now read-only.

Commit 180fcf5

Browse files
author
Jason Costello
committed
Shifted other .list() resource methods over to cls.request pattern
1 parent a903df1 commit 180fcf5

File tree

5 files changed

+8
-6
lines changed

5 files changed

+8
-6
lines changed

hypervector/resources/abstract/api_resource.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ def get(cls, uuid):
2828
@classmethod
2929
def request(cls, endpoint, method=requests.get):
3030
response = method(url=endpoint, headers=cls.get_headers())
31-
return response.json()
31+
if response.status_code == 200:
32+
return response.json()
33+
else:
34+
raise HypervectorError(response)
3235

3336
@classmethod
3437
def delete(cls, uuid):

hypervector/resources/core/benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def list(cls, ensemble):
4040
parent_endpoint = f"{hypervector.API_BASE}/definition/{ensemble.definition_uuid}" \
4141
f"/ensemble/{ensemble.ensemble_uuid}"
4242
endpoint = f"{parent_endpoint}/benchmarks"
43-
response = requests.get(endpoint, headers=cls.get_headers())
44-
return [cls.from_response(obj) for obj in response.json()]
43+
response = cls.request(endpoint)
44+
return [cls.from_response(obj) for obj in response]
4545

4646
@classmethod
4747
def new(cls, ensemble, expected_output):

hypervector/resources/core/definition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def refresh(self):
4545
@classmethod
4646
def list(cls):
4747
endpoint = f"{hypervector.API_BASE}/definitions"
48-
response = requests.get(endpoint, headers=cls.get_headers()).json()
48+
response = cls.request(endpoint)
4949
return [cls.from_response(definition) for definition in response]
5050

5151
@classmethod

hypervector/resources/core/ensemble.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def refresh(self):
5454
def list(cls, definition):
5555
parent_endpoint = f"{hypervector.API_BASE}/definition/{definition.definition_uuid}"
5656
endpoint = f"{parent_endpoint}/ensembles"
57-
response = requests.get(endpoint, headers=cls.get_headers()).json()
57+
response = cls.request(endpoint)
5858
return [cls.from_response(ensemble) for ensemble in response]
5959

6060
@classmethod

hypervector/resources/core/project.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ def list(cls):
4747
def new(cls):
4848
endpoint = hypervector.API_BASE + "/" + cls.resource_name + "/new"
4949
response = requests.post(endpoint, headers=cls.get_headers()).json()
50-
5150
return cls.from_response(response)
5251

5352

0 commit comments

Comments
 (0)