|
1 | | -from typing import Any, Dict, List, Union, cast |
| 1 | +from typing import Any, Dict, List, Union, cast, overload |
2 | 2 | from typing_extensions import NotRequired, TypedDict |
3 | 3 | from .request import Request, RequestConfig |
4 | 4 | from .async_request import AsyncRequest, AsyncRequestConfig |
5 | 5 | from ._config import ClientConfig |
6 | 6 | from typing import Any, Dict, List, cast |
7 | | -from typing_extensions import NotRequired, TypedDict |
| 7 | +from typing_extensions import NotRequired, TypedDict, Union, Optional |
8 | 8 | from .helpers import build_path |
9 | 9 |
|
10 | 10 |
|
@@ -101,16 +101,37 @@ def email(self, params: EmailValidationParams) -> EmailValidationResponse: |
101 | 101 | verb="get", |
102 | 102 | ).perform_with_content() |
103 | 103 | 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} |
104 | 128 |
|
105 | | - def nsfw(self, params: NSFWParams) -> NSFWResponse: |
106 | | - path = f"/validate/nsfw" |
107 | 129 | resp = Request( |
108 | 130 | config=self.config, |
109 | 131 | path=path, |
110 | | - params=cast( |
111 | | - Dict[Any, Any], |
112 | | - params |
113 | | - ), |
| 132 | + params=options, |
| 133 | + data=blob, |
| 134 | + headers=headers, |
114 | 135 | verb="post", |
115 | 136 | ).perform_with_content() |
116 | 137 | return resp |
@@ -184,15 +205,36 @@ async def email(self, params: EmailValidationParams) -> EmailValidationResponse: |
184 | 205 | ).perform_with_content() |
185 | 206 | return resp |
186 | 207 |
|
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 | + |
189 | 232 | resp = await AsyncRequest( |
190 | 233 | config=self.config, |
191 | 234 | path=path, |
192 | | - params=cast( |
193 | | - Dict[Any, Any], |
194 | | - params, |
195 | | - ), |
| 235 | + params=options, |
| 236 | + data=blob, |
| 237 | + headers=headers, |
196 | 238 | verb="post", |
197 | 239 | ).perform_with_content() |
198 | 240 | return resp |
|
0 commit comments