|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +from typing import TYPE_CHECKING, Any, NamedTuple |
| 4 | + |
| 5 | +from ..core import BoundModelBase, ClientEntityBase, Meta |
| 6 | +from .domain import StorageBoxType |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from .._client import Client |
| 10 | + |
| 11 | + |
| 12 | +class BoundStorageBoxType(BoundModelBase, StorageBoxType): |
| 13 | + _client: StorageBoxTypesClient |
| 14 | + |
| 15 | + model = StorageBoxType |
| 16 | + |
| 17 | + |
| 18 | +class StorageBoxTypesPageResult(NamedTuple): |
| 19 | + storage_box_types: list[BoundStorageBoxType] |
| 20 | + meta: Meta |
| 21 | + |
| 22 | + |
| 23 | +class StorageBoxTypesClient(ClientEntityBase): |
| 24 | + """ |
| 25 | + A client for the Storage Box Types API. |
| 26 | +
|
| 27 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types. |
| 28 | + """ |
| 29 | + |
| 30 | + _client: Client |
| 31 | + |
| 32 | + def get_by_id(self, id: int) -> BoundStorageBoxType: |
| 33 | + """ |
| 34 | + Returns a specific Storage Box Type. |
| 35 | +
|
| 36 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-get-a-storage-box-type |
| 37 | +
|
| 38 | + :param id: ID of the Storage Box Type. |
| 39 | + """ |
| 40 | + response = self._client._request_hetzner( # pylint: disable=protected-access |
| 41 | + method="GET", |
| 42 | + url=f"/storage_box_types/{id}", |
| 43 | + ) |
| 44 | + return BoundStorageBoxType(self, response["storage_box_type"]) |
| 45 | + |
| 46 | + def get_by_name(self, name: str) -> BoundStorageBoxType | None: |
| 47 | + """ |
| 48 | + Returns a specific Storage Box Type. |
| 49 | +
|
| 50 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-list-storage-box-types |
| 51 | +
|
| 52 | + :param name: Name of the Storage Box Type. |
| 53 | + """ |
| 54 | + return self._get_first_by(name=name) |
| 55 | + |
| 56 | + def get_list( |
| 57 | + self, |
| 58 | + name: str | None = None, |
| 59 | + page: int | None = None, |
| 60 | + per_page: int | None = None, |
| 61 | + ) -> StorageBoxTypesPageResult: |
| 62 | + """ |
| 63 | + Returns a list of Storage Box Types for a specific page. |
| 64 | +
|
| 65 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-list-storage-box-types |
| 66 | +
|
| 67 | + :param name: Name of the Storage Box Type. |
| 68 | + :param page: Page number to return. |
| 69 | + :param per_page: Maximum number of entries returned per page. |
| 70 | + """ |
| 71 | + params: dict[str, Any] = {} |
| 72 | + if name is not None: |
| 73 | + params["name"] = name |
| 74 | + if page is not None: |
| 75 | + params["page"] = page |
| 76 | + if per_page is not None: |
| 77 | + params["per_page"] = per_page |
| 78 | + |
| 79 | + response = self._client._request_hetzner( # pylint: disable=protected-access |
| 80 | + method="GET", |
| 81 | + url="/storage_box_types", |
| 82 | + params=params, |
| 83 | + ) |
| 84 | + return StorageBoxTypesPageResult( |
| 85 | + storage_box_types=[ |
| 86 | + BoundStorageBoxType(self, o) for o in response["storage_box_types"] |
| 87 | + ], |
| 88 | + meta=Meta.parse_meta(response), |
| 89 | + ) |
| 90 | + |
| 91 | + def get_all( |
| 92 | + self, |
| 93 | + name: str | None = None, |
| 94 | + ) -> list[BoundStorageBoxType]: |
| 95 | + """ |
| 96 | + Returns all Storage Box Types. |
| 97 | +
|
| 98 | + See https://docs.hetzner.cloud/reference/hetzner#storage-box-types-list-storage-box-types |
| 99 | +
|
| 100 | + :param name: Name of the Storage Box Type. |
| 101 | + """ |
| 102 | + return self._iter_pages( |
| 103 | + self.get_list, |
| 104 | + name=name, |
| 105 | + ) |
0 commit comments