Skip to content

Commit 3f94ddf

Browse files
feat(api): api update
1 parent 3a32563 commit 3f94ddf

4 files changed

Lines changed: 40 additions & 35 deletions

File tree

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 1759
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-bb4f00f35d216fc086f41a566a2008bf2d7665f18c9977f0c305df8aa50610f9.yml
3-
openapi_spec_hash: 07db6ce298038f2c1688b7b2ee9f4c43
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-9da40dd6e26c12cb5cc2621882e3a721c33102947241937aecf8b1cf1bfd1906.yml
3+
openapi_spec_hash: 8e673d154552fd22c1291dc39644d664
44
config_hash: 920bb1b417565d337cbdb7c39e77be5b

src/cloudflare/resources/images/v1/v1.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import typing_extensions
6-
from typing import Any, Type, cast
6+
from typing import Any, Type, Mapping, cast
77

88
import httpx
99

@@ -39,8 +39,8 @@
3939
VariantsResourceWithStreamingResponse,
4040
AsyncVariantsResourceWithStreamingResponse,
4141
)
42-
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
43-
from ...._utils import maybe_transform, async_maybe_transform
42+
from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven, FileTypes
43+
from ...._utils import extract_files, maybe_transform, deepcopy_minimal, async_maybe_transform
4444
from ...._compat import cached_property
4545
from ...._resource import SyncAPIResource, AsyncAPIResource
4646
from ...._response import (
@@ -100,8 +100,8 @@ def create(
100100
self,
101101
*,
102102
account_id: str,
103-
id: object | NotGiven = NOT_GIVEN,
104-
file: object | NotGiven = NOT_GIVEN,
103+
id: str | NotGiven = NOT_GIVEN,
104+
file: FileTypes | NotGiven = NOT_GIVEN,
105105
metadata: object | NotGiven = NOT_GIVEN,
106106
require_signed_urls: bool | NotGiven = NOT_GIVEN,
107107
url: str | NotGiven = NOT_GIVEN,
@@ -142,22 +142,24 @@ def create(
142142
"""
143143
if not account_id:
144144
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
145+
body = deepcopy_minimal(
146+
{
147+
"id": id,
148+
"file": file,
149+
"metadata": metadata,
150+
"require_signed_urls": require_signed_urls,
151+
"url": url,
152+
}
153+
)
154+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
145155
# It should be noted that the actual Content-Type header that will be
146156
# sent to the server will contain a `boundary` parameter, e.g.
147157
# multipart/form-data; boundary=---abc--
148158
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
149159
return self._post(
150160
f"/accounts/{account_id}/images/v1",
151-
body=maybe_transform(
152-
{
153-
"id": id,
154-
"file": file,
155-
"metadata": metadata,
156-
"require_signed_urls": require_signed_urls,
157-
"url": url,
158-
},
159-
v1_create_params.V1CreateParams,
160-
),
161+
body=maybe_transform(body, v1_create_params.V1CreateParams),
162+
files=files,
161163
options=make_request_options(
162164
extra_headers=extra_headers,
163165
extra_query=extra_query,
@@ -421,8 +423,8 @@ async def create(
421423
self,
422424
*,
423425
account_id: str,
424-
id: object | NotGiven = NOT_GIVEN,
425-
file: object | NotGiven = NOT_GIVEN,
426+
id: str | NotGiven = NOT_GIVEN,
427+
file: FileTypes | NotGiven = NOT_GIVEN,
426428
metadata: object | NotGiven = NOT_GIVEN,
427429
require_signed_urls: bool | NotGiven = NOT_GIVEN,
428430
url: str | NotGiven = NOT_GIVEN,
@@ -463,22 +465,24 @@ async def create(
463465
"""
464466
if not account_id:
465467
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
468+
body = deepcopy_minimal(
469+
{
470+
"id": id,
471+
"file": file,
472+
"metadata": metadata,
473+
"require_signed_urls": require_signed_urls,
474+
"url": url,
475+
}
476+
)
477+
files = extract_files(cast(Mapping[str, object], body), paths=[["file"]])
466478
# It should be noted that the actual Content-Type header that will be
467479
# sent to the server will contain a `boundary` parameter, e.g.
468480
# multipart/form-data; boundary=---abc--
469481
extra_headers = {"Content-Type": "multipart/form-data", **(extra_headers or {})}
470482
return await self._post(
471483
f"/accounts/{account_id}/images/v1",
472-
body=await async_maybe_transform(
473-
{
474-
"id": id,
475-
"file": file,
476-
"metadata": metadata,
477-
"require_signed_urls": require_signed_urls,
478-
"url": url,
479-
},
480-
v1_create_params.V1CreateParams,
481-
),
484+
body=await async_maybe_transform(body, v1_create_params.V1CreateParams),
485+
files=files,
482486
options=make_request_options(
483487
extra_headers=extra_headers,
484488
extra_query=extra_query,

src/cloudflare/types/images/v1_create_params.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from typing_extensions import Required, Annotated, TypedDict
66

7+
from ..._types import FileTypes
78
from ..._utils import PropertyInfo
89

910
__all__ = ["V1CreateParams"]
@@ -13,10 +14,10 @@ class V1CreateParams(TypedDict, total=False):
1314
account_id: Required[str]
1415
"""Account identifier tag."""
1516

16-
id: object
17+
id: str
1718
"""An optional custom unique identifier for your image."""
1819

19-
file: object
20+
file: FileTypes
2021
"""An image binary data. Only needed when type is uploading a file."""
2122

2223
metadata: object

tests/api_resources/images/test_v1.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def test_method_create(self, client: Cloudflare) -> None:
3737
def test_method_create_with_all_params(self, client: Cloudflare) -> None:
3838
v1 = client.images.v1.create(
3939
account_id="023e105f4ecef8ad9ca31a8372d0c353",
40-
id={},
41-
file={},
40+
id="id",
41+
file=b"raw file contents",
4242
metadata={},
4343
require_signed_urls=True,
4444
url="https://example.com/path/to/logo.png",
@@ -306,8 +306,8 @@ async def test_method_create(self, async_client: AsyncCloudflare) -> None:
306306
async def test_method_create_with_all_params(self, async_client: AsyncCloudflare) -> None:
307307
v1 = await async_client.images.v1.create(
308308
account_id="023e105f4ecef8ad9ca31a8372d0c353",
309-
id={},
310-
file={},
309+
id="id",
310+
file=b"raw file contents",
311311
metadata={},
312312
require_signed_urls=True,
313313
url="https://example.com/path/to/logo.png",

0 commit comments

Comments
 (0)