|
| 1 | +# File generated from our OpenAPI spec by Stainless. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Any, cast |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ......_types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 10 | +from ......_compat import cached_property |
| 11 | +from ......_resource import SyncAPIResource, AsyncAPIResource |
| 12 | +from ......_response import ( |
| 13 | + to_raw_response_wrapper, |
| 14 | + to_streamed_response_wrapper, |
| 15 | + async_to_raw_response_wrapper, |
| 16 | + async_to_streamed_response_wrapper, |
| 17 | +) |
| 18 | +from ......_base_client import ( |
| 19 | + make_request_options, |
| 20 | +) |
| 21 | +from ......types.workers_for_platforms.dispatch.namespaces.scripts import BindingGetResponse |
| 22 | + |
| 23 | +__all__ = ["Bindings", "AsyncBindings"] |
| 24 | + |
| 25 | + |
| 26 | +class Bindings(SyncAPIResource): |
| 27 | + @cached_property |
| 28 | + def with_raw_response(self) -> BindingsWithRawResponse: |
| 29 | + return BindingsWithRawResponse(self) |
| 30 | + |
| 31 | + @cached_property |
| 32 | + def with_streaming_response(self) -> BindingsWithStreamingResponse: |
| 33 | + return BindingsWithStreamingResponse(self) |
| 34 | + |
| 35 | + def get( |
| 36 | + self, |
| 37 | + script_name: str, |
| 38 | + *, |
| 39 | + account_id: str, |
| 40 | + dispatch_namespace: str, |
| 41 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 42 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 43 | + extra_headers: Headers | None = None, |
| 44 | + extra_query: Query | None = None, |
| 45 | + extra_body: Body | None = None, |
| 46 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 47 | + ) -> BindingGetResponse: |
| 48 | + """ |
| 49 | + Fetch script bindings from a script uploaded to a Workers for Platforms |
| 50 | + namespace. |
| 51 | +
|
| 52 | + Args: |
| 53 | + account_id: Identifier |
| 54 | +
|
| 55 | + dispatch_namespace: Name of the Workers for Platforms dispatch namespace. |
| 56 | +
|
| 57 | + script_name: Name of the script, used in URLs and route configuration. |
| 58 | +
|
| 59 | + extra_headers: Send extra headers |
| 60 | +
|
| 61 | + extra_query: Add additional query parameters to the request |
| 62 | +
|
| 63 | + extra_body: Add additional JSON properties to the request |
| 64 | +
|
| 65 | + timeout: Override the client-level default timeout for this request, in seconds |
| 66 | + """ |
| 67 | + if not account_id: |
| 68 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 69 | + if not dispatch_namespace: |
| 70 | + raise ValueError(f"Expected a non-empty value for `dispatch_namespace` but received {dispatch_namespace!r}") |
| 71 | + if not script_name: |
| 72 | + raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}") |
| 73 | + return cast( |
| 74 | + BindingGetResponse, |
| 75 | + self._get( |
| 76 | + f"/accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/bindings", |
| 77 | + options=make_request_options( |
| 78 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 79 | + ), |
| 80 | + cast_to=cast( |
| 81 | + Any, BindingGetResponse |
| 82 | + ), # Union types cannot be passed in as arguments in the type system |
| 83 | + ), |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | +class AsyncBindings(AsyncAPIResource): |
| 88 | + @cached_property |
| 89 | + def with_raw_response(self) -> AsyncBindingsWithRawResponse: |
| 90 | + return AsyncBindingsWithRawResponse(self) |
| 91 | + |
| 92 | + @cached_property |
| 93 | + def with_streaming_response(self) -> AsyncBindingsWithStreamingResponse: |
| 94 | + return AsyncBindingsWithStreamingResponse(self) |
| 95 | + |
| 96 | + async def get( |
| 97 | + self, |
| 98 | + script_name: str, |
| 99 | + *, |
| 100 | + account_id: str, |
| 101 | + dispatch_namespace: str, |
| 102 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 103 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 104 | + extra_headers: Headers | None = None, |
| 105 | + extra_query: Query | None = None, |
| 106 | + extra_body: Body | None = None, |
| 107 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 108 | + ) -> BindingGetResponse: |
| 109 | + """ |
| 110 | + Fetch script bindings from a script uploaded to a Workers for Platforms |
| 111 | + namespace. |
| 112 | +
|
| 113 | + Args: |
| 114 | + account_id: Identifier |
| 115 | +
|
| 116 | + dispatch_namespace: Name of the Workers for Platforms dispatch namespace. |
| 117 | +
|
| 118 | + script_name: Name of the script, used in URLs and route configuration. |
| 119 | +
|
| 120 | + extra_headers: Send extra headers |
| 121 | +
|
| 122 | + extra_query: Add additional query parameters to the request |
| 123 | +
|
| 124 | + extra_body: Add additional JSON properties to the request |
| 125 | +
|
| 126 | + timeout: Override the client-level default timeout for this request, in seconds |
| 127 | + """ |
| 128 | + if not account_id: |
| 129 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 130 | + if not dispatch_namespace: |
| 131 | + raise ValueError(f"Expected a non-empty value for `dispatch_namespace` but received {dispatch_namespace!r}") |
| 132 | + if not script_name: |
| 133 | + raise ValueError(f"Expected a non-empty value for `script_name` but received {script_name!r}") |
| 134 | + return cast( |
| 135 | + BindingGetResponse, |
| 136 | + await self._get( |
| 137 | + f"/accounts/{account_id}/workers/dispatch/namespaces/{dispatch_namespace}/scripts/{script_name}/bindings", |
| 138 | + options=make_request_options( |
| 139 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 140 | + ), |
| 141 | + cast_to=cast( |
| 142 | + Any, BindingGetResponse |
| 143 | + ), # Union types cannot be passed in as arguments in the type system |
| 144 | + ), |
| 145 | + ) |
| 146 | + |
| 147 | + |
| 148 | +class BindingsWithRawResponse: |
| 149 | + def __init__(self, bindings: Bindings) -> None: |
| 150 | + self._bindings = bindings |
| 151 | + |
| 152 | + self.get = to_raw_response_wrapper( |
| 153 | + bindings.get, |
| 154 | + ) |
| 155 | + |
| 156 | + |
| 157 | +class AsyncBindingsWithRawResponse: |
| 158 | + def __init__(self, bindings: AsyncBindings) -> None: |
| 159 | + self._bindings = bindings |
| 160 | + |
| 161 | + self.get = async_to_raw_response_wrapper( |
| 162 | + bindings.get, |
| 163 | + ) |
| 164 | + |
| 165 | + |
| 166 | +class BindingsWithStreamingResponse: |
| 167 | + def __init__(self, bindings: Bindings) -> None: |
| 168 | + self._bindings = bindings |
| 169 | + |
| 170 | + self.get = to_streamed_response_wrapper( |
| 171 | + bindings.get, |
| 172 | + ) |
| 173 | + |
| 174 | + |
| 175 | +class AsyncBindingsWithStreamingResponse: |
| 176 | + def __init__(self, bindings: AsyncBindings) -> None: |
| 177 | + self._bindings = bindings |
| 178 | + |
| 179 | + self.get = async_to_streamed_response_wrapper( |
| 180 | + bindings.get, |
| 181 | + ) |
0 commit comments