|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import httpx |
| 6 | + |
| 7 | +from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given |
| 8 | +from ..._utils import path_template, maybe_transform, async_maybe_transform |
| 9 | +from ..._compat import cached_property |
| 10 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 11 | +from ..._response import ( |
| 12 | + to_raw_response_wrapper, |
| 13 | + to_streamed_response_wrapper, |
| 14 | + async_to_raw_response_wrapper, |
| 15 | + async_to_streamed_response_wrapper, |
| 16 | +) |
| 17 | +from ..._base_client import make_request_options |
| 18 | +from ...types.browsers import BrowserLiveViewScope, live_view_create_params |
| 19 | +from ...types.browsers.browser_live_view import BrowserLiveView |
| 20 | +from ...types.browsers.browser_live_view_scope import BrowserLiveViewScope |
| 21 | + |
| 22 | +__all__ = ["LiveViewResource", "AsyncLiveViewResource"] |
| 23 | + |
| 24 | + |
| 25 | +class LiveViewResource(SyncAPIResource): |
| 26 | + """Create and manage browser sessions.""" |
| 27 | + |
| 28 | + @cached_property |
| 29 | + def with_raw_response(self) -> LiveViewResourceWithRawResponse: |
| 30 | + """ |
| 31 | + This property can be used as a prefix for any HTTP method call to return |
| 32 | + the raw response object instead of the parsed content. |
| 33 | +
|
| 34 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers |
| 35 | + """ |
| 36 | + return LiveViewResourceWithRawResponse(self) |
| 37 | + |
| 38 | + @cached_property |
| 39 | + def with_streaming_response(self) -> LiveViewResourceWithStreamingResponse: |
| 40 | + """ |
| 41 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 42 | +
|
| 43 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response |
| 44 | + """ |
| 45 | + return LiveViewResourceWithStreamingResponse(self) |
| 46 | + |
| 47 | + def create( |
| 48 | + self, |
| 49 | + id_or_name: str, |
| 50 | + *, |
| 51 | + scope: BrowserLiveViewScope | Omit = omit, |
| 52 | + ttl_seconds: int | Omit = omit, |
| 53 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 54 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 55 | + extra_headers: Headers | None = None, |
| 56 | + extra_query: Query | None = None, |
| 57 | + extra_body: Body | None = None, |
| 58 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 59 | + idempotency_key: str | None = None, |
| 60 | + ) -> BrowserLiveView: |
| 61 | + """ |
| 62 | + Creates a live view URL for a headful browser that grants either read-only or |
| 63 | + control access. The URL works only for the live view: it cannot connect to CDP, |
| 64 | + WebDriver, or any other browser endpoint. A read-only URL shows the browser but |
| 65 | + cannot send input, regardless of query parameters. The URL stays valid until the |
| 66 | + browser is deleted, or until `ttl_seconds` elapse when set. For a browser |
| 67 | + acquired from a pool, it stops working when the browser is released. Nothing is |
| 68 | + stored, so a URL cannot be revoked before then. |
| 69 | +
|
| 70 | + Args: |
| 71 | + scope: `read` shows the browser without accepting input. `control` also lets the viewer |
| 72 | + drive the browser through the live view. |
| 73 | +
|
| 74 | + ttl_seconds: Seconds until the URL expires. Omit to keep it valid until the browser is |
| 75 | + deleted. |
| 76 | +
|
| 77 | + extra_headers: Send extra headers |
| 78 | +
|
| 79 | + extra_query: Add additional query parameters to the request |
| 80 | +
|
| 81 | + extra_body: Add additional JSON properties to the request |
| 82 | +
|
| 83 | + timeout: Override the client-level default timeout for this request, in seconds |
| 84 | +
|
| 85 | + idempotency_key: Specify a custom idempotency key for this request |
| 86 | + """ |
| 87 | + if not id_or_name: |
| 88 | + raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}") |
| 89 | + return self._post( |
| 90 | + path_template("/browsers/{id_or_name}/live_view", id_or_name=id_or_name), |
| 91 | + body=maybe_transform( |
| 92 | + { |
| 93 | + "scope": scope, |
| 94 | + "ttl_seconds": ttl_seconds, |
| 95 | + }, |
| 96 | + live_view_create_params.LiveViewCreateParams, |
| 97 | + ), |
| 98 | + options=make_request_options( |
| 99 | + extra_headers=extra_headers, |
| 100 | + extra_query=extra_query, |
| 101 | + extra_body=extra_body, |
| 102 | + timeout=timeout, |
| 103 | + idempotency_key=idempotency_key, |
| 104 | + ), |
| 105 | + cast_to=BrowserLiveView, |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +class AsyncLiveViewResource(AsyncAPIResource): |
| 110 | + """Create and manage browser sessions.""" |
| 111 | + |
| 112 | + @cached_property |
| 113 | + def with_raw_response(self) -> AsyncLiveViewResourceWithRawResponse: |
| 114 | + """ |
| 115 | + This property can be used as a prefix for any HTTP method call to return |
| 116 | + the raw response object instead of the parsed content. |
| 117 | +
|
| 118 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#accessing-raw-response-data-eg-headers |
| 119 | + """ |
| 120 | + return AsyncLiveViewResourceWithRawResponse(self) |
| 121 | + |
| 122 | + @cached_property |
| 123 | + def with_streaming_response(self) -> AsyncLiveViewResourceWithStreamingResponse: |
| 124 | + """ |
| 125 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 126 | +
|
| 127 | + For more information, see https://www.github.com/kernel/kernel-python-sdk#with_streaming_response |
| 128 | + """ |
| 129 | + return AsyncLiveViewResourceWithStreamingResponse(self) |
| 130 | + |
| 131 | + async def create( |
| 132 | + self, |
| 133 | + id_or_name: str, |
| 134 | + *, |
| 135 | + scope: BrowserLiveViewScope | Omit = omit, |
| 136 | + ttl_seconds: int | Omit = omit, |
| 137 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 138 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 139 | + extra_headers: Headers | None = None, |
| 140 | + extra_query: Query | None = None, |
| 141 | + extra_body: Body | None = None, |
| 142 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 143 | + idempotency_key: str | None = None, |
| 144 | + ) -> BrowserLiveView: |
| 145 | + """ |
| 146 | + Creates a live view URL for a headful browser that grants either read-only or |
| 147 | + control access. The URL works only for the live view: it cannot connect to CDP, |
| 148 | + WebDriver, or any other browser endpoint. A read-only URL shows the browser but |
| 149 | + cannot send input, regardless of query parameters. The URL stays valid until the |
| 150 | + browser is deleted, or until `ttl_seconds` elapse when set. For a browser |
| 151 | + acquired from a pool, it stops working when the browser is released. Nothing is |
| 152 | + stored, so a URL cannot be revoked before then. |
| 153 | +
|
| 154 | + Args: |
| 155 | + scope: `read` shows the browser without accepting input. `control` also lets the viewer |
| 156 | + drive the browser through the live view. |
| 157 | +
|
| 158 | + ttl_seconds: Seconds until the URL expires. Omit to keep it valid until the browser is |
| 159 | + deleted. |
| 160 | +
|
| 161 | + extra_headers: Send extra headers |
| 162 | +
|
| 163 | + extra_query: Add additional query parameters to the request |
| 164 | +
|
| 165 | + extra_body: Add additional JSON properties to the request |
| 166 | +
|
| 167 | + timeout: Override the client-level default timeout for this request, in seconds |
| 168 | +
|
| 169 | + idempotency_key: Specify a custom idempotency key for this request |
| 170 | + """ |
| 171 | + if not id_or_name: |
| 172 | + raise ValueError(f"Expected a non-empty value for `id_or_name` but received {id_or_name!r}") |
| 173 | + return await self._post( |
| 174 | + path_template("/browsers/{id_or_name}/live_view", id_or_name=id_or_name), |
| 175 | + body=await async_maybe_transform( |
| 176 | + { |
| 177 | + "scope": scope, |
| 178 | + "ttl_seconds": ttl_seconds, |
| 179 | + }, |
| 180 | + live_view_create_params.LiveViewCreateParams, |
| 181 | + ), |
| 182 | + options=make_request_options( |
| 183 | + extra_headers=extra_headers, |
| 184 | + extra_query=extra_query, |
| 185 | + extra_body=extra_body, |
| 186 | + timeout=timeout, |
| 187 | + idempotency_key=idempotency_key, |
| 188 | + ), |
| 189 | + cast_to=BrowserLiveView, |
| 190 | + ) |
| 191 | + |
| 192 | + |
| 193 | +class LiveViewResourceWithRawResponse: |
| 194 | + def __init__(self, live_view: LiveViewResource) -> None: |
| 195 | + self._live_view = live_view |
| 196 | + |
| 197 | + self.create = to_raw_response_wrapper( |
| 198 | + live_view.create, |
| 199 | + ) |
| 200 | + |
| 201 | + |
| 202 | +class AsyncLiveViewResourceWithRawResponse: |
| 203 | + def __init__(self, live_view: AsyncLiveViewResource) -> None: |
| 204 | + self._live_view = live_view |
| 205 | + |
| 206 | + self.create = async_to_raw_response_wrapper( |
| 207 | + live_view.create, |
| 208 | + ) |
| 209 | + |
| 210 | + |
| 211 | +class LiveViewResourceWithStreamingResponse: |
| 212 | + def __init__(self, live_view: LiveViewResource) -> None: |
| 213 | + self._live_view = live_view |
| 214 | + |
| 215 | + self.create = to_streamed_response_wrapper( |
| 216 | + live_view.create, |
| 217 | + ) |
| 218 | + |
| 219 | + |
| 220 | +class AsyncLiveViewResourceWithStreamingResponse: |
| 221 | + def __init__(self, live_view: AsyncLiveViewResource) -> None: |
| 222 | + self._live_view = live_view |
| 223 | + |
| 224 | + self.create = async_to_streamed_response_wrapper( |
| 225 | + live_view.create, |
| 226 | + ) |
0 commit comments