|
| 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 Any, 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 ..types.ips import ip_list_params |
| 21 | +from .._base_client import make_request_options |
| 22 | +from ..types.ips.ip_list_response import IPListResponse |
| 23 | + |
| 24 | +__all__ = ["IPsResource", "AsyncIPsResource"] |
| 25 | + |
| 26 | + |
| 27 | +class IPsResource(SyncAPIResource): |
| 28 | + @cached_property |
| 29 | + def with_raw_response(self) -> IPsResourceWithRawResponse: |
| 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/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 35 | + """ |
| 36 | + return IPsResourceWithRawResponse(self) |
| 37 | + |
| 38 | + @cached_property |
| 39 | + def with_streaming_response(self) -> IPsResourceWithStreamingResponse: |
| 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/cloudflare/cloudflare-python#with_streaming_response |
| 44 | + """ |
| 45 | + return IPsResourceWithStreamingResponse(self) |
| 46 | + |
| 47 | + def list( |
| 48 | + self, |
| 49 | + *, |
| 50 | + networks: str | NotGiven = NOT_GIVEN, |
| 51 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 52 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 53 | + extra_headers: Headers | None = None, |
| 54 | + extra_query: Query | None = None, |
| 55 | + extra_body: Body | None = None, |
| 56 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 57 | + ) -> Optional[IPListResponse]: |
| 58 | + """ |
| 59 | + Get IPs used on the Cloudflare/JD Cloud network, see |
| 60 | + https://www.cloudflare.com/ips for Cloudflare IPs or |
| 61 | + https://developers.cloudflare.com/china-network/reference/infrastructure/ for JD |
| 62 | + Cloud IPs. |
| 63 | +
|
| 64 | + Args: |
| 65 | + networks: Specified as `jdcloud` to list IPs used by JD Cloud data centers. |
| 66 | +
|
| 67 | + extra_headers: Send extra headers |
| 68 | +
|
| 69 | + extra_query: Add additional query parameters to the request |
| 70 | +
|
| 71 | + extra_body: Add additional JSON properties to the request |
| 72 | +
|
| 73 | + timeout: Override the client-level default timeout for this request, in seconds |
| 74 | + """ |
| 75 | + return cast( |
| 76 | + Optional[IPListResponse], |
| 77 | + self._get( |
| 78 | + "/ips", |
| 79 | + options=make_request_options( |
| 80 | + extra_headers=extra_headers, |
| 81 | + extra_query=extra_query, |
| 82 | + extra_body=extra_body, |
| 83 | + timeout=timeout, |
| 84 | + query=maybe_transform({"networks": networks}, ip_list_params.IPListParams), |
| 85 | + post_parser=ResultWrapper[Optional[IPListResponse]]._unwrapper, |
| 86 | + ), |
| 87 | + cast_to=cast( |
| 88 | + Any, ResultWrapper[IPListResponse] |
| 89 | + ), # Union types cannot be passed in as arguments in the type system |
| 90 | + ), |
| 91 | + ) |
| 92 | + |
| 93 | + |
| 94 | +class AsyncIPsResource(AsyncAPIResource): |
| 95 | + @cached_property |
| 96 | + def with_raw_response(self) -> AsyncIPsResourceWithRawResponse: |
| 97 | + """ |
| 98 | + This property can be used as a prefix for any HTTP method call to return |
| 99 | + the raw response object instead of the parsed content. |
| 100 | +
|
| 101 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 102 | + """ |
| 103 | + return AsyncIPsResourceWithRawResponse(self) |
| 104 | + |
| 105 | + @cached_property |
| 106 | + def with_streaming_response(self) -> AsyncIPsResourceWithStreamingResponse: |
| 107 | + """ |
| 108 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 109 | +
|
| 110 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 111 | + """ |
| 112 | + return AsyncIPsResourceWithStreamingResponse(self) |
| 113 | + |
| 114 | + async def list( |
| 115 | + self, |
| 116 | + *, |
| 117 | + networks: str | NotGiven = NOT_GIVEN, |
| 118 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 119 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 120 | + extra_headers: Headers | None = None, |
| 121 | + extra_query: Query | None = None, |
| 122 | + extra_body: Body | None = None, |
| 123 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 124 | + ) -> Optional[IPListResponse]: |
| 125 | + """ |
| 126 | + Get IPs used on the Cloudflare/JD Cloud network, see |
| 127 | + https://www.cloudflare.com/ips for Cloudflare IPs or |
| 128 | + https://developers.cloudflare.com/china-network/reference/infrastructure/ for JD |
| 129 | + Cloud IPs. |
| 130 | +
|
| 131 | + Args: |
| 132 | + networks: Specified as `jdcloud` to list IPs used by JD Cloud data centers. |
| 133 | +
|
| 134 | + extra_headers: Send extra headers |
| 135 | +
|
| 136 | + extra_query: Add additional query parameters to the request |
| 137 | +
|
| 138 | + extra_body: Add additional JSON properties to the request |
| 139 | +
|
| 140 | + timeout: Override the client-level default timeout for this request, in seconds |
| 141 | + """ |
| 142 | + return cast( |
| 143 | + Optional[IPListResponse], |
| 144 | + await self._get( |
| 145 | + "/ips", |
| 146 | + options=make_request_options( |
| 147 | + extra_headers=extra_headers, |
| 148 | + extra_query=extra_query, |
| 149 | + extra_body=extra_body, |
| 150 | + timeout=timeout, |
| 151 | + query=await async_maybe_transform({"networks": networks}, ip_list_params.IPListParams), |
| 152 | + post_parser=ResultWrapper[Optional[IPListResponse]]._unwrapper, |
| 153 | + ), |
| 154 | + cast_to=cast( |
| 155 | + Any, ResultWrapper[IPListResponse] |
| 156 | + ), # Union types cannot be passed in as arguments in the type system |
| 157 | + ), |
| 158 | + ) |
| 159 | + |
| 160 | + |
| 161 | +class IPsResourceWithRawResponse: |
| 162 | + def __init__(self, ips: IPsResource) -> None: |
| 163 | + self._ips = ips |
| 164 | + |
| 165 | + self.list = to_raw_response_wrapper( |
| 166 | + ips.list, |
| 167 | + ) |
| 168 | + |
| 169 | + |
| 170 | +class AsyncIPsResourceWithRawResponse: |
| 171 | + def __init__(self, ips: AsyncIPsResource) -> None: |
| 172 | + self._ips = ips |
| 173 | + |
| 174 | + self.list = async_to_raw_response_wrapper( |
| 175 | + ips.list, |
| 176 | + ) |
| 177 | + |
| 178 | + |
| 179 | +class IPsResourceWithStreamingResponse: |
| 180 | + def __init__(self, ips: IPsResource) -> None: |
| 181 | + self._ips = ips |
| 182 | + |
| 183 | + self.list = to_streamed_response_wrapper( |
| 184 | + ips.list, |
| 185 | + ) |
| 186 | + |
| 187 | + |
| 188 | +class AsyncIPsResourceWithStreamingResponse: |
| 189 | + def __init__(self, ips: AsyncIPsResource) -> None: |
| 190 | + self._ips = ips |
| 191 | + |
| 192 | + self.list = async_to_streamed_response_wrapper( |
| 193 | + ips.list, |
| 194 | + ) |
0 commit comments