|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Type, Optional, cast |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 10 | +from ..._utils import maybe_transform, async_maybe_transform |
| 11 | +from ..._compat import cached_property |
| 12 | +from ..._resource import SyncAPIResource, AsyncAPIResource |
| 13 | +from ..._response import ( |
| 14 | + to_raw_response_wrapper, |
| 15 | + to_streamed_response_wrapper, |
| 16 | + async_to_raw_response_wrapper, |
| 17 | + async_to_streamed_response_wrapper, |
| 18 | +) |
| 19 | +from ..._wrappers import ResultWrapper |
| 20 | +from ...pagination import SyncSinglePage, AsyncSinglePage |
| 21 | +from ..._base_client import AsyncPaginator, make_request_options |
| 22 | +from ...types.logpush import edge_create_params |
| 23 | +from ...types.logpush.instant_logpush_job import InstantLogpushJob |
| 24 | + |
| 25 | +__all__ = ["EdgeResource", "AsyncEdgeResource"] |
| 26 | + |
| 27 | + |
| 28 | +class EdgeResource(SyncAPIResource): |
| 29 | + @cached_property |
| 30 | + def with_raw_response(self) -> EdgeResourceWithRawResponse: |
| 31 | + """ |
| 32 | + This property can be used as a prefix for any HTTP method call to return |
| 33 | + the raw response object instead of the parsed content. |
| 34 | +
|
| 35 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 36 | + """ |
| 37 | + return EdgeResourceWithRawResponse(self) |
| 38 | + |
| 39 | + @cached_property |
| 40 | + def with_streaming_response(self) -> EdgeResourceWithStreamingResponse: |
| 41 | + """ |
| 42 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 43 | +
|
| 44 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 45 | + """ |
| 46 | + return EdgeResourceWithStreamingResponse(self) |
| 47 | + |
| 48 | + def create( |
| 49 | + self, |
| 50 | + *, |
| 51 | + zone_id: str, |
| 52 | + fields: str | NotGiven = NOT_GIVEN, |
| 53 | + filter: str | NotGiven = NOT_GIVEN, |
| 54 | + sample: int | NotGiven = NOT_GIVEN, |
| 55 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 56 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 57 | + extra_headers: Headers | None = None, |
| 58 | + extra_query: Query | None = None, |
| 59 | + extra_body: Body | None = None, |
| 60 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 61 | + ) -> Optional[InstantLogpushJob]: |
| 62 | + """ |
| 63 | + Creates a new Instant Logs job for a zone. |
| 64 | +
|
| 65 | + Args: |
| 66 | + zone_id: Identifier. |
| 67 | +
|
| 68 | + fields: Comma-separated list of fields. |
| 69 | +
|
| 70 | + filter: Filters to drill down into specific events. |
| 71 | +
|
| 72 | + sample: |
| 73 | + The sample parameter is the sample rate of the records set by the client: |
| 74 | + "sample": 1 is 100% of records "sample": 10 is 10% and so on. |
| 75 | +
|
| 76 | + extra_headers: Send extra headers |
| 77 | +
|
| 78 | + extra_query: Add additional query parameters to the request |
| 79 | +
|
| 80 | + extra_body: Add additional JSON properties to the request |
| 81 | +
|
| 82 | + timeout: Override the client-level default timeout for this request, in seconds |
| 83 | + """ |
| 84 | + if not zone_id: |
| 85 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 86 | + return self._post( |
| 87 | + f"/zones/{zone_id}/logpush/edge", |
| 88 | + body=maybe_transform( |
| 89 | + { |
| 90 | + "fields": fields, |
| 91 | + "filter": filter, |
| 92 | + "sample": sample, |
| 93 | + }, |
| 94 | + edge_create_params.EdgeCreateParams, |
| 95 | + ), |
| 96 | + options=make_request_options( |
| 97 | + extra_headers=extra_headers, |
| 98 | + extra_query=extra_query, |
| 99 | + extra_body=extra_body, |
| 100 | + timeout=timeout, |
| 101 | + post_parser=ResultWrapper[Optional[InstantLogpushJob]]._unwrapper, |
| 102 | + ), |
| 103 | + cast_to=cast(Type[Optional[InstantLogpushJob]], ResultWrapper[InstantLogpushJob]), |
| 104 | + ) |
| 105 | + |
| 106 | + def get( |
| 107 | + self, |
| 108 | + *, |
| 109 | + zone_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 | + ) -> SyncSinglePage[Optional[InstantLogpushJob]]: |
| 117 | + """ |
| 118 | + Lists Instant Logs jobs for a zone. |
| 119 | +
|
| 120 | + Args: |
| 121 | + zone_id: Identifier. |
| 122 | +
|
| 123 | + extra_headers: Send extra headers |
| 124 | +
|
| 125 | + extra_query: Add additional query parameters to the request |
| 126 | +
|
| 127 | + extra_body: Add additional JSON properties to the request |
| 128 | +
|
| 129 | + timeout: Override the client-level default timeout for this request, in seconds |
| 130 | + """ |
| 131 | + if not zone_id: |
| 132 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 133 | + return self._get_api_list( |
| 134 | + f"/zones/{zone_id}/logpush/edge", |
| 135 | + page=SyncSinglePage[Optional[InstantLogpushJob]], |
| 136 | + options=make_request_options( |
| 137 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 138 | + ), |
| 139 | + model=InstantLogpushJob, |
| 140 | + ) |
| 141 | + |
| 142 | + |
| 143 | +class AsyncEdgeResource(AsyncAPIResource): |
| 144 | + @cached_property |
| 145 | + def with_raw_response(self) -> AsyncEdgeResourceWithRawResponse: |
| 146 | + """ |
| 147 | + This property can be used as a prefix for any HTTP method call to return |
| 148 | + the raw response object instead of the parsed content. |
| 149 | +
|
| 150 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 151 | + """ |
| 152 | + return AsyncEdgeResourceWithRawResponse(self) |
| 153 | + |
| 154 | + @cached_property |
| 155 | + def with_streaming_response(self) -> AsyncEdgeResourceWithStreamingResponse: |
| 156 | + """ |
| 157 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 158 | +
|
| 159 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 160 | + """ |
| 161 | + return AsyncEdgeResourceWithStreamingResponse(self) |
| 162 | + |
| 163 | + async def create( |
| 164 | + self, |
| 165 | + *, |
| 166 | + zone_id: str, |
| 167 | + fields: str | NotGiven = NOT_GIVEN, |
| 168 | + filter: str | NotGiven = NOT_GIVEN, |
| 169 | + sample: int | NotGiven = NOT_GIVEN, |
| 170 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 171 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 172 | + extra_headers: Headers | None = None, |
| 173 | + extra_query: Query | None = None, |
| 174 | + extra_body: Body | None = None, |
| 175 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 176 | + ) -> Optional[InstantLogpushJob]: |
| 177 | + """ |
| 178 | + Creates a new Instant Logs job for a zone. |
| 179 | +
|
| 180 | + Args: |
| 181 | + zone_id: Identifier. |
| 182 | +
|
| 183 | + fields: Comma-separated list of fields. |
| 184 | +
|
| 185 | + filter: Filters to drill down into specific events. |
| 186 | +
|
| 187 | + sample: |
| 188 | + The sample parameter is the sample rate of the records set by the client: |
| 189 | + "sample": 1 is 100% of records "sample": 10 is 10% and so on. |
| 190 | +
|
| 191 | + extra_headers: Send extra headers |
| 192 | +
|
| 193 | + extra_query: Add additional query parameters to the request |
| 194 | +
|
| 195 | + extra_body: Add additional JSON properties to the request |
| 196 | +
|
| 197 | + timeout: Override the client-level default timeout for this request, in seconds |
| 198 | + """ |
| 199 | + if not zone_id: |
| 200 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 201 | + return await self._post( |
| 202 | + f"/zones/{zone_id}/logpush/edge", |
| 203 | + body=await async_maybe_transform( |
| 204 | + { |
| 205 | + "fields": fields, |
| 206 | + "filter": filter, |
| 207 | + "sample": sample, |
| 208 | + }, |
| 209 | + edge_create_params.EdgeCreateParams, |
| 210 | + ), |
| 211 | + options=make_request_options( |
| 212 | + extra_headers=extra_headers, |
| 213 | + extra_query=extra_query, |
| 214 | + extra_body=extra_body, |
| 215 | + timeout=timeout, |
| 216 | + post_parser=ResultWrapper[Optional[InstantLogpushJob]]._unwrapper, |
| 217 | + ), |
| 218 | + cast_to=cast(Type[Optional[InstantLogpushJob]], ResultWrapper[InstantLogpushJob]), |
| 219 | + ) |
| 220 | + |
| 221 | + def get( |
| 222 | + self, |
| 223 | + *, |
| 224 | + zone_id: str, |
| 225 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 226 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 227 | + extra_headers: Headers | None = None, |
| 228 | + extra_query: Query | None = None, |
| 229 | + extra_body: Body | None = None, |
| 230 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 231 | + ) -> AsyncPaginator[Optional[InstantLogpushJob], AsyncSinglePage[Optional[InstantLogpushJob]]]: |
| 232 | + """ |
| 233 | + Lists Instant Logs jobs for a zone. |
| 234 | +
|
| 235 | + Args: |
| 236 | + zone_id: Identifier. |
| 237 | +
|
| 238 | + extra_headers: Send extra headers |
| 239 | +
|
| 240 | + extra_query: Add additional query parameters to the request |
| 241 | +
|
| 242 | + extra_body: Add additional JSON properties to the request |
| 243 | +
|
| 244 | + timeout: Override the client-level default timeout for this request, in seconds |
| 245 | + """ |
| 246 | + if not zone_id: |
| 247 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 248 | + return self._get_api_list( |
| 249 | + f"/zones/{zone_id}/logpush/edge", |
| 250 | + page=AsyncSinglePage[Optional[InstantLogpushJob]], |
| 251 | + options=make_request_options( |
| 252 | + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout |
| 253 | + ), |
| 254 | + model=InstantLogpushJob, |
| 255 | + ) |
| 256 | + |
| 257 | + |
| 258 | +class EdgeResourceWithRawResponse: |
| 259 | + def __init__(self, edge: EdgeResource) -> None: |
| 260 | + self._edge = edge |
| 261 | + |
| 262 | + self.create = to_raw_response_wrapper( |
| 263 | + edge.create, |
| 264 | + ) |
| 265 | + self.get = to_raw_response_wrapper( |
| 266 | + edge.get, |
| 267 | + ) |
| 268 | + |
| 269 | + |
| 270 | +class AsyncEdgeResourceWithRawResponse: |
| 271 | + def __init__(self, edge: AsyncEdgeResource) -> None: |
| 272 | + self._edge = edge |
| 273 | + |
| 274 | + self.create = async_to_raw_response_wrapper( |
| 275 | + edge.create, |
| 276 | + ) |
| 277 | + self.get = async_to_raw_response_wrapper( |
| 278 | + edge.get, |
| 279 | + ) |
| 280 | + |
| 281 | + |
| 282 | +class EdgeResourceWithStreamingResponse: |
| 283 | + def __init__(self, edge: EdgeResource) -> None: |
| 284 | + self._edge = edge |
| 285 | + |
| 286 | + self.create = to_streamed_response_wrapper( |
| 287 | + edge.create, |
| 288 | + ) |
| 289 | + self.get = to_streamed_response_wrapper( |
| 290 | + edge.get, |
| 291 | + ) |
| 292 | + |
| 293 | + |
| 294 | +class AsyncEdgeResourceWithStreamingResponse: |
| 295 | + def __init__(self, edge: AsyncEdgeResource) -> None: |
| 296 | + self._edge = edge |
| 297 | + |
| 298 | + self.create = async_to_streamed_response_wrapper( |
| 299 | + edge.create, |
| 300 | + ) |
| 301 | + self.get = async_to_streamed_response_wrapper( |
| 302 | + edge.get, |
| 303 | + ) |
0 commit comments