Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

111 rader
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.setting_item import SettingItem
  7. from ...types import Response
  8. def _get_kwargs(
  9. *,
  10. body: SettingItem,
  11. ) -> dict[str, Any]:
  12. headers: dict[str, Any] = {}
  13. _kwargs: dict[str, Any] = {
  14. "method": "post",
  15. "url": "/postSetting",
  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: SettingItem,
  43. ) -> Response[Any]:
  44. """Post a group of settings
  45. Post a group settings
  46. Args:
  47. body (SettingItem): General setting of the app
  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: SettingItem,
  65. ) -> Response[Any]:
  66. """Post a group of settings
  67. Post a group settings
  68. Args:
  69. body (SettingItem): General setting of the app
  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)