feat: initial commit
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
"""Atrapa acme-sdk 2.1.0 - wyłącznie API z wersji 2.x.
|
||||
|
||||
Odpowiada SDK dostarczanemu przez dostawcę: klasa `Client` i metoda `send()` z 1.x
|
||||
zostały usunięte, więc kod sprzed migracji nie zaimportuje się ani nie zadziała.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from .errors import AcmeError
|
||||
|
||||
__version__ = "2.1.0"
|
||||
|
||||
|
||||
@dataclass
|
||||
class Message:
|
||||
id: str
|
||||
recipient: str
|
||||
content: str
|
||||
|
||||
|
||||
class _Messages:
|
||||
def __init__(self, client: "AcmeClient") -> None:
|
||||
self._client = client
|
||||
|
||||
def create(self, recipient: str, content: str) -> Message:
|
||||
if recipient.startswith("odrzuc@"):
|
||||
raise AcmeError("recipient rejected by provider")
|
||||
return Message(id=f"msg_{abs(hash((recipient, content))) % 10**8:08d}", recipient=recipient, content=content)
|
||||
|
||||
|
||||
class AcmeClient:
|
||||
"""Klient 2.x. Zasoby zwalniane automatycznie - brak metody close()."""
|
||||
|
||||
def __init__(self, api_key: str, base_url: str, timeout: float = 10.0) -> None:
|
||||
if not api_key:
|
||||
raise AcmeError("api_key is required")
|
||||
self.api_key = api_key
|
||||
self.base_url = base_url
|
||||
self.timeout = timeout
|
||||
self.messages = _Messages(self)
|
||||
|
||||
def __enter__(self) -> "AcmeClient":
|
||||
return self
|
||||
|
||||
def __exit__(self, *exc_info: object) -> None:
|
||||
return None
|
||||
|
||||
|
||||
__all__ = ["AcmeClient", "AcmeError", "Message", "__version__"]
|
||||
@@ -0,0 +1,5 @@
|
||||
"""Hierarchia błędów acme-sdk - niezmieniona między 1.x a 2.x."""
|
||||
|
||||
|
||||
class AcmeError(Exception):
|
||||
"""Błąd zwrócony przez dostawcę."""
|
||||
Reference in New Issue
Block a user