Skip to content

Commit

Permalink
feat(api): update via SDK Studio (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Apr 2, 2024
1 parent b9ad754 commit ac63efe
Show file tree
Hide file tree
Showing 338 changed files with 2,770 additions and 4,013 deletions.
407 changes: 164 additions & 243 deletions api.md

Large diffs are not rendered by default.

41 changes: 9 additions & 32 deletions src/cloudflare/pagination.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import Any, List, Type, Generic, Mapping, TypeVar, Optional, cast
from typing import List, Generic, TypeVar, Optional, cast
from typing_extensions import override

from httpx import Response

from ._utils import is_mapping
from ._models import BaseModel, GenericModel
from ._base_client import BasePage, PageInfo, BaseSyncPage, BaseAsyncPage

Expand All @@ -27,8 +24,6 @@
"AsyncSinglePage",
]

_BaseModelT = TypeVar("_BaseModelT", bound=BaseModel)

_T = TypeVar("_T")


Expand Down Expand Up @@ -257,14 +252,14 @@ def next_page_info(self) -> Optional[PageInfo]:


class SyncSinglePage(BaseSyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]
result: List[_T]

@override
def _get_page_items(self) -> List[_T]:
items = self.items
if not items:
result = self.result
if not result:
return []
return items
return result

@override
def next_page_info(self) -> None:
Expand All @@ -274,25 +269,16 @@ def next_page_info(self) -> None:
"""
return None

@classmethod
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
return cls.construct(
None,
**{
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}),
},
)


class AsyncSinglePage(BaseAsyncPage[_T], BasePage[_T], Generic[_T]):
items: List[_T]
result: List[_T]

@override
def _get_page_items(self) -> List[_T]:
items = self.items
if not items:
result = self.result
if not result:
return []
return items
return result

@override
def next_page_info(self) -> None:
Expand All @@ -301,12 +287,3 @@ def next_page_info(self) -> None:
so there will never be a next page.
"""
return None

@classmethod
def build(cls: Type[_BaseModelT], *, response: Response, data: object) -> _BaseModelT: # noqa: ARG003
return cls.construct(
None,
**{
**(cast(Mapping[str, Any], data) if is_mapping(data) else {"items": data}),
},
)
34 changes: 15 additions & 19 deletions src/cloudflare/resources/accounts/roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from __future__ import annotations

from typing import Any, Type, Optional, cast
from typing import Any, cast

import httpx

Expand All @@ -16,10 +16,12 @@
async_to_streamed_response_wrapper,
)
from ..._wrappers import ResultWrapper
from ...pagination import SyncSinglePage, AsyncSinglePage
from ..._base_client import (
AsyncPaginator,
make_request_options,
)
from ...types.accounts import RoleGetResponse, RoleListResponse
from ...types.accounts import Role, RoleGetResponse

__all__ = ["Roles", "AsyncRoles"]

Expand All @@ -43,7 +45,7 @@ def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[RoleListResponse]:
) -> SyncSinglePage[Role]:
"""
Get all available roles for an account.
Expand All @@ -56,16 +58,13 @@ def list(
timeout: Override the client-level default timeout for this request, in seconds
"""
return self._get(
return self._get_api_list(
f"/accounts/{account_id}/roles",
page=SyncSinglePage[Role],
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[RoleListResponse]], ResultWrapper[RoleListResponse]),
model=Role,
)

