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

Commit bf81e1d

Browse files
authored
Feedback changes (#1)
1 parent aa11813 commit bf81e1d

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

netbox_python/rest.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,22 @@
1313
class Result:
1414
def __init__(
1515
self,
16-
status_code: int,
17-
headers: CaseInsensitiveDict,
18-
message: str = "",
1916
pagination: dict = None,
2017
params: dict = None,
18+
response: requests.Response = None,
2119
data: List[Dict] = None,
2220
):
2321
"""
2422
Result returned from low-level RestAdapter
25-
:param status_code: Standard HTTP Status code
26-
:param message: Human readable result
23+
:param pagination: {'count': int, 'next': str, 'previous': str} for paginating list returns
24+
:param params: dict of parmas sent in the query
25+
:param response: requests.response object (status, headers) from API call
2726
:param data: Python List of Dictionaries (or maybe just a single Dictionary on error)
2827
"""
29-
self.status_code = int(status_code)
30-
self.headers = headers
31-
self.message = str(message)
32-
self.data = data if data else []
3328
self.pagination = pagination
3429
self.params = params
30+
self.response = response
31+
self.data = data if data else []
3532

3633

3734
class RestClient:
@@ -65,22 +62,18 @@ def request(self, method: str, path: str, **kwargs) -> Result:
6562
f"Invalid request from {self.base_url}: {http_error}"
6663
) from http_error
6764
except requests.RequestException as err:
68-
# self._logger.error(msg=(str(err)))
6965
raise NetBoxException("Request failed") from err
7066

7167
if method != "DELETE":
7268
# Deserialize JSON output to Python object, or return failed Result on exception
7369
try:
7470
data_out = response.json()
7571
except (ValueError, TypeError, JSONDecodeError) as err:
76-
# self._logger.error(msg=log_line_post.format(False, None, e))
7772
raise NetBoxException("Bad JSON in response") from err
7873

7974
# If status_code in 200-299 range, return success Result with data, otherwise raise exception
8075
is_success = 299 >= response.status_code >= 200 # 200 to 299 is OK
81-
# log_line = log_line_post.format(is_success, response.status_code, response.reason)
8276
if is_success:
83-
# self._logger.debug(msg=log_line)
8477
# check if list - fixme: should have cleaner way to do this
8578
pagination = None
8679
if "count" in data_out and "results" in data_out:
@@ -92,14 +85,11 @@ def request(self, method: str, path: str, **kwargs) -> Result:
9285
data_out = data_out.get("results")
9386

9487
return Result(
95-
response.status_code,
96-
headers=response.headers,
97-
message=response.reason,
9888
pagination=pagination,
9989
params=kwargs.get("params", None),
90+
response=response,
10091
data=data_out,
10192
)
102-
# self._logger.error(msg=log_line)
10393
raise NetBoxException(f"{response.status_code}: {response.reason}")
10494

10595
get = partialmethod(request, "GET")

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 0.1.3
2+
current_version = 0.1.4
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@
4242
test_suite="tests",
4343
tests_require=test_requirements,
4444
url="https://github.com/netbox-community/netbox_python",
45-
version="0.1.3",
45+
version="0.1.4",
4646
zip_safe=False,
4747
)

0 commit comments

Comments
 (0)