|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Dict, Type, Optional, cast |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ....._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 10 | +from ....._utils import ( |
| 11 | + maybe_transform, |
| 12 | + async_maybe_transform, |
| 13 | +) |
| 14 | +from ....._compat import cached_property |
| 15 | +from ....._resource import SyncAPIResource, AsyncAPIResource |
| 16 | +from ....._response import ( |
| 17 | + to_raw_response_wrapper, |
| 18 | + to_streamed_response_wrapper, |
| 19 | + async_to_raw_response_wrapper, |
| 20 | + async_to_streamed_response_wrapper, |
| 21 | +) |
| 22 | +from ....._wrappers import ResultWrapper |
| 23 | +from ....._base_client import make_request_options |
| 24 | +from .....types.workers.scripts.assets import upload_create_params |
| 25 | +from .....types.workers.scripts.assets.upload_create_response import UploadCreateResponse |
| 26 | + |
| 27 | +__all__ = ["UploadResource", "AsyncUploadResource"] |
| 28 | + |
| 29 | + |
| 30 | +class UploadResource(SyncAPIResource): |
| 31 | + @cached_property |
| 32 | + def with_raw_response(self) -> UploadResourceWithRawResponse: |
| 33 | + """ |
| 34 | + This property can be used as a prefix for any HTTP method call to return the |
| 35 | + the raw response object instead of the parsed content. |
| 36 | +
|
| 37 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 38 | + """ |
| 39 | + return UploadResourceWithRawResponse(self) |
| 40 | + |
| 41 | + @cached_property |
| 42 | + def with_streaming_response(self) -> UploadResourceWithStreamingResponse: |
| 43 | + """ |
| 44 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 45 | +
|
| 46 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 47 | + """ |
| 48 | + return UploadResourceWithStreamingResponse(self) |
| 49 | + |
| 50 | + def create( |
| 51 | + self, |
| 52 | + script_name: str, |
| 53 | + *, |
| 54 | + account_id: str, |
| 55 | + manifest: Dict[str, upload_create_params.Manifest] | NotGiven = NOT_GIVEN, |
| 56 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 57 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 58 | + extra_headers: Headers | None = None, |
| 59 | + extra_query: Query | None = None, |
| 60 | + extra_body: Body | None = None, |
| 61 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 62 | + ) -> Optional[UploadCreateResponse]: |
| 63 | + """ |
| 64 | + Start uploading a collection of assets for use in a Worker version. |
| 65 | +
|
| 66 | + Args: |
| 67 | + account_id: Identifier |
| 68 | +
|
| 69 | + script_name: Name of the script, used in URLs and route configuration. |
| 70 | +
|
| 71 | + manifest: A manifest ([path]: {hash, size}) map of files to upload. As an example, |
| 72 | + `/blog/hello-world.html` would be a valid path key. |
| 73 | +
|
| 74 | + extra_headers: Send extra headers |
| 75 | +
|
| 76 | + extra_query: Add additional query parameters to the request |
| 77 | +
|
| 78 | + extra_body: Add additional JSON properties to the request |
| 79 | +
|
| 80 | + timeout: Override the client-level default timeout for this request, in seconds |
| 81 | + """ |
| 82 | + if not account_id: |
| 83 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 84 | + if not script_name: |
| 85 | + raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}") |
| 86 | + return self._post( |
| 87 | + f"/accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session", |
| 88 | + body=maybe_transform({"manifest": manifest}, upload_create_params.UploadCreateParams), |
| 89 | + options=make_request_options( |
| 90 | + extra_headers=extra_headers, |
| 91 | + extra_query=extra_query, |
| 92 | + extra_body=extra_body, |
| 93 | + timeout=timeout, |
| 94 | + post_parser=ResultWrapper[Optional[UploadCreateResponse]]._unwrapper, |
| 95 | + ), |
| 96 | + cast_to=cast(Type[Optional[UploadCreateResponse]], ResultWrapper[UploadCreateResponse]), |
| 97 | + ) |
| 98 | + |
| 99 | + |
| 100 | +class AsyncUploadResource(AsyncAPIResource): |
| 101 | + @cached_property |
| 102 | + def with_raw_response(self) -> AsyncUploadResourceWithRawResponse: |
| 103 | + """ |
| 104 | + This property can be used as a prefix for any HTTP method call to return the |
| 105 | + the raw response object instead of the parsed content. |
| 106 | +
|
| 107 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 108 | + """ |
| 109 | + return AsyncUploadResourceWithRawResponse(self) |
| 110 | + |
| 111 | + @cached_property |
| 112 | + def with_streaming_response(self) -> AsyncUploadResourceWithStreamingResponse: |
| 113 | + """ |
| 114 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 115 | +
|
| 116 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 117 | + """ |
| 118 | + return AsyncUploadResourceWithStreamingResponse(self) |
| 119 | + |
| 120 | + async def create( |
| 121 | + self, |
| 122 | + script_name: str, |
| 123 | + *, |
| 124 | + account_id: str, |
| 125 | + manifest: Dict[str, upload_create_params.Manifest] | NotGiven = NOT_GIVEN, |
| 126 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 127 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 128 | + extra_headers: Headers | None = None, |
| 129 | + extra_query: Query | None = None, |
| 130 | + extra_body: Body | None = None, |
| 131 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 132 | + ) -> Optional[UploadCreateResponse]: |
| 133 | + """ |
| 134 | + Start uploading a collection of assets for use in a Worker version. |
| 135 | +
|
| 136 | + Args: |
| 137 | + account_id: Identifier |
| 138 | +
|
| 139 | + script_name: Name of the script, used in URLs and route configuration. |
| 140 | +
|
| 141 | + manifest: A manifest ([path]: {hash, size}) map of files to upload. As an example, |
| 142 | + `/blog/hello-world.html` would be a valid path key. |
| 143 | +
|
| 144 | + extra_headers: Send extra headers |
| 145 | +
|
| 146 | + extra_query: Add additional query parameters to the request |
| 147 | +
|
| 148 | + extra_body: Add additional JSON properties to the request |
| 149 | +
|
| 150 | + timeout: Override the client-level default timeout for this request, in seconds |
| 151 | + """ |
| 152 | + if not account_id: |
| 153 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 154 | + if not script_name: |
| 155 | + raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}") |
| 156 | + return await self._post( |
| 157 | + f"/accounts/{account_id}/workers/scripts/{script_name}/assets-upload-session", |
| 158 | + body=await async_maybe_transform({"manifest": manifest}, upload_create_params.UploadCreateParams), |
| 159 | + options=make_request_options( |
| 160 | + extra_headers=extra_headers, |
| 161 | + extra_query=extra_query, |
| 162 | + extra_body=extra_body, |
| 163 | + timeout=timeout, |
| 164 | + post_parser=ResultWrapper[Optional[UploadCreateResponse]]._unwrapper, |
| 165 | + ), |
| 166 | + cast_to=cast(Type[Optional[UploadCreateResponse]], ResultWrapper[UploadCreateResponse]), |
| 167 | + ) |
| 168 | + |
| 169 | + |
| 170 | +class UploadResourceWithRawResponse: |
| 171 | + def __init__(self, upload: UploadResource) -> None: |
| 172 | + self._upload = upload |
| 173 | + |
| 174 | + self.create = to_raw_response_wrapper( |
| 175 | + upload.create, |
| 176 | + ) |
| 177 | + |
| 178 | + |
| 179 | +class AsyncUploadResourceWithRawResponse: |
| 180 | + def __init__(self, upload: AsyncUploadResource) -> None: |
| 181 | + self._upload = upload |
| 182 | + |
| 183 | + self.create = async_to_raw_response_wrapper( |
| 184 | + upload.create, |
| 185 | + ) |
| 186 | + |
| 187 | + |
| 188 | +class UploadResourceWithStreamingResponse: |
| 189 | + def __init__(self, upload: UploadResource) -> None: |
| 190 | + self._upload = upload |
| 191 | + |
| 192 | + self.create = to_streamed_response_wrapper( |
| 193 | + upload.create, |
| 194 | + ) |
| 195 | + |
| 196 | + |
| 197 | +class AsyncUploadResourceWithStreamingResponse: |
| 198 | + def __init__(self, upload: AsyncUploadResource) -> None: |
| 199 | + self._upload = upload |
| 200 | + |
| 201 | + self.create = async_to_streamed_response_wrapper( |
| 202 | + upload.create, |
| 203 | + ) |
0 commit comments