|
| 1 | +from typing import Optional |
| 2 | + |
| 3 | +from typing import Dict |
| 4 | + |
| 5 | +from box_sdk_gen.internal.utils import to_string |
| 6 | + |
| 7 | +from box_sdk_gen.serialization.json import deserialize |
| 8 | + |
| 9 | +from typing import List |
| 10 | + |
| 11 | +from box_sdk_gen.serialization.json import serialize |
| 12 | + |
| 13 | +from box_sdk_gen.networking.fetch_options import ResponseFormat |
| 14 | + |
| 15 | +from box_sdk_gen.schemas.v2025_r0.hub_item_operation_v2025_r0 import ( |
| 16 | + HubItemOperationV2025R0, |
| 17 | +) |
| 18 | + |
| 19 | +from box_sdk_gen.schemas.v2025_r0.hub_items_v2025_r0 import HubItemsV2025R0 |
| 20 | + |
| 21 | +from box_sdk_gen.schemas.v2025_r0.client_error_v2025_r0 import ClientErrorV2025R0 |
| 22 | + |
| 23 | +from box_sdk_gen.parameters.v2025_r0.box_version_header_v2025_r0 import ( |
| 24 | + BoxVersionHeaderV2025R0, |
| 25 | +) |
| 26 | + |
| 27 | +from box_sdk_gen.schemas.v2025_r0.hub_items_manage_response_v2025_r0 import ( |
| 28 | + HubItemsManageResponseV2025R0, |
| 29 | +) |
| 30 | + |
| 31 | +from box_sdk_gen.schemas.v2025_r0.hub_items_manage_request_v2025_r0 import ( |
| 32 | + HubItemsManageRequestV2025R0, |
| 33 | +) |
| 34 | + |
| 35 | +from box_sdk_gen.box.errors import BoxSDKError |
| 36 | + |
| 37 | +from box_sdk_gen.networking.auth import Authentication |
| 38 | + |
| 39 | +from box_sdk_gen.networking.network import NetworkSession |
| 40 | + |
| 41 | +from box_sdk_gen.networking.fetch_options import FetchOptions |
| 42 | + |
| 43 | +from box_sdk_gen.networking.fetch_response import FetchResponse |
| 44 | + |
| 45 | +from box_sdk_gen.internal.utils import prepare_params |
| 46 | + |
| 47 | +from box_sdk_gen.internal.utils import to_string |
| 48 | + |
| 49 | +from box_sdk_gen.internal.utils import ByteStream |
| 50 | + |
| 51 | +from box_sdk_gen.serialization.json import sd_to_json |
| 52 | + |
| 53 | +from box_sdk_gen.serialization.json import SerializedData |
| 54 | + |
| 55 | + |
| 56 | +class HubItemsManager: |
| 57 | + def __init__( |
| 58 | + self, |
| 59 | + *, |
| 60 | + auth: Optional[Authentication] = None, |
| 61 | + network_session: NetworkSession = None |
| 62 | + ): |
| 63 | + if network_session is None: |
| 64 | + network_session = NetworkSession() |
| 65 | + self.auth = auth |
| 66 | + self.network_session = network_session |
| 67 | + |
| 68 | + def get_hub_items_v2025_r0( |
| 69 | + self, |
| 70 | + hub_id: str, |
| 71 | + *, |
| 72 | + marker: Optional[str] = None, |
| 73 | + limit: Optional[int] = None, |
| 74 | + box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0, |
| 75 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 76 | + ) -> HubItemsV2025R0: |
| 77 | + """ |
| 78 | + Retrieves all items associated with a Hub. |
| 79 | + :param hub_id: The unique identifier that represent a hub. |
| 80 | +
|
| 81 | + The ID for any hub can be determined |
| 82 | + by visiting this hub in the web application |
| 83 | + and copying the ID from the URL. For example, |
| 84 | + for the URL `https://*.app.box.com/hubs/123` |
| 85 | + the `hub_id` is `123`. |
| 86 | + :type hub_id: str |
| 87 | + :param marker: Defines the position marker at which to begin returning results. This is |
| 88 | + used when paginating using marker-based pagination. |
| 89 | +
|
| 90 | + This requires `usemarker` to be set to `true`., defaults to None |
| 91 | + :type marker: Optional[str], optional |
| 92 | + :param limit: The maximum number of items to return per page., defaults to None |
| 93 | + :type limit: Optional[int], optional |
| 94 | + :param box_version: Version header., defaults to BoxVersionHeaderV2025R0._2025_0 |
| 95 | + :type box_version: BoxVersionHeaderV2025R0, optional |
| 96 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 97 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 98 | + """ |
| 99 | + if extra_headers is None: |
| 100 | + extra_headers = {} |
| 101 | + query_params_map: Dict[str, str] = prepare_params( |
| 102 | + { |
| 103 | + 'hub_id': to_string(hub_id), |
| 104 | + 'marker': to_string(marker), |
| 105 | + 'limit': to_string(limit), |
| 106 | + } |
| 107 | + ) |
| 108 | + headers_map: Dict[str, str] = prepare_params( |
| 109 | + {'box-version': to_string(box_version), **extra_headers} |
| 110 | + ) |
| 111 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 112 | + FetchOptions( |
| 113 | + url=''.join( |
| 114 | + [self.network_session.base_urls.base_url, '/2.0/hub_items'] |
| 115 | + ), |
| 116 | + method='GET', |
| 117 | + params=query_params_map, |
| 118 | + headers=headers_map, |
| 119 | + response_format=ResponseFormat.JSON, |
| 120 | + auth=self.auth, |
| 121 | + network_session=self.network_session, |
| 122 | + ) |
| 123 | + ) |
| 124 | + return deserialize(response.data, HubItemsV2025R0) |
| 125 | + |
| 126 | + def create_hub_manage_item_v2025_r0( |
| 127 | + self, |
| 128 | + hub_id: str, |
| 129 | + *, |
| 130 | + operations: Optional[List[HubItemOperationV2025R0]] = None, |
| 131 | + box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0, |
| 132 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 133 | + ) -> HubItemsManageResponseV2025R0: |
| 134 | + """ |
| 135 | + Adds and/or removes Hub items from a Hub. |
| 136 | + :param hub_id: The unique identifier that represent a hub. |
| 137 | +
|
| 138 | + The ID for any hub can be determined |
| 139 | + by visiting this hub in the web application |
| 140 | + and copying the ID from the URL. For example, |
| 141 | + for the URL `https://*.app.box.com/hubs/123` |
| 142 | + the `hub_id` is `123`. |
| 143 | + Example: "12345" |
| 144 | + :type hub_id: str |
| 145 | + :param operations: List of operations to perform on Hub items., defaults to None |
| 146 | + :type operations: Optional[List[HubItemOperationV2025R0]], optional |
| 147 | + :param box_version: Version header., defaults to BoxVersionHeaderV2025R0._2025_0 |
| 148 | + :type box_version: BoxVersionHeaderV2025R0, optional |
| 149 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 150 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 151 | + """ |
| 152 | + if extra_headers is None: |
| 153 | + extra_headers = {} |
| 154 | + request_body: Dict = {'operations': operations} |
| 155 | + headers_map: Dict[str, str] = prepare_params( |
| 156 | + {'box-version': to_string(box_version), **extra_headers} |
| 157 | + ) |
| 158 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 159 | + FetchOptions( |
| 160 | + url=''.join( |
| 161 | + [ |
| 162 | + self.network_session.base_urls.base_url, |
| 163 | + '/2.0/hubs/', |
| 164 | + to_string(hub_id), |
| 165 | + '/manage_items', |
| 166 | + ] |
| 167 | + ), |
| 168 | + method='POST', |
| 169 | + headers=headers_map, |
| 170 | + data=serialize(request_body), |
| 171 | + content_type='application/json', |
| 172 | + response_format=ResponseFormat.JSON, |
| 173 | + auth=self.auth, |
| 174 | + network_session=self.network_session, |
| 175 | + ) |
| 176 | + ) |
| 177 | + return deserialize(response.data, HubItemsManageResponseV2025R0) |
0 commit comments