This commit is contained in:
+31
-13
@@ -28,24 +28,30 @@ MAPPING: Dict[str, str] = {
|
||||
"story_arc": "api/comics/storyarcs",
|
||||
"issue": "api/comics/issues",
|
||||
"issue_work": "api/comics/issueworks",
|
||||
"article": "",
|
||||
"bookshelf_publisher": "",
|
||||
"book": "",
|
||||
"author": "",
|
||||
"article_author": "",
|
||||
"book_author": "",
|
||||
"media_article": "",
|
||||
"article": "api/bookshelf/articles",
|
||||
"bookshelf_publisher": "api/bookshelf/publishers",
|
||||
"book": "api/bookshelf/books",
|
||||
"author": "api/bookshelf/authors",
|
||||
"article_author": "api/bookshelf/articleauthors",
|
||||
"book_author": "api/bookshelf/bookauthors",
|
||||
"media_article": "api/media/articles",
|
||||
"media_video": "api/media/videos",
|
||||
"media_file": "api/media/files",
|
||||
"media_actor": "api/media/actors",
|
||||
"media_actor_file": "api/media/actorfiles",
|
||||
"profile": "",
|
||||
"permission": "",
|
||||
"assignment": "",
|
||||
"token": "",
|
||||
"mail_account": "",
|
||||
"profile": "api/user/profiles",
|
||||
"permission": "api/user/permissions",
|
||||
"assignment": "api/user/assignments",
|
||||
"token": "api/user/tokens",
|
||||
"mail_account": "api/admin/mailaccount",
|
||||
}
|
||||
|
||||
class EndPointNotAvailableException(Exception):
|
||||
"""
|
||||
Raised when calling an not existing endpoint.
|
||||
"""
|
||||
|
||||
pass
|
||||
|
||||
@dataclass
|
||||
class Login:
|
||||
@@ -99,7 +105,9 @@ class Server:
|
||||
url: str = f"{self.url}/{MAPPING[table]}?{param}"
|
||||
headers: Dict[str, str] = {"Authorization": f"Bearer {self.token}"}
|
||||
response = requests.get(url, headers=headers, timeout=self.timeout)
|
||||
log.info(f"Status: {response.status_code}")
|
||||
log.debug(f"Status: {response.status_code}")
|
||||
if response.status_code==404:
|
||||
raise EndPointNotAvailableException
|
||||
data = response.json()
|
||||
return data
|
||||
|
||||
@@ -121,6 +129,16 @@ class ApiConfig:
|
||||
|
||||
login: Login
|
||||
server: List[Server]
|
||||
|
||||
def get_server(self, server_name: str) -> Optional[Server]:
|
||||
"""
|
||||
"""
|
||||
found_server = None
|
||||
for server in self.server:
|
||||
if server.name == server_name:
|
||||
found_server = server
|
||||
return found_server
|
||||
|
||||
|
||||
|
||||
def get_logger(level, config: str):
|
||||
|
||||
Reference in New Issue
Block a user