Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rest_api_device): Enable sending raw data for restful api devices. #107

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading