diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2024-01-16 17:14:47 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2024-01-16 17:14:47 +0100 |
commit | 8551865b4ab342d5f0dfdfafda313b3d8a4d8fa4 (patch) | |
tree | f34787a1c42c7e1b24fb5d55dac0449f279370fd | |
parent | e12a23e676d15411443e3ee2f6ea5485cf968fe2 (diff) | |
download | automato-8551865b4ab342d5f0dfdfafda313b3d8a4d8fa4.tar.gz |
HttpJsonState
-rw-r--r-- | automato/state/__init__.py | 2 | ||||
-rw-r--r-- | automato/state/http.py | 25 |
2 files changed, 26 insertions, 1 deletions
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], <other options you might need>) _get(self, key: str) - init(self, [transport], <other options you might need>) 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() |