Skip to content

Commit

Permalink
feat(rest_api_device): Enable sending raw data for restful api device…
Browse files Browse the repository at this point in the history
…s. (tektronix#107)

Co-authored-by: Collin Charvat <[email protected]>
  • Loading branch information
2 people authored and qthompso committed Feb 16, 2024
1 parent a1a628c commit 0293232
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ ______________________________________________________________________

Things to be included in the next release go here.

### Added

- Added an option to send raw data for RESTful API devices

### Changed

- Updated the package classifiers for PyPI
Expand Down
38 changes: 32 additions & 6 deletions src/tm_devices/drivers/api/rest_api/rest_api_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def get( # noqa: PLR0913
def patch( # noqa: PLR0913
self,
url: str,
json_body: Dict[str, Any],
json_body: Optional[Dict[str, Any]] = None,
data_body: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
auth: Optional[Tuple[str, str]] = None,
timeout: Optional[float] = None,
Expand All @@ -154,7 +155,11 @@ def patch( # noqa: PLR0913
Args:
url: The url to PATCH.
json_body: Any data to send to the url.
json_body: Any data to serialize and send to the url.
The "Content-Type" header is set to "application/json".
data_body: Any raw data to send to the url. "Content-Type" must be set manually.
The data is not serialized. WARNING: IF DATA IS PASSED USING THIS ARGUMENT
THEN ANY DATA PASSED USING THE ``json_body`` ARGUMENT WILL BE IGNORED.
headers: The headers to use during the request.
auth: A tuple containing the username and password to use in the request.
timeout: How many seconds to wait for the server to send data before giving up.
Expand All @@ -172,6 +177,7 @@ def patch( # noqa: PLR0913
SupportedRequestTypes.PATCH,
url,
json_body=json_body,
data_body=data_body,
headers=headers,
auth=auth,
timeout=timeout,
Expand All @@ -187,6 +193,7 @@ def post( # noqa: PLR0913
self,
url: str,
json_body: Optional[Dict[str, Any]] = None,
data_body: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
auth: Optional[Tuple[str, str]] = None,
timeout: Optional[float] = None,
Expand All @@ -200,7 +207,11 @@ def post( # noqa: PLR0913
Args:
url: The url to POST.
json_body: Any data to send to the url.
json_body: Any data to serialize and send to the url.
The "Content-Type" header is set to "application/json".
data_body: Any raw data to send to the url. "Content-Type" must be set manually.
The data is not serialized. WARNING: IF DATA IS PASSED USING THIS ARGUMENT
THEN ANY DATA PASSED USING THE ``json_body`` ARGUMENT WILL BE IGNORED.
headers: The headers to use during the request.
auth: A tuple containing the username and password to use in the request.
timeout: How many seconds to wait for the server to send data before giving up.
Expand All @@ -218,6 +229,7 @@ def post( # noqa: PLR0913
SupportedRequestTypes.POST,
url,
json_body=json_body,
data_body=data_body,
headers=headers,
auth=auth,
timeout=timeout,
Expand All @@ -232,7 +244,8 @@ def post( # noqa: PLR0913
def put( # noqa: PLR0913
self,
url: str,
json_body: Dict[str, Any],
json_body: Optional[Dict[str, Any]] = None,
data_body: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
auth: Optional[Tuple[str, str]] = None,
timeout: Optional[float] = None,
Expand All @@ -246,7 +259,11 @@ def put( # noqa: PLR0913
Args:
url: The url to PUT.
json_body: Any data to send to the url.
json_body: Any data to serialize and send to the url.
The "Content-Type" header is set to "application/json".
data_body: Any raw data to send to the url. "Content-Type" must be set manually.
The data is not serialized. WARNING: IF DATA IS PASSED USING THIS ARGUMENT
THEN ANY DATA PASSED USING THE ``json_body`` ARGUMENT WILL BE IGNORED.
headers: The headers to use during the request.
auth: A tuple containing the username and password to use in the request.
timeout: How many seconds to wait for the server to send data before giving up.
Expand All @@ -264,6 +281,7 @@ def put( # noqa: PLR0913
SupportedRequestTypes.PUT,
url,
json_body=json_body,
data_body=data_body,
headers=headers,
auth=auth,
timeout=timeout,
Expand Down Expand Up @@ -362,6 +380,7 @@ def _send_request( # noqa: PLR0913,PLR0912,C901
request_type: SupportedRequestTypes,
url: str,
json_body: Optional[Dict[str, Any]] = None,
data_body: Optional[str] = None,
headers: Optional[Mapping[str, str]] = None,
auth: Optional[Tuple[str, str]] = None,
timeout: Optional[float] = None,
Expand All @@ -376,7 +395,11 @@ def _send_request( # noqa: PLR0913,PLR0912,C901
Args:
request_type: The type of request to send.
url: The url to use.
json_body: Any data to send to the url.
json_body: Any data to serialize and send to the url.
The "Content-Type" header is set to "application/json".
data_body: Any raw data to send to the url. "Content-Type" must be set manually.
The data is not serialized. WARNING: IF DATA IS PASSED USING THIS ARGUMENT
THEN ANY DATA PASSED USING THE ``json_body`` ARGUMENT WILL BE IGNORED.
headers: The headers to use during the request.
auth: A tuple containing the username and password to use in the request.
timeout: How many seconds to wait for the server to send data before giving up.
Expand Down Expand Up @@ -435,6 +458,7 @@ def _send_request( # noqa: PLR0913,PLR0912,C901
headers=headers,
auth=auth,
json=json_body,
data=data_body,
timeout=timeout,
verify=verify_ssl,
allow_redirects=allow_redirects,
Expand All @@ -445,6 +469,7 @@ def _send_request( # noqa: PLR0913,PLR0912,C901
headers=headers,
auth=auth,
json=json_body,
data=data_body,
timeout=timeout,
verify=verify_ssl,
allow_redirects=allow_redirects,
Expand All @@ -455,6 +480,7 @@ def _send_request( # noqa: PLR0913,PLR0912,C901
headers=headers,
auth=auth,
json=json_body,
data=data_body,
timeout=timeout,
verify=verify_ssl,
allow_redirects=allow_redirects,
Expand Down

0 comments on commit 0293232

Please sign in to comment.