예제 #1
0
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
예제 #2
0
 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()
예제 #3
0
 def GET_RAW(self,
             path: str,
             meta: CachingMeta = None) -> Tuple[bytes, CachingMeta]:
     raise KoiApiOfflineException()
예제 #4
0
 def _POST_raw(self,
               path: str,
               auth: AuthBase,
               data: bytes = None) -> Tuple[Any, CachingMeta]:
     raise KoiApiOfflineException()
예제 #5
0
 def GET(self,
         path: str,
         meta: CachingMeta = None) -> Tuple[Any, CachingMeta]:
     raise KoiApiOfflineException()
예제 #6
0
 def _PUT(self,
          path: str,
          auth: AuthBase,
          data: Any = None) -> Tuple[Any, CachingMeta]:
     raise KoiApiOfflineException()
예제 #7
0
 def _GET_raw(self, path, auth: AuthBase) -> Tuple[bytes, CachingMeta]:
     raise KoiApiOfflineException()
예제 #8
0
 def _GET(self,
          path: str,
          auth: AuthBase,
          parameter=None) -> Tuple[Any, CachingMeta]:
     raise KoiApiOfflineException()
예제 #9
0
 def _DELETE(self, path: str, auth: AuthBase) -> Tuple[Any, CachingMeta]:
     raise KoiApiOfflineException()
예제 #10
0
 def _HEAD(self, path: str, auth: AuthBase) -> CachingMeta:
     raise KoiApiOfflineException()
예제 #11
0
 def authenticate(self):
     raise KoiApiOfflineException()
예제 #12
0
 def reconnect(self):
     raise KoiApiOfflineException()