changed API endpoint from v2 to v3.

This commit is contained in:
2023-12-12 20:05:46 +09:00
parent f10b42a1f2
commit 292ca1df27
19 changed files with 61 additions and 68 deletions

View File

@@ -1,11 +1,11 @@
from mdrsclient.api.file import FileApi
from mdrsclient.api.folder import FolderApi
from mdrsclient.api.laboratory import LaboratoryApi
from mdrsclient.api.files import FilesApi
from mdrsclient.api.folders import FoldersApi
from mdrsclient.api.laboratories import LaboratoriesApi
from mdrsclient.api.users import UsersApi
__all__ = [
"FileApi",
"FolderApi",
"LaboratoryApi",
"FilesApi",
"FoldersApi",
"LaboratoriesApi",
"UsersApi",
]

View File

@@ -10,12 +10,12 @@ from mdrsclient.models import File
@dataclass(frozen=True)
class FileCreateResponse:
class FilesApiCreateResponse:
id: str
class FileApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/file/"
class FilesApi(BaseApi):
ENTRYPOINT: Final[str] = "v3/files/"
def retrieve(self, id: str) -> File:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
@@ -34,7 +34,7 @@ class FileApi(BaseApi):
with open(path, mode="rb") as fp:
response = self.connection.post(url, data=data, files={"file": fp})
self._raise_response_error(response)
ret = TypeAdapter(FileCreateResponse).validate_python(response.json())
ret = TypeAdapter(FilesApiCreateResponse).validate_python(response.json())
except OSError:
raise UnexpectedException(f"Could not open `{path}` file.")
return ret.id
@@ -93,7 +93,7 @@ class FileApi(BaseApi):
def download(self, file: File, path: str) -> bool:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
url = "v2/" + file.download_url
url = file.download_url
response = self.connection.get(url, stream=True)
self._raise_response_error(response)
try:

View File

@@ -11,12 +11,12 @@ from mdrsclient.models import Folder, FolderSimple
@dataclass(frozen=True)
class FolderCreateResponse:
class FoldersApiCreateResponse:
id: str
class FolderApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/folder/"
class FoldersApi(BaseApi):
ENTRYPOINT: Final[str] = "v3/folders/"
def list(self, laboratory_id: int, path: str) -> list[FolderSimple]:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
@@ -46,7 +46,7 @@ class FolderApi(BaseApi):
token_check(self.connection)
response = self.connection.post(url, data=data)
self._raise_response_error(response)
ret = TypeAdapter(FolderCreateResponse).validate_python(response.json())
ret = TypeAdapter(FoldersApiCreateResponse).validate_python(response.json())
return ret.id
def update(self, folder: FolderSimple) -> bool:

View File

@@ -7,8 +7,8 @@ from mdrsclient.api.utils import token_check
from mdrsclient.models import Laboratories, Laboratory
class LaboratoryApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/laboratory/"
class LaboratoriesApi(BaseApi):
ENTRYPOINT: Final[str] = "v3/laboratories/"
def list(self) -> Laboratories:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)

View File

@@ -1,4 +1,3 @@
from dataclasses import field
from typing import Final
import requests
@@ -7,13 +6,7 @@ from pydantic.dataclasses import dataclass
from mdrsclient.api.base import BaseApi
from mdrsclient.exceptions import UnauthorizedException
from mdrsclient.models import Laboratory, Token, User
@dataclass(frozen=True)
class UserAuthResponse(Token):
is_reviewer: bool | None = None
laboratories: list[Laboratory] = field(default_factory=list)
from mdrsclient.models import Token, User
@dataclass(frozen=True)
@@ -24,7 +17,7 @@ class UsersCurrentResponseLaboratory:
@dataclass(frozen=True)
class UsersCurrentResponse:
class UsersApiCurrentResponse:
id: int
username: str
full_name: str
@@ -39,21 +32,21 @@ class UsersCurrentResponse:
class UsersApi(BaseApi):
ENTRYPOINT: Final[str] = "v2/"
ENTRYPOINT: Final[str] = "v3/users/"
def current(self) -> User:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
url = self.ENTRYPOINT + "users/current/"
url = self.ENTRYPOINT + "current/"
response = self.connection.get(url)
self._raise_response_error(response)
obj = TypeAdapter(UsersCurrentResponse).validate_python(response.json())
obj = TypeAdapter(UsersApiCurrentResponse).validate_python(response.json())
laboratory_ids = list(map(lambda x: x.id, obj.laboratories))
user = User(id=obj.id, username=obj.username, laboratory_ids=laboratory_ids, is_reviewer=obj.is_reviewer)
return user
def token(self, username: str, password: str) -> Token:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
url = self.ENTRYPOINT + "users/token/"
url = self.ENTRYPOINT + "token/"
data: dict[str, str | int] = {"username": username, "password": password}
response = self.connection.post(url, data=data)
if response.status_code == requests.codes.unauthorized:
@@ -64,7 +57,7 @@ class UsersApi(BaseApi):
def tokenRefresh(self, token: Token) -> Token:
# print(self.__class__.__name__ + "::" + sys._getframe().f_code.co_name)
url = self.ENTRYPOINT + "users/token/refresh/"
url = self.ENTRYPOINT + "token/refresh/"
data: dict[str, str | int] = {"refresh": token.refresh}
response = self.connection.post(url, data=data)
if response.status_code == requests.codes.unauthorized: