22
33from __future__ import annotations
44
5+ from typing import Mapping , cast
6+
57import httpx
68
79from ..types import extension_update_params , extension_upload_params
8- from .._types import Body , Omit , Query , Headers , NotGiven , omit , not_given
9- from .._utils import maybe_transform , async_maybe_transform
10+ from .._types import Body , Omit , Query , Headers , NotGiven , FileTypes , omit , not_given
11+ from .._utils import extract_files , maybe_transform , deepcopy_minimal , async_maybe_transform
1012from .._compat import cached_property
1113from .._resource import SyncAPIResource , AsyncAPIResource
1214from .._response import (
@@ -49,7 +51,7 @@ def update(
4951 self ,
5052 extension_id : str ,
5153 * ,
52- file : object | Omit = omit ,
54+ file : FileTypes | Omit = omit ,
5355 url : str | Omit = omit ,
5456 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
5557 # The extra values given here take precedence over values defined on the client or passed to this method.
@@ -77,19 +79,21 @@ def update(
7779 """
7880 if not extension_id :
7981 raise ValueError (f"Expected a non-empty value for `extension_id` but received { extension_id !r} " )
82+ body = deepcopy_minimal (
83+ {
84+ "file" : file ,
85+ "url" : url ,
86+ }
87+ )
88+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
8089 # It should be noted that the actual Content-Type header that will be
8190 # sent to the server will contain a `boundary` parameter, e.g.
8291 # multipart/form-data; boundary=---abc--
8392 extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
8493 return self ._put (
8594 f"/v1/extensions/{ extension_id } " ,
86- body = maybe_transform (
87- {
88- "file" : file ,
89- "url" : url ,
90- },
91- extension_update_params .ExtensionUpdateParams ,
92- ),
95+ body = maybe_transform (body , extension_update_params .ExtensionUpdateParams ),
96+ files = files ,
9397 options = make_request_options (
9498 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
9599 ),
@@ -203,7 +207,7 @@ def download(
203207 def upload (
204208 self ,
205209 * ,
206- file : object | Omit = omit ,
210+ file : FileTypes | Omit = omit ,
207211 url : str | Omit = omit ,
208212 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
209213 # The extra values given here take precedence over values defined on the client or passed to this method.
@@ -229,19 +233,21 @@ def upload(
229233
230234 timeout: Override the client-level default timeout for this request, in seconds
231235 """
236+ body = deepcopy_minimal (
237+ {
238+ "file" : file ,
239+ "url" : url ,
240+ }
241+ )
242+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
232243 # It should be noted that the actual Content-Type header that will be
233244 # sent to the server will contain a `boundary` parameter, e.g.
234245 # multipart/form-data; boundary=---abc--
235246 extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
236247 return self ._post (
237248 "/v1/extensions" ,
238- body = maybe_transform (
239- {
240- "file" : file ,
241- "url" : url ,
242- },
243- extension_upload_params .ExtensionUploadParams ,
244- ),
249+ body = maybe_transform (body , extension_upload_params .ExtensionUploadParams ),
250+ files = files ,
245251 options = make_request_options (
246252 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
247253 ),
@@ -273,7 +279,7 @@ async def update(
273279 self ,
274280 extension_id : str ,
275281 * ,
276- file : object | Omit = omit ,
282+ file : FileTypes | Omit = omit ,
277283 url : str | Omit = omit ,
278284 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
279285 # The extra values given here take precedence over values defined on the client or passed to this method.
@@ -301,19 +307,21 @@ async def update(
301307 """
302308 if not extension_id :
303309 raise ValueError (f"Expected a non-empty value for `extension_id` but received { extension_id !r} " )
310+ body = deepcopy_minimal (
311+ {
312+ "file" : file ,
313+ "url" : url ,
314+ }
315+ )
316+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
304317 # It should be noted that the actual Content-Type header that will be
305318 # sent to the server will contain a `boundary` parameter, e.g.
306319 # multipart/form-data; boundary=---abc--
307320 extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
308321 return await self ._put (
309322 f"/v1/extensions/{ extension_id } " ,
310- body = await async_maybe_transform (
311- {
312- "file" : file ,
313- "url" : url ,
314- },
315- extension_update_params .ExtensionUpdateParams ,
316- ),
323+ body = await async_maybe_transform (body , extension_update_params .ExtensionUpdateParams ),
324+ files = files ,
317325 options = make_request_options (
318326 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
319327 ),
@@ -427,7 +435,7 @@ async def download(
427435 async def upload (
428436 self ,
429437 * ,
430- file : object | Omit = omit ,
438+ file : FileTypes | Omit = omit ,
431439 url : str | Omit = omit ,
432440 # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
433441 # The extra values given here take precedence over values defined on the client or passed to this method.
@@ -453,19 +461,21 @@ async def upload(
453461
454462 timeout: Override the client-level default timeout for this request, in seconds
455463 """
464+ body = deepcopy_minimal (
465+ {
466+ "file" : file ,
467+ "url" : url ,
468+ }
469+ )
470+ files = extract_files (cast (Mapping [str , object ], body ), paths = [["file" ]])
456471 # It should be noted that the actual Content-Type header that will be
457472 # sent to the server will contain a `boundary` parameter, e.g.
458473 # multipart/form-data; boundary=---abc--
459474 extra_headers = {"Content-Type" : "multipart/form-data" , ** (extra_headers or {})}
460475 return await self ._post (
461476 "/v1/extensions" ,
462- body = await async_maybe_transform (
463- {
464- "file" : file ,
465- "url" : url ,
466- },
467- extension_upload_params .ExtensionUploadParams ,
468- ),
477+ body = await async_maybe_transform (body , extension_upload_params .ExtensionUploadParams ),
478+ files = files ,
469479 options = make_request_options (
470480 extra_headers = extra_headers , extra_query = extra_query , extra_body = extra_body , timeout = timeout
471481 ),
0 commit comments