From 8551865b4ab342d5f0dfdfafda313b3d8a4d8fa4 Mon Sep 17 00:00:00 2001 From: Jonas Gunz Date: Tue, 16 Jan 2024 17:14:47 +0100 Subject: HttpJsonState --- automato/state/__init__.py | 2 +- automato/state/http.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 automato/state/http.py diff --git a/automato/state/__init__.py b/automato/state/__init__.py index bbcb653..1092a45 100644 --- a/automato/state/__init__.py +++ b/automato/state/__init__.py @@ -11,8 +11,8 @@ MUST implement: _collect(self) CAN implement: + _init(self, [transport], ) _get(self, key: str) - init(self, [transport], ) SHOULDNT implement: get(self, key) diff --git a/automato/state/http.py b/automato/state/http.py new file mode 100644 index 0000000..977541b --- /dev/null +++ b/automato/state/http.py @@ -0,0 +1,25 @@ +import logging + +from automato.transport.http import HttpTransport +from automato.state import State + +logger = logging.getLogger(__name__) + + +class HttpJsonState(State): + def _init(self, transport: HttpTransport, method: str, path: str, + json_path: [None,str] = None, **kwargs): + + if json_path is not None: + logger.warning('Filtering of JSON path requested but not implemented') + + self._transport = transport + self._path = path + self._method = method + self._json_path = json_path + self._request_args = kwargs + + def _collect(self): + response = self._transport.request(self._method, self._path, + **self._request_args) + self._data = response.json() -- cgit v1.2.3