|
| 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 |
| 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 .....pagination import SyncSinglePage, AsyncSinglePage |
| 18 | +from ....._base_client import AsyncPaginator, make_request_options |
| 19 | +from .....types.logs.log_explorer.datasets.available_dataset import AvailableDataset |
| 20 | + |
| 21 | +__all__ = ["AvailableResource", "AsyncAvailableResource"] |
| 22 | + |
| 23 | + |
| 24 | +class AvailableResource(SyncAPIResource): |
| 25 | + @cached_property |
| 26 | + def with_raw_response(self) -> AvailableResourceWithRawResponse: |
| 27 | + """ |
| 28 | + This property can be used as a prefix for any HTTP method call to return |
| 29 | + the raw response object instead of the parsed content. |
| 30 | +
|
| 31 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 32 | + """ |
| 33 | + return AvailableResourceWithRawResponse(self) |
| 34 | + |
| 35 | + @cached_property |
| 36 | + def with_streaming_response(self) -> AvailableResourceWithStreamingResponse: |
| 37 | + """ |
| 38 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 39 | +
|
| 40 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 41 | + """ |
| 42 | + return AvailableResourceWithStreamingResponse(self) |
| 43 | + |
| 44 | + def list( |
| 45 | + self, |
| 46 | + *, |
| 47 | + account_id: str | Omit = omit, |
| 48 | + zone_id: str | Omit = omit, |
| 49 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 50 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 51 | + extra_headers: Headers | None = None, |
| 52 | + extra_query: Query | None = None, |
| 53 | + extra_body: Body | None = None, |
| 54 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 55 | + ) -> SyncSinglePage[AvailableDataset]: |
| 56 | + """Returns all dataset types that this account or zone can create. |
| 57 | +
|
| 58 | + Each entry |
| 59 | + includes the dataset schema and timestamp field. |
| 60 | +
|
| 61 | + The schema shows all possible fields for a dataset. However, not all fields may |
| 62 | + be available for your account or zone. When creating or updating a dataset, only |
| 63 | + fields available to your account or zone can be enabled. If you request a field |
| 64 | + that is not available, you will receive an error. |
| 65 | +
|
| 66 | + Args: |
| 67 | + account_id: The Account ID to use for this endpoint. Mutually exclusive with the Zone ID. |
| 68 | +
|
| 69 | + zone_id: The Zone ID to use for this endpoint. Mutually exclusive with the Account ID. |
| 70 | +
|
| 71 | + extra_headers: Send extra headers |
| 72 | +
|
| 73 | + extra_query: Add additional query parameters to the request |
| 74 | +
|
| 75 | + extra_body: Add additional JSON properties to the request |
| 76 | +
|
| 77 | + timeout: Override the client-level default timeout for this request, in seconds |
| 78 | + """ |
| 79 | + if account_id and zone_id: |
| 80 | + raise ValueError("You cannot provide both account_id and zone_id") |
| 81 | + |
| 82 | + if account_id: |
| 83 | + account_or_zone = "accounts" |
| 84 | + account_or_zone_id = account_id |
| 85 | + else: |
| 86 | + if not zone_id: |
| 87 | + raise ValueError("You must provide either account_id or zone_id") |
| 88 | + |
| 89 | + account_or_zone = "zones" |
| 90 | + account_or_zone_id = zone_id |
| 91 | + return self._get_api_list( |
| 92 | + path_template( |
| 93 | + "/{account_or_zone}/{account_or_zone_id}/logs/explorer/datasets/available", |
| 94 | + account_or_zone=account_or_zone, |
| 95 | + account_or_zone_id=account_or_zone_id, |
| 96 | + ), |
| 97 | + page=SyncSinglePage[AvailableDataset], |
| 98 | + options=make_request_options( |
| 99 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 100 | + ), |
| 101 | + model=AvailableDataset, |
| 102 | + ) |
| 103 | + |
| 104 | + |
| 105 | +class AsyncAvailableResource(AsyncAPIResource): |
| 106 | + @cached_property |
| 107 | + def with_raw_response(self) -> AsyncAvailableResourceWithRawResponse: |
| 108 | + """ |
| 109 | + This property can be used as a prefix for any HTTP method call to return |
| 110 | + the raw response object instead of the parsed content. |
| 111 | +
|
| 112 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 113 | + """ |
| 114 | + return AsyncAvailableResourceWithRawResponse(self) |
| 115 | + |
| 116 | + @cached_property |
| 117 | + def with_streaming_response(self) -> AsyncAvailableResourceWithStreamingResponse: |
| 118 | + """ |
| 119 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 120 | +
|
| 121 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 122 | + """ |
| 123 | + return AsyncAvailableResourceWithStreamingResponse(self) |
| 124 | + |
| 125 | + def list( |
| 126 | + self, |
| 127 | + *, |
| 128 | + account_id: str | Omit = omit, |
| 129 | + zone_id: str | Omit = omit, |
| 130 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 131 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 132 | + extra_headers: Headers | None = None, |
| 133 | + extra_query: Query | None = None, |
| 134 | + extra_body: Body | None = None, |
| 135 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 136 | + ) -> AsyncPaginator[AvailableDataset, AsyncSinglePage[AvailableDataset]]: |
| 137 | + """Returns all dataset types that this account or zone can create. |
| 138 | +
|
| 139 | + Each entry |
| 140 | + includes the dataset schema and timestamp field. |
| 141 | +
|
| 142 | + The schema shows all possible fields for a dataset. However, not all fields may |
| 143 | + be available for your account or zone. When creating or updating a dataset, only |
| 144 | + fields available to your account or zone can be enabled. If you request a field |
| 145 | + that is not available, you will receive an error. |
| 146 | +
|
| 147 | + Args: |
| 148 | + account_id: The Account ID to use for this endpoint. Mutually exclusive with the Zone ID. |
| 149 | +
|
| 150 | + zone_id: The Zone ID to use for this endpoint. Mutually exclusive with the Account ID. |
| 151 | +
|
| 152 | + extra_headers: Send extra headers |
| 153 | +
|
| 154 | + extra_query: Add additional query parameters to the request |
| 155 | +
|
| 156 | + extra_body: Add additional JSON properties to the request |
| 157 | +
|
| 158 | + timeout: Override the client-level default timeout for this request, in seconds |
| 159 | + """ |
| 160 | + if account_id and zone_id: |
| 161 | + raise ValueError("You cannot provide both account_id and zone_id") |
| 162 | + |
| 163 | + if account_id: |
| 164 | + account_or_zone = "accounts" |
| 165 | + account_or_zone_id = account_id |
| 166 | + else: |
| 167 | + if not zone_id: |
| 168 | + raise ValueError("You must provide either account_id or zone_id") |
| 169 | + |
| 170 | + account_or_zone = "zones" |
| 171 | + account_or_zone_id = zone_id |
| 172 | + return self._get_api_list( |
| 173 | + path_template( |
| 174 | + "/{account_or_zone}/{account_or_zone_id}/logs/explorer/datasets/available", |
| 175 | + account_or_zone=account_or_zone, |
| 176 | + account_or_zone_id=account_or_zone_id, |
| 177 | + ), |
| 178 | + page=AsyncSinglePage[AvailableDataset], |
| 179 | + options=make_request_options( |
| 180 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 181 | + ), |
| 182 | + model=AvailableDataset, |
| 183 | + ) |
| 184 | + |
| 185 | + |
| 186 | +class AvailableResourceWithRawResponse: |
| 187 | + def __init__(self, available: AvailableResource) -> None: |
| 188 | + self._available = available |
| 189 | + |
| 190 | + self.list = to_raw_response_wrapper( |
| 191 | + available.list, |
| 192 | + ) |
| 193 | + |
| 194 | + |
| 195 | +class AsyncAvailableResourceWithRawResponse: |
| 196 | + def __init__(self, available: AsyncAvailableResource) -> None: |
| 197 | + self._available = available |
| 198 | + |
| 199 | + self.list = async_to_raw_response_wrapper( |
| 200 | + available.list, |
| 201 | + ) |
| 202 | + |
| 203 | + |
| 204 | +class AvailableResourceWithStreamingResponse: |
| 205 | + def __init__(self, available: AvailableResource) -> None: |
| 206 | + self._available = available |
| 207 | + |
| 208 | + self.list = to_streamed_response_wrapper( |
| 209 | + available.list, |
| 210 | + ) |
| 211 | + |
| 212 | + |
| 213 | +class AsyncAvailableResourceWithStreamingResponse: |
| 214 | + def __init__(self, available: AsyncAvailableResource) -> None: |
| 215 | + self._available = available |
| 216 | + |
| 217 | + self.list = async_to_streamed_response_wrapper( |
| 218 | + available.list, |
| 219 | + ) |
0 commit comments