def get(
Expand Down Expand Up @@ -119,7 +118,7 @@ def with_raw_response(self) -> AsyncRolesWithRawResponse:
def with_streaming_response(self) -> AsyncRolesWithStreamingResponse:
return AsyncRolesWithStreamingResponse(self)

async def list(
def list(
self,
*,
account_id: object,
Expand All @@ -129,7 +128,7 @@ async def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[RoleListResponse]:
) -> AsyncPaginator[Role, AsyncSinglePage[Role]]:
"""
Get all available roles for an account.
Expand All @@ -142,16 +141,13 @@ async def list(
timeout: Override the client-level default timeout for this request, in seconds
"""
return await self._get(
return self._get_api_list(
f"/accounts/{account_id}/roles",
page=AsyncSinglePage[Role],
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[RoleListResponse]], ResultWrapper[RoleListResponse]),
model=Role,
)

async def get(
Expand Down
31 changes: 13 additions & 18 deletions src/cloudflare/resources/addressing/address_maps/address_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,14 @@
async_to_streamed_response_wrapper,
)
from ...._wrappers import ResultWrapper
from ....pagination import SyncSinglePage, AsyncSinglePage
from ...._base_client import (
AsyncPaginator,
make_request_options,
)
from ....types.addressing import (
AddressingAddressMaps,
AddressMapGetResponse,
AddressMapListResponse,
AddressMapCreateResponse,
AddressMapDeleteResponse,
address_map_edit_params,
Expand Down Expand Up @@ -145,7 +146,7 @@ def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[AddressMapListResponse]:
) -> SyncSinglePage[AddressingAddressMaps]:
"""
List all address maps owned by the account.
Expand All @@ -162,16 +163,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}/addressing/address_maps",
page=SyncSinglePage[AddressingAddressMaps],
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[AddressMapListResponse]], ResultWrapper[AddressMapListResponse]),
model=AddressingAddressMaps,
)

def delete(
Expand Down Expand Up @@ -412,7 +410,7 @@ async def create(
cast_to=cast(Type[AddressMapCreateResponse], ResultWrapper[AddressMapCreateResponse]),
)

async def list(
def list(
self,
*,
account_id: str,
Expand All @@ -422,7 +420,7 @@ async def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> Optional[AddressMapListResponse]:
) -> AsyncPaginator[AddressingAddressMaps, AsyncSinglePage[AddressingAddressMaps]]:
"""
List all address maps owned by the account.
Expand All @@ -439,16 +437,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}/addressing/address_maps",
page=AsyncSinglePage[AddressingAddressMaps],
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[AddressMapListResponse]], ResultWrapper[AddressMapListResponse]),
model=AddressingAddressMaps,
)

async def delete(
Expand Down
37 changes: 14 additions & 23 deletions src/cloudflare/resources/addressing/prefixes/bgp/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
async_to_streamed_response_wrapper,
)
from ....._wrappers import ResultWrapper
from .....pagination import SyncSinglePage, AsyncSinglePage
from ....._base_client import (
AsyncPaginator,
make_request_options,
)
from .....types.addressing.prefixes.bgp import (
BindingListResponse,
BindingDeleteResponse,
AddressingServiceBinding,
binding_create_params,
)
from .....types.addressing.prefixes.bgp import BindingDeleteResponse, AddressingServiceBinding, binding_create_params

__all__ = ["Bindings", "AsyncBindings"]

Expand Down Expand Up @@ -113,7 +110,7 @@ def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> BindingListResponse:
) -> SyncSinglePage[AddressingServiceBinding]:
"""List the Cloudflare services this prefix is currently bound to.
Traffic sent to
Expand All @@ -140,16 +137,13 @@ def list(
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not prefix_id:
raise ValueError(f"Expected a non-empty value for `prefix_id` but received {prefix_id!r}")
return self._get(
return self._get_api_list(
f"/accounts/{account_id}/addressing/prefixes/{prefix_id}/bindings",
page=SyncSinglePage[AddressingServiceBinding],
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[BindingListResponse], ResultWrapper[BindingListResponse]),
model=AddressingServiceBinding,
)

def delete(
Expand Down Expand Up @@ -325,7 +319,7 @@ async def create(
cast_to=cast(Type[AddressingServiceBinding], ResultWrapper[AddressingServiceBinding]),
)

async def list(
def list(
self,
prefix_id: str,
*,
Expand All @@ -336,7 +330,7 @@ async def list(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> BindingListResponse:
) -> AsyncPaginator[AddressingServiceBinding, AsyncSinglePage[AddressingServiceBinding]]:
"""List the Cloudflare services this prefix is currently bound to.
Traffic sent to
Expand All @@ -363,16 +357,13 @@ async def list(
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
if not prefix_id:
raise ValueError(f"Expected a non-empty value for `prefix_id` but received {prefix_id!r}")
return await self._get(
return self._get_api_list(
f"/accounts/{account_id}/addressing/prefixes/{prefix_id}/bindings",
page=AsyncSinglePage[AddressingServiceBinding],
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[BindingListResponse], ResultWrapper[BindingListResponse]),
model=AddressingServiceBinding,
)

async def delete(
Expand Down
Loading

0 comments on commit ac63efe

Please sign in to comment.