Skip to content

Commit 8f7e539

Browse files
UP.
1 parent fb3f9e0 commit 8f7e539

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

jigsawstack/validate.py

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from typing import Any, Dict, List, Union, cast
1+
from typing import Any, Dict, List, Union, cast, overload
22
from typing_extensions import NotRequired, TypedDict
33
from .request import Request, RequestConfig
44
from .async_request import AsyncRequest, AsyncRequestConfig
55
from ._config import ClientConfig
66
from typing import Any, Dict, List, cast
7-
from typing_extensions import NotRequired, TypedDict
7+
from typing_extensions import NotRequired, TypedDict, Union, Optional
88
from .helpers import build_path
99

1010

@@ -101,16 +101,37 @@ def email(self, params: EmailValidationParams) -> EmailValidationResponse:
101101
verb="get",
102102
).perform_with_content()
103103
return resp
104+
105+
@overload
106+
def nsfw(self, params: NSFWParams) -> NSFWResponse: ...
107+
@overload
108+
def speech_to_text(self, file: bytes, options: Optional[NSFWParams] = None) -> NSFWParams: ...
109+
110+
def nsfw(
111+
self,
112+
blob: Union[NSFWParams, bytes],
113+
options: Optional[NSFWParams] = None,
114+
) -> NSFWResponse:
115+
if isinstance(blob, dict):
116+
resp = Request(
117+
config=self.config,
118+
path="/validate/nsfw",
119+
params=cast(Dict[Any, Any], blob),
120+
verb="post",
121+
).perform_with_content()
122+
return resp
123+
124+
options = options or {}
125+
path = build_path(base_path="/validate/nsfw", params=options)
126+
content_type = options.get("content_type", "application/octet-stream")
127+
headers = {"Content-Type": content_type}
104128

105-
def nsfw(self, params: NSFWParams) -> NSFWResponse:
106-
path = f"/validate/nsfw"
107129
resp = Request(
108130
config=self.config,
109131
path=path,
110-
params=cast(
111-
Dict[Any, Any],
112-
params
113-
),
132+
params=options,
133+
data=blob,
134+
headers=headers,
114135
verb="post",
115136
).perform_with_content()
116137
return resp
@@ -184,15 +205,36 @@ async def email(self, params: EmailValidationParams) -> EmailValidationResponse:
184205
).perform_with_content()
185206
return resp
186207

187-
async def nsfw(self, params: NSFWParams) -> NSFWResponse:
188-
path = f"/validate/nsfw"
208+
@overload
209+
async def nsfw(self, params: NSFWParams) -> NSFWResponse: ...
210+
@overload
211+
async def speech_to_text(self, file: bytes, options: Optional[NSFWParams] = None) -> NSFWParams: ...
212+
213+
async def nsfw(
214+
self,
215+
blob: Union[NSFWParams, bytes],
216+
options: Optional[NSFWParams] = None,
217+
) -> NSFWResponse:
218+
if isinstance(blob, dict):
219+
resp = await AsyncRequest(
220+
config=self.config,
221+
path="/validate/nsfw",
222+
params=cast(Dict[Any, Any], blob),
223+
verb="post",
224+
).perform_with_content()
225+
return resp
226+
227+
options = options or {}
228+
path = build_path(base_path="/validate/nsfw", params=options)
229+
content_type = options.get("content_type", "application/octet-stream")
230+
headers = {"Content-Type": content_type}
231+
189232
resp = await AsyncRequest(
190233
config=self.config,
191234
path=path,
192-
params=cast(
193-
Dict[Any, Any],
194-
params,
195-
),
235+
params=options,
236+
data=blob,
237+
headers=headers,
196238
verb="post",
197239
).perform_with_content()
198240
return resp

0 commit comments

Comments
 (0)