diff options
-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() |