diff --git a/.stats.yml b/.stats.yml index 51913296bf9..43a05597334 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,4 +1,4 @@ -configured_endpoints: 1680 +configured_endpoints: 1681 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-22aa409339ba3ba4e61a86e7e94dc5a66082c5c20615d1d30e3b9499d6407e31.yml openapi_spec_hash: e5eb84a55caa82c6dfdc82b7fbe3e8aa -config_hash: 713ebf60a015dd910800437b34425bea +config_hash: 6861676932ec6aacb336d1cdc59ca521 diff --git a/api.md b/api.md index 019b9503a0f..445c8f29721 100644 --- a/api.md +++ b/api.md @@ -9255,6 +9255,18 @@ Methods: - client.workflows.instances.status.edit(instance_id, \*, account_id, workflow_name, \*\*params) -> StatusEditResponse +### Events + +Types: + +```python +from cloudflare.types.workflows.instances import EventCreateResponse +``` + +Methods: + +- client.workflows.instances.events.create(event_type, \*, account_id, workflow_name, instance_id, \*\*params) -> object + ## Versions Types: diff --git a/src/cloudflare/resources/workflows/instances/__init__.py b/src/cloudflare/resources/workflows/instances/__init__.py index 803b1850242..eaef3efe5f5 100644 --- a/src/cloudflare/resources/workflows/instances/__init__.py +++ b/src/cloudflare/resources/workflows/instances/__init__.py @@ -1,5 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from .events import ( + EventsResource, + AsyncEventsResource, + EventsResourceWithRawResponse, + AsyncEventsResourceWithRawResponse, + EventsResourceWithStreamingResponse, + AsyncEventsResourceWithStreamingResponse, +) from .status import ( StatusResource, AsyncStatusResource, @@ -24,6 +32,12 @@ "AsyncStatusResourceWithRawResponse", "StatusResourceWithStreamingResponse", "AsyncStatusResourceWithStreamingResponse", + "EventsResource", + "AsyncEventsResource", + "EventsResourceWithRawResponse", + "AsyncEventsResourceWithRawResponse", + "EventsResourceWithStreamingResponse", + "AsyncEventsResourceWithStreamingResponse", "InstancesResource", "AsyncInstancesResource", "InstancesResourceWithRawResponse", diff --git a/src/cloudflare/resources/workflows/instances/events.py b/src/cloudflare/resources/workflows/instances/events.py new file mode 100644 index 00000000000..e1488ac5e7b --- /dev/null +++ b/src/cloudflare/resources/workflows/instances/events.py @@ -0,0 +1,200 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Type, Optional, cast + +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 ( + to_raw_response_wrapper, + to_streamed_response_wrapper, + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, +) +from ...._wrappers import ResultWrapper +from ...._base_client import make_request_options +from ....types.workflows.instances import event_create_params + +__all__ = ["EventsResource", "AsyncEventsResource"] + + +class EventsResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> EventsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers + """ + return EventsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> EventsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response + """ + return EventsResourceWithStreamingResponse(self) + + def create( + self, + event_type: str, + *, + account_id: str, + workflow_name: str, + instance_id: str, + body: object | NotGiven = NOT_GIVEN, + # 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, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> object: + """ + Send event to instance + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not account_id: + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") + if not workflow_name: + raise ValueError(f"Expected a non-empty value for `workflow_name` but received {workflow_name!r}") + if not instance_id: + raise ValueError(f"Expected a non-empty value for `instance_id` but received {instance_id!r}") + if not event_type: + raise ValueError(f"Expected a non-empty value for `event_type` but received {event_type!r}") + return self._post( + f"/accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}/events/{event_type}", + body=maybe_transform(body, event_create_params.EventCreateParams), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[object]]._unwrapper, + ), + cast_to=cast(Type[object], ResultWrapper[object]), + ) + + +class AsyncEventsResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncEventsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return + the raw response object instead of the parsed content. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers + """ + return AsyncEventsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncEventsResourceWithStreamingResponse: + """ + An alternative to `.with_raw_response` that doesn't eagerly read the response body. + + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response + """ + return AsyncEventsResourceWithStreamingResponse(self) + + async def create( + self, + event_type: str, + *, + account_id: str, + workflow_name: str, + instance_id: str, + body: object | NotGiven = NOT_GIVEN, + # 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, + extra_query: Query | None = None, + extra_body: Body | None = None, + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, + ) -> object: + """ + Send event to instance + + Args: + extra_headers: Send extra headers + + extra_query: Add additional query parameters to the request + + extra_body: Add additional JSON properties to the request + + timeout: Override the client-level default timeout for this request, in seconds + """ + if not account_id: + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") + if not workflow_name: + raise ValueError(f"Expected a non-empty value for `workflow_name` but received {workflow_name!r}") + if not instance_id: + raise ValueError(f"Expected a non-empty value for `instance_id` but received {instance_id!r}") + if not event_type: + raise ValueError(f"Expected a non-empty value for `event_type` but received {event_type!r}") + return await self._post( + f"/accounts/{account_id}/workflows/{workflow_name}/instances/{instance_id}/events/{event_type}", + body=await async_maybe_transform(body, event_create_params.EventCreateParams), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[object]]._unwrapper, + ), + cast_to=cast(Type[object], ResultWrapper[object]), + ) + + +class EventsResourceWithRawResponse: + def __init__(self, events: EventsResource) -> None: + self._events = events + + self.create = to_raw_response_wrapper( + events.create, + ) + + +class AsyncEventsResourceWithRawResponse: + def __init__(self, events: AsyncEventsResource) -> None: + self._events = events + + self.create = async_to_raw_response_wrapper( + events.create, + ) + + +class EventsResourceWithStreamingResponse: + def __init__(self, events: EventsResource) -> None: + self._events = events + + self.create = to_streamed_response_wrapper( + events.create, + ) + + +class AsyncEventsResourceWithStreamingResponse: + def __init__(self, events: AsyncEventsResource) -> None: + self._events = events + + self.create = async_to_streamed_response_wrapper( + events.create, + ) diff --git a/src/cloudflare/resources/workflows/instances/instances.py b/src/cloudflare/resources/workflows/instances/instances.py index 585736712d4..d11f60b659e 100644 --- a/src/cloudflare/resources/workflows/instances/instances.py +++ b/src/cloudflare/resources/workflows/instances/instances.py @@ -8,6 +8,14 @@ import httpx +from .events import ( + EventsResource, + AsyncEventsResource, + EventsResourceWithRawResponse, + AsyncEventsResourceWithRawResponse, + EventsResourceWithStreamingResponse, + AsyncEventsResourceWithStreamingResponse, +) from .status import ( StatusResource, AsyncStatusResource, @@ -46,6 +54,10 @@ class InstancesResource(SyncAPIResource): def status(self) -> StatusResource: return StatusResource(self._client) + @cached_property + def events(self) -> EventsResource: + return EventsResource(self._client) + @cached_property def with_raw_response(self) -> InstancesResourceWithRawResponse: """ @@ -265,6 +277,10 @@ class AsyncInstancesResource(AsyncAPIResource): def status(self) -> AsyncStatusResource: return AsyncStatusResource(self._client) + @cached_property + def events(self) -> AsyncEventsResource: + return AsyncEventsResource(self._client) + @cached_property def with_raw_response(self) -> AsyncInstancesResourceWithRawResponse: """ @@ -500,6 +516,10 @@ def __init__(self, instances: InstancesResource) -> None: def status(self) -> StatusResourceWithRawResponse: return StatusResourceWithRawResponse(self._instances.status) + @cached_property + def events(self) -> EventsResourceWithRawResponse: + return EventsResourceWithRawResponse(self._instances.events) + class AsyncInstancesResourceWithRawResponse: def __init__(self, instances: AsyncInstancesResource) -> None: @@ -522,6 +542,10 @@ def __init__(self, instances: AsyncInstancesResource) -> None: def status(self) -> AsyncStatusResourceWithRawResponse: return AsyncStatusResourceWithRawResponse(self._instances.status) + @cached_property + def events(self) -> AsyncEventsResourceWithRawResponse: + return AsyncEventsResourceWithRawResponse(self._instances.events) + class InstancesResourceWithStreamingResponse: def __init__(self, instances: InstancesResource) -> None: @@ -544,6 +568,10 @@ def __init__(self, instances: InstancesResource) -> None: def status(self) -> StatusResourceWithStreamingResponse: return StatusResourceWithStreamingResponse(self._instances.status) + @cached_property + def events(self) -> EventsResourceWithStreamingResponse: + return EventsResourceWithStreamingResponse(self._instances.events) + class AsyncInstancesResourceWithStreamingResponse: def __init__(self, instances: AsyncInstancesResource) -> None: @@ -565,3 +593,7 @@ def __init__(self, instances: AsyncInstancesResource) -> None: @cached_property def status(self) -> AsyncStatusResourceWithStreamingResponse: return AsyncStatusResourceWithStreamingResponse(self._instances.status) + + @cached_property + def events(self) -> AsyncEventsResourceWithStreamingResponse: + return AsyncEventsResourceWithStreamingResponse(self._instances.events) diff --git a/src/cloudflare/types/workflows/instances/__init__.py b/src/cloudflare/types/workflows/instances/__init__.py index c962e03d75d..66347d6448a 100644 --- a/src/cloudflare/types/workflows/instances/__init__.py +++ b/src/cloudflare/types/workflows/instances/__init__.py @@ -3,4 +3,5 @@ from __future__ import annotations from .status_edit_params import StatusEditParams as StatusEditParams +from .event_create_params import EventCreateParams as EventCreateParams from .status_edit_response import StatusEditResponse as StatusEditResponse diff --git a/src/cloudflare/types/workflows/instances/event_create_params.py b/src/cloudflare/types/workflows/instances/event_create_params.py new file mode 100644 index 00000000000..52118424ae5 --- /dev/null +++ b/src/cloudflare/types/workflows/instances/event_create_params.py @@ -0,0 +1,17 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing_extensions import Required, TypedDict + +__all__ = ["EventCreateParams"] + + +class EventCreateParams(TypedDict, total=False): + account_id: Required[str] + + workflow_name: Required[str] + + instance_id: Required[str] + + body: object diff --git a/tests/api_resources/workflows/instances/test_events.py b/tests/api_resources/workflows/instances/test_events.py new file mode 100644 index 00000000000..8857d0356fd --- /dev/null +++ b/tests/api_resources/workflows/instances/test_events.py @@ -0,0 +1,191 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from cloudflare import Cloudflare, AsyncCloudflare +from tests.utils import assert_matches_type + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestEvents: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: Cloudflare) -> None: + event = client.workflows.instances.events.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) + assert_matches_type(object, event, path=["response"]) + + @parametrize + def test_method_create_with_all_params(self, client: Cloudflare) -> None: + event = client.workflows.instances.events.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + body={}, + ) + assert_matches_type(object, event, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: Cloudflare) -> None: + response = client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + event = response.parse() + assert_matches_type(object, event, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: Cloudflare) -> None: + with client.workflows.instances.events.with_streaming_response.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + event = response.parse() + assert_matches_type(object, event, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_create(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"): + client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="", + workflow_name="x", + instance_id="x", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `workflow_name` but received ''"): + client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="account_id", + workflow_name="", + instance_id="x", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `instance_id` but received ''"): + client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `event_type` but received ''"): + client.workflows.instances.events.with_raw_response.create( + event_type="", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) + + +class TestAsyncEvents: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_create(self, async_client: AsyncCloudflare) -> None: + event = await async_client.workflows.instances.events.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) + assert_matches_type(object, event, path=["response"]) + + @parametrize + async def test_method_create_with_all_params(self, async_client: AsyncCloudflare) -> None: + event = await async_client.workflows.instances.events.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + body={}, + ) + assert_matches_type(object, event, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None: + response = await async_client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + event = await response.parse() + assert_matches_type(object, event, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None: + async with async_client.workflows.instances.events.with_streaming_response.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="x", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + event = await response.parse() + assert_matches_type(object, event, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_create(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `account_id` but received ''"): + await async_client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="", + workflow_name="x", + instance_id="x", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `workflow_name` but received ''"): + await async_client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="account_id", + workflow_name="", + instance_id="x", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `instance_id` but received ''"): + await async_client.workflows.instances.events.with_raw_response.create( + event_type="x", + account_id="account_id", + workflow_name="x", + instance_id="", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `event_type` but received ''"): + await async_client.workflows.instances.events.with_raw_response.create( + event_type="", + account_id="account_id", + workflow_name="x", + instance_id="x", + )