|
1 | 1 | # This file was auto-generated by Fern from our API Definition. |
2 | 2 |
|
| 3 | +import contextlib |
3 | 4 | import typing |
4 | 5 | from json.decoder import JSONDecodeError |
5 | 6 |
|
@@ -122,6 +123,57 @@ def get( |
122 | 123 | raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
123 | 124 | raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
124 | 125 |
|
| 126 | + @contextlib.contextmanager |
| 127 | + def get_zone_file( |
| 128 | + self, domain_id: DomainId, *, request_options: typing.Optional[RequestOptions] = None |
| 129 | + ) -> typing.Iterator[HttpResponse[typing.Iterator[bytes]]]: |
| 130 | + """ |
| 131 | + Parameters |
| 132 | + ---------- |
| 133 | + domain_id : DomainId |
| 134 | +
|
| 135 | + request_options : typing.Optional[RequestOptions] |
| 136 | + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. |
| 137 | +
|
| 138 | + Returns |
| 139 | + ------- |
| 140 | + typing.Iterator[HttpResponse[typing.Iterator[bytes]]] |
| 141 | + """ |
| 142 | + with self._client_wrapper.httpx_client.stream( |
| 143 | + f"v0/domains/{jsonable_encoder(domain_id)}/zone-file", |
| 144 | + base_url=self._client_wrapper.get_environment().http, |
| 145 | + method="GET", |
| 146 | + request_options=request_options, |
| 147 | + ) as _response: |
| 148 | + |
| 149 | + def _stream() -> HttpResponse[typing.Iterator[bytes]]: |
| 150 | + try: |
| 151 | + if 200 <= _response.status_code < 300: |
| 152 | + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None |
| 153 | + return HttpResponse( |
| 154 | + response=_response, data=(_chunk for _chunk in _response.iter_bytes(chunk_size=_chunk_size)) |
| 155 | + ) |
| 156 | + _response.read() |
| 157 | + if _response.status_code == 404: |
| 158 | + raise NotFoundError( |
| 159 | + headers=dict(_response.headers), |
| 160 | + body=typing.cast( |
| 161 | + ErrorResponse, |
| 162 | + construct_type( |
| 163 | + type_=ErrorResponse, # type: ignore |
| 164 | + object_=_response.json(), |
| 165 | + ), |
| 166 | + ), |
| 167 | + ) |
| 168 | + _response_json = _response.json() |
| 169 | + except JSONDecodeError: |
| 170 | + raise ApiError( |
| 171 | + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text |
| 172 | + ) |
| 173 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 174 | + |
| 175 | + yield _stream() |
| 176 | + |
125 | 177 | def create( |
126 | 178 | self, |
127 | 179 | *, |
@@ -358,6 +410,58 @@ async def get( |
358 | 410 | raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text) |
359 | 411 | raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
360 | 412 |
|
| 413 | + @contextlib.asynccontextmanager |
| 414 | + async def get_zone_file( |
| 415 | + self, domain_id: DomainId, *, request_options: typing.Optional[RequestOptions] = None |
| 416 | + ) -> typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]]: |
| 417 | + """ |
| 418 | + Parameters |
| 419 | + ---------- |
| 420 | + domain_id : DomainId |
| 421 | +
|
| 422 | + request_options : typing.Optional[RequestOptions] |
| 423 | + Request-specific configuration. You can pass in configuration such as `chunk_size`, and more to customize the request and response. |
| 424 | +
|
| 425 | + Returns |
| 426 | + ------- |
| 427 | + typing.AsyncIterator[AsyncHttpResponse[typing.AsyncIterator[bytes]]] |
| 428 | + """ |
| 429 | + async with self._client_wrapper.httpx_client.stream( |
| 430 | + f"v0/domains/{jsonable_encoder(domain_id)}/zone-file", |
| 431 | + base_url=self._client_wrapper.get_environment().http, |
| 432 | + method="GET", |
| 433 | + request_options=request_options, |
| 434 | + ) as _response: |
| 435 | + |
| 436 | + async def _stream() -> AsyncHttpResponse[typing.AsyncIterator[bytes]]: |
| 437 | + try: |
| 438 | + if 200 <= _response.status_code < 300: |
| 439 | + _chunk_size = request_options.get("chunk_size", None) if request_options is not None else None |
| 440 | + return AsyncHttpResponse( |
| 441 | + response=_response, |
| 442 | + data=(_chunk async for _chunk in _response.aiter_bytes(chunk_size=_chunk_size)), |
| 443 | + ) |
| 444 | + await _response.aread() |
| 445 | + if _response.status_code == 404: |
| 446 | + raise NotFoundError( |
| 447 | + headers=dict(_response.headers), |
| 448 | + body=typing.cast( |
| 449 | + ErrorResponse, |
| 450 | + construct_type( |
| 451 | + type_=ErrorResponse, # type: ignore |
| 452 | + object_=_response.json(), |
| 453 | + ), |
| 454 | + ), |
| 455 | + ) |
| 456 | + _response_json = _response.json() |
| 457 | + except JSONDecodeError: |
| 458 | + raise ApiError( |
| 459 | + status_code=_response.status_code, headers=dict(_response.headers), body=_response.text |
| 460 | + ) |
| 461 | + raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json) |
| 462 | + |
| 463 | + yield await _stream() |
| 464 | + |
361 | 465 | async def create( |
362 | 466 | self, |
363 | 467 | *, |
|
0 commit comments