Add logging and doc

This commit is contained in:
2025-09-05 11:08:40 +02:00
parent 89ff54acfe
commit afd27a811a
2 changed files with 107 additions and 27 deletions

View File

@@ -1,5 +1,8 @@
from typing import Any, cast
import ovh
import logging
logger = logging.getLogger("ovh_factures.fetcher")
def fetch_api(app_key: str, app_secret: str, consumer_key: str) -> list[str]:
@@ -12,12 +15,15 @@ def fetch_api(app_key: str, app_secret: str, consumer_key: str) -> list[str]:
data: Any = client.get("/me/bill/")
if data is None:
logger.warning("Réponse vide pour /me/bill/")
return []
if not isinstance(data, list) or not all(isinstance(x, str) for x in data):
logger.error("Réponse inattendue pour /me/bill/: %r", data)
raise TypeError("Réponse OVH inattendue pour /me/bill/: liste de str requise")
bills: list[str] = cast(list[str], data)
logger.info("%d factures détectées dans /me/bill/", len(bills))
return bills
@@ -32,5 +38,7 @@ def fetch_invoice_content(
)
bill = client.get(f"/me/bill/{id}")
if bill is None:
logger.error("Facture %s introuvable", id)
raise RuntimeError(f"Facture {id} introuvable")
logger.debug("Facture %s récupérée avec succès", id)
return bill