From 4c76f22d1e9bb3a8bd127a998c7bf94f111070b9 Mon Sep 17 00:00:00 2001 From: stainless-bot Date: Wed, 3 Apr 2024 04:56:40 +0000 Subject: [PATCH] feat(api): update via SDK Studio --- api.md | 2 +- src/cloudflare/resources/queues/queues.py | 30 +++++++++------------ src/cloudflare/types/queue_list_response.py | 9 +++---- tests/api_resources/test_queues.py | 13 ++++----- 4 files changed, 24 insertions(+), 30 deletions(-) diff --git a/api.md b/api.md index 479c140dede..c085adab0bf 100644 --- a/api.md +++ b/api.md @@ -2960,7 +2960,7 @@ Methods: - client.queues.create(\*, account_id, \*\*params) -> Optional - client.queues.update(queue_id, \*, account_id, \*\*params) -> Optional -- client.queues.list(\*, account_id) -> Optional +- client.queues.list(\*, account_id) -> SyncSinglePage[QueueListResponse] - client.queues.delete(queue_id, \*, account_id) -> Optional - client.queues.get(queue_id, \*, account_id) -> Optional diff --git a/src/cloudflare/resources/queues/queues.py b/src/cloudflare/resources/queues/queues.py index 5f3220b8cbb..0f3f2a0c7fe 100644 --- a/src/cloudflare/resources/queues/queues.py +++ b/src/cloudflare/resources/queues/queues.py @@ -45,7 +45,9 @@ async_to_streamed_response_wrapper, ) from ..._wrappers import ResultWrapper +from ...pagination import SyncSinglePage, AsyncSinglePage from ..._base_client import ( + AsyncPaginator, make_request_options, ) @@ -166,7 +168,7 @@ def list( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Optional[QueueListResponse]: + ) -> SyncSinglePage[QueueListResponse]: """ Returns the queues owned by an account. @@ -183,16 +185,13 @@ def list( """ if not account_id: raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") - return self._get( + return self._get_api_list( f"/accounts/{account_id}/queues", + page=SyncSinglePage[QueueListResponse], options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - post_parser=ResultWrapper._unwrapper, + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=cast(Type[Optional[QueueListResponse]], ResultWrapper[QueueListResponse]), + model=QueueListResponse, ) def delete( @@ -393,7 +392,7 @@ async def update( cast_to=cast(Type[Optional[QueueUpdateResponse]], ResultWrapper[QueueUpdateResponse]), ) - async def list( + def list( self, *, account_id: str, @@ -403,7 +402,7 @@ async def list( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> Optional[QueueListResponse]: + ) -> AsyncPaginator[QueueListResponse, AsyncSinglePage[QueueListResponse]]: """ Returns the queues owned by an account. @@ -420,16 +419,13 @@ async def list( """ if not account_id: raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") - return await self._get( + return self._get_api_list( f"/accounts/{account_id}/queues", + page=AsyncSinglePage[QueueListResponse], options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - post_parser=ResultWrapper._unwrapper, + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), - cast_to=cast(Type[Optional[QueueListResponse]], ResultWrapper[QueueListResponse]), + model=QueueListResponse, ) async def delete( diff --git a/src/cloudflare/types/queue_list_response.py b/src/cloudflare/types/queue_list_response.py index 9b0038b8c4d..1ccfe1e6e71 100644 --- a/src/cloudflare/types/queue_list_response.py +++ b/src/cloudflare/types/queue_list_response.py @@ -1,13 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import List, Optional +from typing import Optional from .._models import BaseModel -__all__ = ["QueueListResponse", "QueueListResponseItem"] +__all__ = ["QueueListResponse"] -class QueueListResponseItem(BaseModel): +class QueueListResponse(BaseModel): consumers: Optional[object] = None consumers_total_count: Optional[object] = None @@ -23,6 +23,3 @@ class QueueListResponseItem(BaseModel): queue_id: Optional[str] = None queue_name: Optional[str] = None - - -QueueListResponse = List[QueueListResponseItem] diff --git a/tests/api_resources/test_queues.py b/tests/api_resources/test_queues.py index 0d2b8b65738..2204fc81cdb 100644 --- a/tests/api_resources/test_queues.py +++ b/tests/api_resources/test_queues.py @@ -16,6 +16,7 @@ QueueDeleteResponse, QueueUpdateResponse, ) +from cloudflare.pagination import SyncSinglePage, AsyncSinglePage base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") @@ -132,7 +133,7 @@ def test_method_list(self, client: Cloudflare) -> None: queue = client.queues.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) - assert_matches_type(Optional[QueueListResponse], queue, path=["response"]) + assert_matches_type(SyncSinglePage[QueueListResponse], queue, path=["response"]) @pytest.mark.skip() @parametrize @@ -144,7 +145,7 @@ def test_raw_response_list(self, client: Cloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" queue = response.parse() - assert_matches_type(Optional[QueueListResponse], queue, path=["response"]) + assert_matches_type(SyncSinglePage[QueueListResponse], queue, path=["response"]) @pytest.mark.skip() @parametrize @@ -156,7 +157,7 @@ def test_streaming_response_list(self, client: Cloudflare) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" queue = response.parse() - assert_matches_type(Optional[QueueListResponse], queue, path=["response"]) + assert_matches_type(SyncSinglePage[QueueListResponse], queue, path=["response"]) assert cast(Any, response.is_closed) is True @@ -385,7 +386,7 @@ async def test_method_list(self, async_client: AsyncCloudflare) -> None: queue = await async_client.queues.list( account_id="023e105f4ecef8ad9ca31a8372d0c353", ) - assert_matches_type(Optional[QueueListResponse], queue, path=["response"]) + assert_matches_type(AsyncSinglePage[QueueListResponse], queue, path=["response"]) @pytest.mark.skip() @parametrize @@ -397,7 +398,7 @@ async def test_raw_response_list(self, async_client: AsyncCloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" queue = await response.parse() - assert_matches_type(Optional[QueueListResponse], queue, path=["response"]) + assert_matches_type(AsyncSinglePage[QueueListResponse], queue, path=["response"]) @pytest.mark.skip() @parametrize @@ -409,7 +410,7 @@ async def test_streaming_response_list(self, async_client: AsyncCloudflare) -> N assert response.http_request.headers.get("X-Stainless-Lang") == "python" queue = await response.parse() - assert_matches_type(Optional[QueueListResponse], queue, path=["response"]) + assert_matches_type(AsyncSinglePage[QueueListResponse], queue, path=["response"]) assert cast(Any, response.is_closed) is True