This commit is contained in:
@@ -4,6 +4,7 @@ from logging import Logger
|
||||
from pathlib import Path
|
||||
from typing import Dict, List, Optional
|
||||
from uuid import UUID
|
||||
from diskcache import Index
|
||||
|
||||
from platformdirs import PlatformDirs
|
||||
import requests
|
||||
@@ -142,12 +143,15 @@ class Server:
|
||||
self.token = str(token)
|
||||
self.token_type = str(token_type)
|
||||
|
||||
def request(self, log: Logger, table: str, param: Optional[Option] = None):
|
||||
def request(self, log: Logger, table: str, index: Index, param: Optional[Option] = None):
|
||||
"""
|
||||
Requests data from Kontor-API instance by given table and optional parameters.
|
||||
"""
|
||||
if not param:
|
||||
url: str = f"{self.url}/{MAPPING[table]}"
|
||||
if table in index:
|
||||
log.info("use chached %s", table)
|
||||
return index[table]
|
||||
else:
|
||||
url: str = f"{self.url}/{MAPPING[table]}{str(param)}"
|
||||
headers: Dict[str, str] = {"Authorization": f"Bearer {self.token}"}
|
||||
@@ -160,6 +164,8 @@ class Server:
|
||||
if response.status_code == 404:
|
||||
raise EndPointNotAvailableException
|
||||
data = response.json()
|
||||
log.info("cache values of %s", table)
|
||||
index[table] = data
|
||||
return data
|
||||
|
||||
def update(self, log: Logger, table: str, item_id: UUID, file_info: dict):
|
||||
|
||||
Reference in New Issue
Block a user