def common_authenticated(self: "BaseAPI", request_func, *args, **kwargs): if not self.online: raise KoiApiOfflineException() authenticate_locked(self) try: response = request_func(self, *args, auth=BearerAuth(self._token), **kwargs) except (requests.exceptions.Timeout, requests.exceptions.ConnectionError): self.online = False raise KoiApiOfflineException() if response.status_code != 200: if response.status_code == 404: raise LookupError() elif response.status_code == 401: authenticate_locked(self, True) response = request_func(self, *args, auth=BearerAuth(self._token), **kwargs) if response.status_code != 200: raise Exception(f"{response.status_code}: {response.content}") else: raise Exception(f"{response.status_code}: {response.content}") meta = getCachingMeta(response.headers) return response, meta
def authenticate(self): if not self.online: raise KoiApiOfflineException() try: response = self._session.post( self._base_url + "/api/login", json={ "user_name": self._user, "password": self._password, }, ) if not response.status_code == 200: raise ValueError("invalid login") self._token = response.json()["token"] except (requests.exceptions.Timeout, requests.exceptions.ConnectionError): self.online = False raise KoiApiOfflineException()
def GET_RAW(self, path: str, meta: CachingMeta = None) -> Tuple[bytes, CachingMeta]: raise KoiApiOfflineException()
def _POST_raw(self, path: str, auth: AuthBase, data: bytes = None) -> Tuple[Any, CachingMeta]: raise KoiApiOfflineException()
def GET(self, path: str, meta: CachingMeta = None) -> Tuple[Any, CachingMeta]: raise KoiApiOfflineException()
def _PUT(self, path: str, auth: AuthBase, data: Any = None) -> Tuple[Any, CachingMeta]: raise KoiApiOfflineException()
def _GET_raw(self, path, auth: AuthBase) -> Tuple[bytes, CachingMeta]: raise KoiApiOfflineException()
def _GET(self, path: str, auth: AuthBase, parameter=None) -> Tuple[Any, CachingMeta]: raise KoiApiOfflineException()
def _DELETE(self, path: str, auth: AuthBase) -> Tuple[Any, CachingMeta]: raise KoiApiOfflineException()
def _HEAD(self, path: str, auth: AuthBase) -> CachingMeta: raise KoiApiOfflineException()
def authenticate(self): raise KoiApiOfflineException()
def reconnect(self): raise KoiApiOfflineException()