|
7 | 7 |
|
8 | 8 | import asyncio |
9 | 9 | import time |
10 | | -from typing import TYPE_CHECKING, Any |
| 10 | +from enum import Enum |
| 11 | +from typing import TYPE_CHECKING, Any, TypeVar |
11 | 12 |
|
12 | 13 | from typing_extensions import Self |
13 | 14 |
|
|
40 | 41 | from creatorsapi_python_sdk.models.search_items_resource import SearchItemsResource |
41 | 42 |
|
42 | 43 | if TYPE_CHECKING: |
43 | | - from enum import Enum |
44 | 44 | from types import TracebackType |
45 | 45 |
|
46 | 46 | from amazon_creatorsapi.core.marketplaces import CountryCode |
|
59 | 59 | ENDPOINT_GET_VARIATIONS = "/catalog/v1/getVariations" |
60 | 60 | ENDPOINT_GET_BROWSE_NODES = "/catalog/v1/getBrowseNodes" |
61 | 61 |
|
| 62 | +# TypeVar for generic resource handling |
| 63 | +ResourceT = TypeVar("ResourceT", bound=Enum) |
| 64 | + |
62 | 65 |
|
63 | 66 | class AsyncAmazonCreatorsApi: |
64 | 67 | """Async version of Amazon Creators API wrapper. |
@@ -89,6 +92,13 @@ class AsyncAmazonCreatorsApi: |
89 | 92 | The context manager approach is more efficient when making multiple |
90 | 93 | requests in quick succession due to HTTP connection pooling. |
91 | 94 |
|
| 95 | + Note: |
| 96 | + Using without context manager creates a new HTTP connection for each |
| 97 | + request, which is less efficient and may impact performance. For |
| 98 | + production code making multiple API calls, always use the context |
| 99 | + manager (async with) to benefit from connection pooling and reduced |
| 100 | + overhead. |
| 101 | +
|
92 | 102 | Args: |
93 | 103 | credential_id: Your Creators API credential ID. |
94 | 104 | credential_secret: Your Creators API credential secret. |
@@ -524,8 +534,16 @@ def _handle_error_response(self, status_code: int, body: str) -> None: |
524 | 534 | msg = f"Request failed with status {status_code}{body_info}" |
525 | 535 | raise RequestError(msg) |
526 | 536 |
|
527 | | - def _get_all_resources(self, resource_class: type[Enum]) -> list[Any]: |
528 | | - """Extract all resource values from a resource enum class.""" |
| 537 | + def _get_all_resources(self, resource_class: type[ResourceT]) -> list[ResourceT]: |
| 538 | + """Extract all resource values from a resource enum class. |
| 539 | +
|
| 540 | + Args: |
| 541 | + resource_class: Enum class containing resource definitions. |
| 542 | +
|
| 543 | + Returns: |
| 544 | + List of all enum members from the resource class. |
| 545 | +
|
| 546 | + """ |
529 | 547 | return list(resource_class) |
530 | 548 |
|
531 | 549 | def _deserialize_items(self, items_data: list[dict[str, Any]]) -> list[Item]: |
|
0 commit comments