Нет описания

pagerduty.py 692B

123456789101112131415161718
  1. from typing import Any
  2. import httpx
  3. class PagerDutyAdapter:
  4. def __init__(self, base_url: str, api_key: str) -> None:
  5. self.base_url = base_url.rstrip("/")
  6. self.api_key = api_key
  7. async def create_incident(self, payload: dict[str, Any]) -> dict[str, Any]:
  8. url = f"{self.base_url}/incidents"
  9. headers = {"Authorization": f"Token token={self.api_key}"} if self.api_key else {}
  10. async with httpx.AsyncClient(timeout=20.0) as client:
  11. response = await client.post(url, json=payload, headers=headers)
  12. response.raise_for_status()
  13. return response.json() if response.content else {"status_code": response.status_code}