|
| 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 NOT_GIVEN, Body, Query, Headers, NotGiven |
| 8 | +from ..._compat import cached_property |
| 9 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 10 | +from ..._response import ( |
| 11 | + to_raw_response_wrapper, |
| 12 | + to_streamed_response_wrapper, |
| 13 | + async_to_raw_response_wrapper, |
| 14 | + async_to_streamed_response_wrapper, |
| 15 | +) |
| 16 | +from ..._base_client import make_request_options |
| 17 | + |
| 18 | +__all__ = ["ResponsesResource", "AsyncResponsesResource"] |
| 19 | + |
| 20 | + |
| 21 | +class ResponsesResource(SyncAPIResource): |
| 22 | + @cached_property |
| 23 | + def with_raw_response(self) -> ResponsesResourceWithRawResponse: |
| 24 | + """ |
| 25 | + This property can be used as a prefix for any HTTP method call to return the |
| 26 | + the raw response object instead of the parsed content. |
| 27 | +
|
| 28 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 29 | + """ |
| 30 | + return ResponsesResourceWithRawResponse(self) |
| 31 | + |
| 32 | + @cached_property |
| 33 | + def with_streaming_response(self) -> ResponsesResourceWithStreamingResponse: |
| 34 | + """ |
| 35 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 36 | +
|
| 37 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 38 | + """ |
| 39 | + return ResponsesResourceWithStreamingResponse(self) |
| 40 | + |
| 41 | + def get( |
| 42 | + self, |
| 43 | + response_id: str, |
| 44 | + *, |
| 45 | + account_id: str, |
| 46 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 47 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 48 | + extra_headers: Headers | None = None, |
| 49 | + extra_query: Query | None = None, |
| 50 | + extra_body: Body | None = None, |
| 51 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 52 | + ) -> str: |
| 53 | + """Returns the raw response of the network request. |
| 54 | +
|
| 55 | + If HTML, a plain text response |
| 56 | + will be returned. |
| 57 | +
|
| 58 | + Args: |
| 59 | + account_id: Account ID. |
| 60 | +
|
| 61 | + response_id: Response hash. |
| 62 | +
|
| 63 | + extra_headers: Send extra headers |
| 64 | +
|
| 65 | + extra_query: Add additional query parameters to the request |
| 66 | +
|
| 67 | + extra_body: Add additional JSON properties to the request |
| 68 | +
|
| 69 | + timeout: Override the client-level default timeout for this request, in seconds |
| 70 | + """ |
| 71 | + if not account_id: |
| 72 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 73 | + if not response_id: |
| 74 | + raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}") |
| 75 | + extra_headers = {"Accept": "text/plain", **(extra_headers or {})} |
| 76 | + return self._get( |
| 77 | + f"/accounts/{account_id}/urlscanner/v2/responses/{response_id}", |
| 78 | + options=make_request_options( |
| 79 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 80 | + ), |
| 81 | + cast_to=str, |
| 82 | + ) |
| 83 | + |
| 84 | + |
| 85 | +class AsyncResponsesResource(AsyncAPIResource): |
| 86 | + @cached_property |
| 87 | + def with_raw_response(self) -> AsyncResponsesResourceWithRawResponse: |
| 88 | + """ |
| 89 | + This property can be used as a prefix for any HTTP method call to return the |
| 90 | + the raw response object instead of the parsed content. |
| 91 | +
|
| 92 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 93 | + """ |
| 94 | + return AsyncResponsesResourceWithRawResponse(self) |
| 95 | + |
| 96 | + @cached_property |
| 97 | + def with_streaming_response(self) -> AsyncResponsesResourceWithStreamingResponse: |
| 98 | + """ |
| 99 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 100 | +
|
| 101 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 102 | + """ |
| 103 | + return AsyncResponsesResourceWithStreamingResponse(self) |
| 104 | + |
| 105 | + async def get( |
| 106 | + self, |
| 107 | + response_id: str, |
| 108 | + *, |
| 109 | + account_id: str, |
| 110 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 111 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 112 | + extra_headers: Headers | None = None, |
| 113 | + extra_query: Query | None = None, |
| 114 | + extra_body: Body | None = None, |
| 115 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 116 | + ) -> str: |
| 117 | + """Returns the raw response of the network request. |
| 118 | +
|
| 119 | + If HTML, a plain text response |
| 120 | + will be returned. |
| 121 | +
|
| 122 | + Args: |
| 123 | + account_id: Account ID. |
| 124 | +
|
| 125 | + response_id: Response hash. |
| 126 | +
|
| 127 | + extra_headers: Send extra headers |
| 128 | +
|
| 129 | + extra_query: Add additional query parameters to the request |
| 130 | +
|
| 131 | + extra_body: Add additional JSON properties to the request |
| 132 | +
|
| 133 | + timeout: Override the client-level default timeout for this request, in seconds |
| 134 | + """ |
| 135 | + if not account_id: |
| 136 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 137 | + if not response_id: |
| 138 | + raise ValueError(f"Expected a non-empty value for `response_id` but received {response_id!r}") |
| 139 | + extra_headers = {"Accept": "text/plain", **(extra_headers or {})} |
| 140 | + return await self._get( |
| 141 | + f"/accounts/{account_id}/urlscanner/v2/responses/{response_id}", |
| 142 | + options=make_request_options( |
| 143 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 144 | + ), |
| 145 | + cast_to=str, |
| 146 | + ) |
| 147 | + |
| 148 | + |
| 149 | +class ResponsesResourceWithRawResponse: |
| 150 | + def __init__(self, responses: ResponsesResource) -> None: |
| 151 | + self._responses = responses |
| 152 | + |
| 153 | + self.get = to_raw_response_wrapper( |
| 154 | + responses.get, |
| 155 | + ) |
| 156 | + |
| 157 | + |
| 158 | +class AsyncResponsesResourceWithRawResponse: |
| 159 | + def __init__(self, responses: AsyncResponsesResource) -> None: |
| 160 | + self._responses = responses |
| 161 | + |
| 162 | + self.get = async_to_raw_response_wrapper( |
| 163 | + responses.get, |
| 164 | + ) |
| 165 | + |
| 166 | + |
| 167 | +class ResponsesResourceWithStreamingResponse: |
| 168 | + def __init__(self, responses: ResponsesResource) -> None: |
| 169 | + self._responses = responses |
| 170 | + |
| 171 | + self.get = to_streamed_response_wrapper( |
| 172 | + responses.get, |
| 173 | + ) |
| 174 | + |
| 175 | + |
| 176 | +class AsyncResponsesResourceWithStreamingResponse: |
| 177 | + def __init__(self, responses: AsyncResponsesResource) -> None: |
| 178 | + self._responses = responses |
| 179 | + |
| 180 | + self.get = async_to_streamed_response_wrapper( |
| 181 | + responses.get, |
| 182 | + ) |
0 commit comments