Skip to content

Commit

Permalink
feat(api): OpenAPI spec update via Stainless API (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Apr 5, 2024
1 parent 9764cf0 commit 3f5595d
Show file tree
Hide file tree
Showing 459 changed files with 5,303 additions and 464 deletions.
268 changes: 134 additions & 134 deletions api.md

Large diffs are not rendered by default.

73 changes: 47 additions & 26 deletions src/cloudflare/_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Stream(Generic[_T]):

response: httpx.Response

_decoder: SSEDecoder | SSEBytesDecoder
_decoder: SSEBytesDecoder

def __init__(
self,
Expand All @@ -46,10 +46,7 @@ def __iter__(self) -> Iterator[_T]:
yield item

def _iter_events(self) -> Iterator[ServerSentEvent]:
if isinstance(self._decoder, SSEBytesDecoder):
yield from self._decoder.iter_bytes(self.response.iter_bytes())
else:
yield from self._decoder.iter(self.response.iter_lines())
yield from self._decoder.iter_bytes(self.response.iter_bytes())

def __stream__(self) -> Iterator[_T]:
cast_to = cast(Any, self._cast_to)
Expand Down Expand Up @@ -112,12 +109,8 @@ async def __aiter__(self) -> AsyncIterator[_T]:
yield item

async def _iter_events(self) -> AsyncIterator[ServerSentEvent]:
if isinstance(self._decoder, SSEBytesDecoder):
async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
yield sse
else:
async for sse in self._decoder.aiter(self.response.aiter_lines()):
yield sse
async for sse in self._decoder.aiter_bytes(self.response.aiter_bytes()):
yield sse

async def __stream__(self) -> AsyncIterator[_T]:
cast_to = cast(Any, self._cast_to)
Expand Down Expand Up @@ -205,21 +198,49 @@ def __init__(self) -> None:
self._last_event_id = None
self._retry = None

def iter(self, iterator: Iterator[str]) -> Iterator[ServerSentEvent]:
"""Given an iterator that yields lines, iterate over it & yield every event encountered"""
for line in iterator:
line = line.rstrip("\n")
sse = self.decode(line)
if sse is not None:
yield sse

async def aiter(self, iterator: AsyncIterator[str]) -> AsyncIterator[ServerSentEvent]:
"""Given an async iterator that yields lines, iterate over it & yield every event encountered"""
async for line in iterator:
line = line.rstrip("\n")
sse = self.decode(line)
if sse is not None:
yield sse
def iter_bytes(self, iterator: Iterator[bytes]) -> Iterator[ServerSentEvent]:
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
for chunk in self._iter_chunks(iterator):
# Split before decoding so splitlines() only uses \r and \n
for raw_line in chunk.splitlines():
line = raw_line.decode("utf-8")
sse = self.decode(line)
if sse:
yield sse

def _iter_chunks(self, iterator: Iterator[bytes]) -> Iterator[bytes]:
"""Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
data = b""
for chunk in iterator:
for line in chunk.splitlines(keepends=True):
data += line
if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
yield data
data = b""
if data:
yield data

async def aiter_bytes(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[ServerSentEvent]:
"""Given an iterator that yields raw binary data, iterate over it & yield every event encountered"""
async for chunk in self._aiter_chunks(iterator):
# Split before decoding so splitlines() only uses \r and \n
for raw_line in chunk.splitlines():
line = raw_line.decode("utf-8")
sse = self.decode(line)
if sse:
yield sse

async def _aiter_chunks(self, iterator: AsyncIterator[bytes]) -> AsyncIterator[bytes]:
"""Given an iterator that yields raw binary data, iterate over it and yield individual SSE chunks"""
data = b""
async for chunk in iterator:
for line in chunk.splitlines(keepends=True):
data += line
if data.endswith((b"\r\r", b"\n\n", b"\r\n\r\n")):
yield data
data = b""
if data:
yield data

def decode(self, line: str) -> ServerSentEvent | None:
# See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501
Expand Down
8 changes: 8 additions & 0 deletions src/cloudflare/resources/accounts/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def list(
self,
*,
direction: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
name: str | NotGiven = NOT_GIVEN,
page: float | NotGiven = NOT_GIVEN,
per_page: float | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -141,6 +142,8 @@ def list(
Args:
direction: Direction to order results.
name: Name of the account.
page: Page number of paginated results.
per_page: Maximum number of results per page.
Expand All @@ -164,6 +167,7 @@ def list(
query=maybe_transform(
{
"direction": direction,
"name": name,
"page": page,
"per_page": per_page,
},
Expand Down Expand Up @@ -288,6 +292,7 @@ def list(
self,
*,
direction: Literal["asc", "desc"] | NotGiven = NOT_GIVEN,
name: str | NotGiven = NOT_GIVEN,
page: float | NotGiven = NOT_GIVEN,
per_page: float | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -303,6 +308,8 @@ def list(
Args:
direction: Direction to order results.
name: Name of the account.
page: Page number of paginated results.
per_page: Maximum number of results per page.
Expand All @@ -326,6 +333,7 @@ def list(
query=maybe_transform(
{
"direction": direction,
"name": name,
"page": page,
"per_page": per_page,
},
Expand Down
5 changes: 5 additions & 0 deletions src/cloudflare/resources/accounts/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
MemberDeleteResponse,
member_list_params,
member_create_params,
member_delete_params,
member_update_params,
)

Expand Down Expand Up @@ -208,6 +209,7 @@ def delete(
member_id: str,
*,
account_id: object,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand All @@ -233,6 +235,7 @@ def delete(
raise ValueError(f"Expected a non-empty value for `member_id` but received {member_id!r}")
return self._delete(
f"/accounts/{account_id}/members/{member_id}",
body=maybe_transform(body, member_delete_params.MemberDeleteParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down Expand Up @@ -452,6 +455,7 @@ async def delete(
member_id: str,
*,
account_id: object,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand All @@ -477,6 +481,7 @@ async def delete(
raise ValueError(f"Expected a non-empty value for `member_id` but received {member_id!r}")
return await self._delete(
f"/accounts/{account_id}/members/{member_id}",
body=await async_maybe_transform(body, member_delete_params.MemberDeleteParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down
19 changes: 18 additions & 1 deletion src/cloudflare/resources/addressing/address_maps/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import httpx

from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven
from ...._utils import (
maybe_transform,
async_maybe_transform,
)
from ...._compat import cached_property
from ...._resource import SyncAPIResource, AsyncAPIResource
from ...._response import (
Expand All @@ -19,7 +23,12 @@
from ...._base_client import (
make_request_options,
)
from ....types.addressing.address_maps import AccountDeleteResponse, AccountUpdateResponse
from ....types.addressing.address_maps import (
AccountDeleteResponse,
AccountUpdateResponse,
account_delete_params,
account_update_params,
)

__all__ = ["Accounts", "AsyncAccounts"]

Expand All @@ -38,6 +47,7 @@ def update(
address_map_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -69,6 +79,7 @@ def update(
Optional[AccountUpdateResponse],
self._put(
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
body=maybe_transform(body, account_update_params.AccountUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand All @@ -87,6 +98,7 @@ def delete(
address_map_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -118,6 +130,7 @@ def delete(
Optional[AccountDeleteResponse],
self._delete(
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
body=maybe_transform(body, account_delete_params.AccountDeleteParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down Expand Up @@ -146,6 +159,7 @@ async def update(
address_map_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -177,6 +191,7 @@ async def update(
Optional[AccountUpdateResponse],
await self._put(
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
body=await async_maybe_transform(body, account_update_params.AccountUpdateParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand All @@ -195,6 +210,7 @@ async def delete(
address_map_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -226,6 +242,7 @@ async def delete(
Optional[AccountDeleteResponse],
await self._delete(
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}/accounts/{account_id}",
body=await async_maybe_transform(body, account_delete_params.AccountDeleteParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
AddressMapDeleteResponse,
address_map_edit_params,
address_map_create_params,
address_map_delete_params,
)

__all__ = ["AddressMaps", "AsyncAddressMaps"]
Expand Down Expand Up @@ -177,6 +178,7 @@ def delete(
address_map_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -210,6 +212,7 @@ def delete(
Optional[AddressMapDeleteResponse],
self._delete(
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}",
body=maybe_transform(body, address_map_delete_params.AddressMapDeleteParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down Expand Up @@ -451,6 +454,7 @@ async def delete(
address_map_id: str,
*,
account_id: str,
body: object,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
# The extra values given here take precedence over values defined on the client or passed to this method.
extra_headers: Headers | None = None,
Expand Down Expand Up @@ -484,6 +488,7 @@ async def delete(
Optional[AddressMapDeleteResponse],
await self._delete(
f"/accounts/{account_id}/addressing/address_maps/{address_map_id}",
body=await async_maybe_transform(body, address_map_delete_params.AddressMapDeleteParams),
options=make_request_options(
extra_headers=extra_headers,
extra_query=extra_query,
Expand Down
Loading

0 comments on commit 3f5595d

Please sign in to comment.