refactor: extract MdrsClient service layer for library portability

To improve the tool's portability as a Python library, the core logic
has been decoupled from the CLI interface. This allows developers to
programmatically interact with MDRS without relying on CLI-specific
argument parsing or local file-based caches.

- Introduce `MdrsClient` service layer to handle core operations.
- Abstract authentication state using `CacheInterface` and `InMemoryCache`.
- Migrate all CLI commands to utilize `MdrsClient` for execution.
- Separate `Doi` data model from API responses and move to `models/doi.py`.
- Update `README.md` to include Python API usage examples.
- Bump package version to 1.3.17.
This commit is contained in:
2026-07-02 13:07:18 +09:00
parent 809140dfbc
commit 36cad6db52
28 changed files with 736 additions and 215 deletions
+6 -11
View File
@@ -21,20 +21,15 @@ class LoginCommand(BaseCommand):
@classmethod
def func(cls, args: Namespace) -> None:
remote = str(args.remote)
username = str(args.username) if args.password else input("Username: ").strip()
username = str(args.username) if args.username else input("Username: ").strip()
password = str(args.password) if args.password else getpass.getpass("Password: ").strip()
cls.login(remote, username, password)
@classmethod
def login(cls, remote: str, username: str, password: str) -> None:
remote = cls._parse_remote_host(remote)
config = ConfigFile(remote)
if config.url is None:
raise MissingConfigurationException(f"Remote host `{remote}` is not found.")
connection = MDRSConnection(config.remote, config.url)
user_api = UsersApi(connection)
token = user_api.token(username, password)
connection.token = token
user = user_api.current()
connection.user = user
remote_host = cls._parse_remote_host(remote)
from mdrsclient.client import MdrsClient
client = MdrsClient.from_remote(remote_host)
client.login(username, password)
print("Login Successful")