init
This commit is contained in:
24
windows_py_client/synctv_client/api_client.py
Normal file
24
windows_py_client/synctv_client/api_client.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import requests
|
||||
|
||||
from .models import RoomInfo, RoomSnapshot
|
||||
|
||||
|
||||
class ApiClient:
|
||||
def __init__(self, base_url: str) -> None:
|
||||
self.base_url = base_url.rstrip("/")
|
||||
|
||||
def create_room(self) -> RoomInfo:
|
||||
response = requests.post(f"{self.base_url}/api/rooms", timeout=10)
|
||||
response.raise_for_status()
|
||||
return RoomInfo.from_json(response.json()["room"])
|
||||
|
||||
def get_room(self, code: str, device_id: str) -> RoomSnapshot:
|
||||
response = requests.get(
|
||||
f"{self.base_url}/api/rooms/{code}",
|
||||
params={"deviceId": device_id},
|
||||
timeout=10,
|
||||
)
|
||||
response.raise_for_status()
|
||||
return RoomSnapshot.from_json(response.json())
|
||||
Reference in New Issue
Block a user