|
| 1 | +from enum import Enum |
| 2 | + |
| 3 | +from box_sdk_gen.internal.base_object import BaseObject |
| 4 | + |
| 5 | +from typing import Optional |
| 6 | + |
| 7 | +from typing import Dict |
| 8 | + |
| 9 | +from box_sdk_gen.internal.utils import to_string |
| 10 | + |
| 11 | +from box_sdk_gen.serialization.json import deserialize |
| 12 | + |
| 13 | +from typing import List |
| 14 | + |
| 15 | +from box_sdk_gen.serialization.json import serialize |
| 16 | + |
| 17 | +from box_sdk_gen.networking.fetch_options import ResponseFormat |
| 18 | + |
| 19 | +from box_sdk_gen.schemas.v2025_r0.file_reference_v2025_r0 import FileReferenceV2025R0 |
| 20 | + |
| 21 | +from box_sdk_gen.schemas.v2025_r0.file_version_base_v2025_r0 import ( |
| 22 | + FileVersionBaseV2025R0, |
| 23 | +) |
| 24 | + |
| 25 | +from box_sdk_gen.schemas.v2025_r0.doc_gen_document_generation_data_v2025_r0 import ( |
| 26 | + DocGenDocumentGenerationDataV2025R0, |
| 27 | +) |
| 28 | + |
| 29 | +from box_sdk_gen.schemas.v2025_r0.doc_gen_job_v2025_r0 import DocGenJobV2025R0 |
| 30 | + |
| 31 | +from box_sdk_gen.schemas.v2025_r0.client_error_v2025_r0 import ClientErrorV2025R0 |
| 32 | + |
| 33 | +from box_sdk_gen.parameters.v2025_r0.box_version_header_v2025_r0 import ( |
| 34 | + BoxVersionHeaderV2025R0, |
| 35 | +) |
| 36 | + |
| 37 | +from box_sdk_gen.schemas.v2025_r0.doc_gen_jobs_full_v2025_r0 import ( |
| 38 | + DocGenJobsFullV2025R0, |
| 39 | +) |
| 40 | + |
| 41 | +from box_sdk_gen.schemas.v2025_r0.doc_gen_jobs_v2025_r0 import DocGenJobsV2025R0 |
| 42 | + |
| 43 | +from box_sdk_gen.schemas.v2025_r0.doc_gen_batch_base_v2025_r0 import ( |
| 44 | + DocGenBatchBaseV2025R0, |
| 45 | +) |
| 46 | + |
| 47 | +from box_sdk_gen.schemas.v2025_r0.doc_gen_batch_create_request_v2025_r0 import ( |
| 48 | + DocGenBatchCreateRequestV2025R0, |
| 49 | +) |
| 50 | + |
| 51 | +from box_sdk_gen.box.errors import BoxSDKError |
| 52 | + |
| 53 | +from box_sdk_gen.networking.auth import Authentication |
| 54 | + |
| 55 | +from box_sdk_gen.networking.network import NetworkSession |
| 56 | + |
| 57 | +from box_sdk_gen.networking.fetch_options import FetchOptions |
| 58 | + |
| 59 | +from box_sdk_gen.networking.fetch_response import FetchResponse |
| 60 | + |
| 61 | +from box_sdk_gen.internal.utils import prepare_params |
| 62 | + |
| 63 | +from box_sdk_gen.internal.utils import to_string |
| 64 | + |
| 65 | +from box_sdk_gen.internal.utils import ByteStream |
| 66 | + |
| 67 | +from box_sdk_gen.serialization.json import sd_to_json |
| 68 | + |
| 69 | +from box_sdk_gen.serialization.json import SerializedData |
| 70 | + |
| 71 | + |
| 72 | +class CreateDocgenBatchV2025R0DestinationFolderTypeField(str, Enum): |
| 73 | + FOLDER = 'folder' |
| 74 | + |
| 75 | + |
| 76 | +class CreateDocgenBatchV2025R0DestinationFolder(BaseObject): |
| 77 | + _discriminator = 'type', {'folder'} |
| 78 | + |
| 79 | + def __init__( |
| 80 | + self, |
| 81 | + id: str, |
| 82 | + *, |
| 83 | + type: CreateDocgenBatchV2025R0DestinationFolderTypeField = CreateDocgenBatchV2025R0DestinationFolderTypeField.FOLDER, |
| 84 | + **kwargs |
| 85 | + ): |
| 86 | + """ |
| 87 | + :param id: ID of the folder |
| 88 | + :type id: str |
| 89 | + :param type: `folder`, defaults to CreateDocgenBatchV2025R0DestinationFolderTypeField.FOLDER |
| 90 | + :type type: CreateDocgenBatchV2025R0DestinationFolderTypeField, optional |
| 91 | + """ |
| 92 | + super().__init__(**kwargs) |
| 93 | + self.id = id |
| 94 | + self.type = type |
| 95 | + |
| 96 | + |
| 97 | +class DocgenManager: |
| 98 | + def __init__( |
| 99 | + self, |
| 100 | + *, |
| 101 | + auth: Optional[Authentication] = None, |
| 102 | + network_session: NetworkSession = None |
| 103 | + ): |
| 104 | + if network_session is None: |
| 105 | + network_session = NetworkSession() |
| 106 | + self.auth = auth |
| 107 | + self.network_session = network_session |
| 108 | + |
| 109 | + def get_docgen_job_by_id_v2025_r0( |
| 110 | + self, |
| 111 | + job_id: str, |
| 112 | + *, |
| 113 | + box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0, |
| 114 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 115 | + ) -> DocGenJobV2025R0: |
| 116 | + """ |
| 117 | + Get details of the Box Doc Gen job. |
| 118 | + :param job_id: Box Doc Gen job ID. |
| 119 | + Example: 123 |
| 120 | + :type job_id: str |
| 121 | + :param box_version: Version header, defaults to BoxVersionHeaderV2025R0._2025_0 |
| 122 | + :type box_version: BoxVersionHeaderV2025R0, optional |
| 123 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 124 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 125 | + """ |
| 126 | + if extra_headers is None: |
| 127 | + extra_headers = {} |
| 128 | + headers_map: Dict[str, str] = prepare_params( |
| 129 | + {'box-version': to_string(box_version), **extra_headers} |
| 130 | + ) |
| 131 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 132 | + FetchOptions( |
| 133 | + url=''.join( |
| 134 | + [ |
| 135 | + self.network_session.base_urls.base_url, |
| 136 | + '/2.0/docgen_jobs/', |
| 137 | + to_string(job_id), |
| 138 | + ] |
| 139 | + ), |
| 140 | + method='GET', |
| 141 | + headers=headers_map, |
| 142 | + response_format=ResponseFormat.JSON, |
| 143 | + auth=self.auth, |
| 144 | + network_session=self.network_session, |
| 145 | + ) |
| 146 | + ) |
| 147 | + return deserialize(response.data, DocGenJobV2025R0) |
| 148 | + |
| 149 | + def get_docgen_jobs_v2025_r0( |
| 150 | + self, |
| 151 | + *, |
| 152 | + marker: Optional[str] = None, |
| 153 | + limit: Optional[int] = None, |
| 154 | + box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0, |
| 155 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 156 | + ) -> DocGenJobsFullV2025R0: |
| 157 | + """ |
| 158 | + Lists all Box Doc Gen jobs for a user. |
| 159 | + :param marker: Defines the position marker at which to begin returning results. This is |
| 160 | + used when paginating using marker-based pagination. |
| 161 | +
|
| 162 | + This requires `usemarker` to be set to `true`., defaults to None |
| 163 | + :type marker: Optional[str], optional |
| 164 | + :param limit: The maximum number of items to return per page., defaults to None |
| 165 | + :type limit: Optional[int], optional |
| 166 | + :param box_version: Version header, defaults to BoxVersionHeaderV2025R0._2025_0 |
| 167 | + :type box_version: BoxVersionHeaderV2025R0, optional |
| 168 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 169 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 170 | + """ |
| 171 | + if extra_headers is None: |
| 172 | + extra_headers = {} |
| 173 | + query_params_map: Dict[str, str] = prepare_params( |
| 174 | + {'marker': to_string(marker), 'limit': to_string(limit)} |
| 175 | + ) |
| 176 | + headers_map: Dict[str, str] = prepare_params( |
| 177 | + {'box-version': to_string(box_version), **extra_headers} |
| 178 | + ) |
| 179 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 180 | + FetchOptions( |
| 181 | + url=''.join( |
| 182 | + [self.network_session.base_urls.base_url, '/2.0/docgen_jobs'] |
| 183 | + ), |
| 184 | + method='GET', |
| 185 | + params=query_params_map, |
| 186 | + headers=headers_map, |
| 187 | + response_format=ResponseFormat.JSON, |
| 188 | + auth=self.auth, |
| 189 | + network_session=self.network_session, |
| 190 | + ) |
| 191 | + ) |
| 192 | + return deserialize(response.data, DocGenJobsFullV2025R0) |
| 193 | + |
| 194 | + def get_docgen_batch_job_by_id_v2025_r0( |
| 195 | + self, |
| 196 | + batch_id: str, |
| 197 | + *, |
| 198 | + marker: Optional[str] = None, |
| 199 | + limit: Optional[int] = None, |
| 200 | + box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0, |
| 201 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 202 | + ) -> DocGenJobsV2025R0: |
| 203 | + """ |
| 204 | + Lists Box Doc Gen jobs in a batch |
| 205 | + :param batch_id: Box Doc Gen batch ID. |
| 206 | + Example: 123 |
| 207 | + :type batch_id: str |
| 208 | + :param marker: Defines the position marker at which to begin returning results. This is |
| 209 | + used when paginating using marker-based pagination. |
| 210 | +
|
| 211 | + This requires `usemarker` to be set to `true`., defaults to None |
| 212 | + :type marker: Optional[str], optional |
| 213 | + :param limit: The maximum number of items to return per page., defaults to None |
| 214 | + :type limit: Optional[int], optional |
| 215 | + :param box_version: Version header, defaults to BoxVersionHeaderV2025R0._2025_0 |
| 216 | + :type box_version: BoxVersionHeaderV2025R0, optional |
| 217 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 218 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 219 | + """ |
| 220 | + if extra_headers is None: |
| 221 | + extra_headers = {} |
| 222 | + query_params_map: Dict[str, str] = prepare_params( |
| 223 | + {'marker': to_string(marker), 'limit': to_string(limit)} |
| 224 | + ) |
| 225 | + headers_map: Dict[str, str] = prepare_params( |
| 226 | + {'box-version': to_string(box_version), **extra_headers} |
| 227 | + ) |
| 228 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 229 | + FetchOptions( |
| 230 | + url=''.join( |
| 231 | + [ |
| 232 | + self.network_session.base_urls.base_url, |
| 233 | + '/2.0/docgen_batch_jobs/', |
| 234 | + to_string(batch_id), |
| 235 | + ] |
| 236 | + ), |
| 237 | + method='GET', |
| 238 | + params=query_params_map, |
| 239 | + headers=headers_map, |
| 240 | + response_format=ResponseFormat.JSON, |
| 241 | + auth=self.auth, |
| 242 | + network_session=self.network_session, |
| 243 | + ) |
| 244 | + ) |
| 245 | + return deserialize(response.data, DocGenJobsV2025R0) |
| 246 | + |
| 247 | + def create_docgen_batch_v2025_r0( |
| 248 | + self, |
| 249 | + file: FileReferenceV2025R0, |
| 250 | + input_source: str, |
| 251 | + destination_folder: CreateDocgenBatchV2025R0DestinationFolder, |
| 252 | + output_type: str, |
| 253 | + document_generation_data: List[DocGenDocumentGenerationDataV2025R0], |
| 254 | + *, |
| 255 | + file_version: Optional[FileVersionBaseV2025R0] = None, |
| 256 | + box_version: BoxVersionHeaderV2025R0 = BoxVersionHeaderV2025R0._2025_0, |
| 257 | + extra_headers: Optional[Dict[str, Optional[str]]] = None |
| 258 | + ) -> DocGenBatchBaseV2025R0: |
| 259 | + """ |
| 260 | + Generates a document using a Box Doc Gen template. |
| 261 | + :param input_source: Source of input. The value has to be `api` for all the API-based document generation requests. |
| 262 | + :type input_source: str |
| 263 | + :param output_type: Type of the output file. |
| 264 | + :type output_type: str |
| 265 | + :param box_version: Version header, defaults to BoxVersionHeaderV2025R0._2025_0 |
| 266 | + :type box_version: BoxVersionHeaderV2025R0, optional |
| 267 | + :param extra_headers: Extra headers that will be included in the HTTP request., defaults to None |
| 268 | + :type extra_headers: Optional[Dict[str, Optional[str]]], optional |
| 269 | + """ |
| 270 | + if extra_headers is None: |
| 271 | + extra_headers = {} |
| 272 | + request_body: Dict = { |
| 273 | + 'file': file, |
| 274 | + 'file_version': file_version, |
| 275 | + 'input_source': input_source, |
| 276 | + 'destination_folder': destination_folder, |
| 277 | + 'output_type': output_type, |
| 278 | + 'document_generation_data': document_generation_data, |
| 279 | + } |
| 280 | + headers_map: Dict[str, str] = prepare_params( |
| 281 | + {'box-version': to_string(box_version), **extra_headers} |
| 282 | + ) |
| 283 | + response: FetchResponse = self.network_session.network_client.fetch( |
| 284 | + FetchOptions( |
| 285 | + url=''.join( |
| 286 | + [self.network_session.base_urls.base_url, '/2.0/docgen_batches'] |
| 287 | + ), |
| 288 | + method='POST', |
| 289 | + headers=headers_map, |
| 290 | + data=serialize(request_body), |
| 291 | + content_type='application/json', |
| 292 | + response_format=ResponseFormat.JSON, |
| 293 | + auth=self.auth, |
| 294 | + network_session=self.network_session, |
| 295 | + ) |
| 296 | + ) |
| 297 | + return deserialize(response.data, DocGenBatchBaseV2025R0) |
0 commit comments