|
6 | 6 |
|
7 | 7 | from ._broadcast import Broadcast |
8 | 8 |
|
| 9 | +# Async imports (optional - only available with pip install resend[async]) |
| 10 | +try: |
| 11 | + from resend.async_request import AsyncRequest |
| 12 | +except ImportError: |
| 13 | + pass |
| 14 | + |
9 | 15 | # _CreateParamsFrom is declared with functional TypedDict syntax here because |
10 | 16 | # "from" is a reserved keyword in Python, and this is the best way to |
11 | 17 | # support type-checking for it. |
@@ -323,3 +329,108 @@ def remove(cls, id: str) -> RemoveResponse: |
323 | 329 | path=path, params={}, verb="delete" |
324 | 330 | ).perform_with_content() |
325 | 331 | return resp |
| 332 | + |
| 333 | + @classmethod |
| 334 | + async def create_async(cls, params: CreateParams) -> CreateResponse: |
| 335 | + """ |
| 336 | + Create a broadcast (async). |
| 337 | + see more: https://resend.com/docs/api-reference/broadcasts/create-broadcast |
| 338 | +
|
| 339 | + Args: |
| 340 | + params (CreateParams): The broadcast creation parameters |
| 341 | +
|
| 342 | + Returns: |
| 343 | + CreateResponse: The new broadcast object response |
| 344 | + """ |
| 345 | + path = "/broadcasts" |
| 346 | + resp = await AsyncRequest[_CreateResponse]( |
| 347 | + path=path, params=cast(Dict[Any, Any], params), verb="post" |
| 348 | + ).perform_with_content() |
| 349 | + return resp |
| 350 | + |
| 351 | + @classmethod |
| 352 | + async def update_async(cls, params: UpdateParams) -> UpdateResponse: |
| 353 | + """ |
| 354 | + Update a broadcast (async). |
| 355 | + see more: https://resend.com/docs/api-reference/broadcasts/update-broadcast |
| 356 | +
|
| 357 | + Args: |
| 358 | + params (UpdateParams): The broadcast update parameters |
| 359 | +
|
| 360 | + Returns: |
| 361 | + UpdateResponse: The updated broadcast object response |
| 362 | + """ |
| 363 | + path = f"/broadcasts/{params['broadcast_id']}" |
| 364 | + resp = await AsyncRequest[_UpdateResponse]( |
| 365 | + path=path, params=cast(Dict[Any, Any], params), verb="patch" |
| 366 | + ).perform_with_content() |
| 367 | + return resp |
| 368 | + |
| 369 | + @classmethod |
| 370 | + async def send_async(cls, params: SendParams) -> SendResponse: |
| 371 | + """ |
| 372 | + Sends a broadcast (async). |
| 373 | + see more: https://resend.com/docs/api-reference/broadcasts/send-broadcast |
| 374 | +
|
| 375 | + Args: |
| 376 | + params (SendParams): The broadcast send parameters |
| 377 | +
|
| 378 | + Returns: |
| 379 | + SendResponse: The new broadcast object response |
| 380 | + """ |
| 381 | + path = f"/broadcasts/{params['broadcast_id']}/send" |
| 382 | + resp = await AsyncRequest[_SendResponse]( |
| 383 | + path=path, params=cast(Dict[Any, Any], params), verb="post" |
| 384 | + ).perform_with_content() |
| 385 | + return resp |
| 386 | + |
| 387 | + @classmethod |
| 388 | + async def list_async(cls) -> ListResponse: |
| 389 | + """ |
| 390 | + Retrieve a list of broadcasts (async). |
| 391 | + see more: https://resend.com/docs/api-reference/broadcasts/list-broadcasts |
| 392 | +
|
| 393 | + Returns: |
| 394 | + ListResponse: A list of broadcast objects |
| 395 | + """ |
| 396 | + path = "/broadcasts/" |
| 397 | + resp = await AsyncRequest[_ListResponse]( |
| 398 | + path=path, params={}, verb="get" |
| 399 | + ).perform_with_content() |
| 400 | + return resp |
| 401 | + |
| 402 | + @classmethod |
| 403 | + async def get_async(cls, id: str) -> Broadcast: |
| 404 | + """ |
| 405 | + Retrieve a single broadcast (async). |
| 406 | + see more: https://resend.com/docs/api-reference/broadcasts/get-broadcast |
| 407 | +
|
| 408 | + Args: |
| 409 | + id (str): The broadcast ID |
| 410 | +
|
| 411 | + Returns: |
| 412 | + Broadcast: The broadcast object |
| 413 | + """ |
| 414 | + path = f"/broadcasts/{id}" |
| 415 | + resp = await AsyncRequest[Broadcast]( |
| 416 | + path=path, params={}, verb="get" |
| 417 | + ).perform_with_content() |
| 418 | + return resp |
| 419 | + |
| 420 | + @classmethod |
| 421 | + async def remove_async(cls, id: str) -> RemoveResponse: |
| 422 | + """ |
| 423 | + Delete a single broadcast (async). |
| 424 | + see more: https://resend.com/docs/api-reference/broadcasts/delete-broadcasts |
| 425 | +
|
| 426 | + Args: |
| 427 | + id (str): The broadcast ID |
| 428 | +
|
| 429 | + Returns: |
| 430 | + RemoveResponse: The remove response object |
| 431 | + """ |
| 432 | + path = f"/broadcasts/{id}" |
| 433 | + resp = await AsyncRequest[_RemoveResponse]( |
| 434 | + path=path, params={}, verb="delete" |
| 435 | + ).perform_with_content() |
| 436 | + return resp |
0 commit comments