Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

111 wiersze
2.7 KiB

  1. from http import HTTPStatus
  2. from typing import Any, Optional, Union
  3. import httpx
  4. from ... import errors
  5. from ...client import AuthenticatedClient, Client
  6. from ...models.gateway_item import GatewayItem
  7. from ...types import Response
  8. def _get_kwargs(
  9. *,
  10. body: GatewayItem,
  11. ) -> dict[str, Any]:
  12. headers: dict[str, Any] = {}
  13. _kwargs: dict[str, Any] = {
  14. "method": "post",
  15. "url": "/postGateway",
  16. }
  17. _kwargs["json"] = body.to_dict()
  18. headers["Content-Type"] = "application/json"
  19. _kwargs["headers"] = headers
  20. return _kwargs
  21. def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]:
  22. if response.status_code == 201:
  23. return None
  24. if response.status_code == 400:
  25. return None
  26. if response.status_code == 409:
  27. return None
  28. if client.raise_on_unexpected_status:
  29. raise errors.UnexpectedStatus(response.status_code, response.content)
  30. else:
  31. return None
  32. def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]:
  33. return Response(
  34. status_code=HTTPStatus(response.status_code),
  35. content=response.content,
  36. headers=response.headers,
  37. parsed=_parse_response(client=client, response=response),
  38. )
  39. def sync_detailed(
  40. *,
  41. client: Union[AuthenticatedClient, Client],
  42. body: GatewayItem,
  43. ) -> Response[Any]:
  44. """Post a gateway item
  45. Post a gateway item
  46. Args:
  47. body (GatewayItem): A gateway of the system
  48. Raises:
  49. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  50. httpx.TimeoutException: If the request takes longer than Client.timeout.
  51. Returns:
  52. Response[Any]
  53. """
  54. kwargs = _get_kwargs(
  55. body=body,
  56. )
  57. response = client.get_httpx_client().request(
  58. **kwargs,
  59. )
  60. return _build_response(client=client, response=response)
  61. async def asyncio_detailed(
  62. *,
  63. client: Union[AuthenticatedClient, Client],
  64. body: GatewayItem,
  65. ) -> Response[Any]:
  66. """Post a gateway item
  67. Post a gateway item
  68. Args:
  69. body (GatewayItem): A gateway of the system
  70. Raises:
  71. errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
  72. httpx.TimeoutException: If the request takes longer than Client.timeout.
  73. Returns:
  74. Response[Any]
  75. """
  76. kwargs = _get_kwargs(
  77. body=body,
  78. )
  79. response = await client.get_async_httpx_client().request(**kwargs)
  80. return _build_response(client=client, response=response)