|
1 |
| -from typing import Any, Dict, List, cast |
| 1 | +from typing import Any, Dict, List, Optional, cast |
2 | 2 |
|
3 |
| -from typing_extensions import TypedDict |
| 3 | +from typing_extensions import NotRequired, TypedDict |
4 | 4 |
|
5 | 5 | from resend import request
|
| 6 | +from resend.pagination_helper import PaginationHelper |
6 | 7 |
|
7 | 8 | from ._audience import Audience
|
8 | 9 |
|
@@ -32,23 +33,46 @@ class RemoveAudienceResponse(TypedDict):
|
32 | 33 | Whether the audience was deleted
|
33 | 34 | """
|
34 | 35 |
|
| 36 | + class ListParams(TypedDict): |
| 37 | + limit: NotRequired[int] |
| 38 | + """ |
| 39 | + Number of audiences to retrieve. Maximum is 100, and minimum is 1. |
| 40 | + """ |
| 41 | + after: NotRequired[str] |
| 42 | + """ |
| 43 | + The ID after which we'll retrieve more audiences (for pagination). |
| 44 | + This ID will not be included in the returned list. |
| 45 | + Cannot be used with the before parameter. |
| 46 | + """ |
| 47 | + before: NotRequired[str] |
| 48 | + """ |
| 49 | + The ID before which we'll retrieve more audiences (for pagination). |
| 50 | + This ID will not be included in the returned list. |
| 51 | + Cannot be used with the after parameter. |
| 52 | + """ |
| 53 | + |
35 | 54 | class ListResponse(TypedDict):
|
36 | 55 | """
|
37 |
| - ListResponse type that wraps a list of audience objects |
| 56 | + ListResponse type that wraps a list of audience objects with pagination metadata |
38 | 57 |
|
39 | 58 | Attributes:
|
40 |
| - object (str): The object type, "list" |
| 59 | + object (str): The object type, always "list" |
41 | 60 | data (List[Audience]): A list of audience objects
|
| 61 | + has_more (bool): Whether there are more results available |
42 | 62 | """
|
43 | 63 |
|
44 | 64 | object: str
|
45 | 65 | """
|
46 |
| - The object type, "list" |
| 66 | + The object type, always "list" |
47 | 67 | """
|
48 | 68 | data: List[Audience]
|
49 | 69 | """
|
50 | 70 | A list of audience objects
|
51 | 71 | """
|
| 72 | + has_more: bool |
| 73 | + """ |
| 74 | + Whether there are more results available for pagination |
| 75 | + """ |
52 | 76 |
|
53 | 77 | class CreateAudienceResponse(TypedDict):
|
54 | 78 | """
|
@@ -99,15 +123,24 @@ def create(cls, params: CreateParams) -> CreateAudienceResponse:
|
99 | 123 | return resp
|
100 | 124 |
|
101 | 125 | @classmethod
|
102 |
| - def list(cls) -> ListResponse: |
| 126 | + def list(cls, params: Optional[ListParams] = None) -> ListResponse: |
103 | 127 | """
|
104 | 128 | Retrieve a list of audiences.
|
105 | 129 | see more: https://resend.com/docs/api-reference/audiences/list-audiences
|
106 | 130 |
|
| 131 | + Args: |
| 132 | + params (Optional[ListParams]): Optional pagination parameters |
| 133 | + - limit: Number of audiences to retrieve (max 100, min 1). |
| 134 | + If not provided, all audiences will be returned without pagination. |
| 135 | + - after: ID after which to retrieve more audiences |
| 136 | + - before: ID before which to retrieve more audiences |
| 137 | +
|
107 | 138 | Returns:
|
108 | 139 | ListResponse: A list of audience objects
|
109 | 140 | """
|
110 |
| - path = "/audiences/" |
| 141 | + base_path = "/audiences" |
| 142 | + query_params = cast(Dict[Any, Any], params) if params else None |
| 143 | + path = PaginationHelper.build_paginated_path(base_path, query_params) |
111 | 144 | resp = request.Request[Audiences.ListResponse](
|
112 | 145 | path=path, params={}, verb="get"
|
113 | 146 | ).perform_with_content()
|
|
0 commit comments