Eerste commit voor rename-mvp
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import httpx
|
||||
from app.config import TVDB_BASE_URL, TVDB_REQUEST_TIMEOUT_SECONDS
|
||||
from app.services.tvdb_auth_service import TvdbAuthService
|
||||
|
||||
|
||||
class TvdbClient:
|
||||
def __init__(self):
|
||||
self.auth = TvdbAuthService()
|
||||
|
||||
def get(self, path: str, params: dict | None = None) -> dict:
|
||||
token = self.auth.get_valid_token()
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
|
||||
with httpx.Client(timeout=TVDB_REQUEST_TIMEOUT_SECONDS) as client:
|
||||
response = client.get(f"{TVDB_BASE_URL}{path}", params=params, headers=headers)
|
||||
|
||||
if response.status_code == 401:
|
||||
token = self.auth.login_and_store_token()["token"]
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
response = client.get(f"{TVDB_BASE_URL}{path}", params=params, headers=headers)
|
||||
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
Reference in New Issue
Block a user