|
| 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 Body, Query, Headers, NotGiven, not_given |
| 10 | +from ...._utils import path_template |
| 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 ...._base_client import make_request_options |
| 21 | +from ....types.dns.usage.account_get_response import AccountGetResponse |
| 22 | + |
| 23 | +__all__ = ["AccountResource", "AsyncAccountResource"] |
| 24 | + |
| 25 | + |
| 26 | +class AccountResource(SyncAPIResource): |
| 27 | + @cached_property |
| 28 | + def with_raw_response(self) -> AccountResourceWithRawResponse: |
| 29 | + """ |
| 30 | + This property can be used as a prefix for any HTTP method call to return |
| 31 | + the raw response object instead of the parsed content. |
| 32 | +
|
| 33 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 34 | + """ |
| 35 | + return AccountResourceWithRawResponse(self) |
| 36 | + |
| 37 | + @cached_property |
| 38 | + def with_streaming_response(self) -> AccountResourceWithStreamingResponse: |
| 39 | + """ |
| 40 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 41 | +
|
| 42 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 43 | + """ |
| 44 | + return AccountResourceWithStreamingResponse(self) |
| 45 | + |
| 46 | + def get( |
| 47 | + self, |
| 48 | + *, |
| 49 | + account_id: str, |
| 50 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 51 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 52 | + extra_headers: Headers | None = None, |
| 53 | + extra_query: Query | None = None, |
| 54 | + extra_body: Body | None = None, |
| 55 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 56 | + ) -> Optional[AccountGetResponse]: |
| 57 | + """Get the current DNS record usage and quota for an account. |
| 58 | +
|
| 59 | + May include internal |
| 60 | + DNS usage and quota. |
| 61 | +
|
| 62 | + Args: |
| 63 | + account_id: Identifier. |
| 64 | +
|
| 65 | + extra_headers: Send extra headers |
| 66 | +
|
| 67 | + extra_query: Add additional query parameters to the request |
| 68 | +
|
| 69 | + extra_body: Add additional JSON properties to the request |
| 70 | +
|
| 71 | + timeout: Override the client-level default timeout for this request, in seconds |
| 72 | + """ |
| 73 | + if not account_id: |
| 74 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 75 | + return self._get( |
| 76 | + path_template("/accounts/{account_id}/dns_records/usage", account_id=account_id), |
| 77 | + options=make_request_options( |
| 78 | + extra_headers=extra_headers, |
| 79 | + extra_query=extra_query, |
| 80 | + extra_body=extra_body, |
| 81 | + timeout=timeout, |
| 82 | + post_parser=ResultWrapper[Optional[AccountGetResponse]]._unwrapper, |
| 83 | + ), |
| 84 | + cast_to=cast(Type[Optional[AccountGetResponse]], ResultWrapper[AccountGetResponse]), |
| 85 | + ) |
| 86 | + |
| 87 | + |
| 88 | +class AsyncAccountResource(AsyncAPIResource): |
| 89 | + @cached_property |
| 90 | + def with_raw_response(self) -> AsyncAccountResourceWithRawResponse: |
| 91 | + """ |
| 92 | + This property can be used as a prefix for any HTTP method call to return |
| 93 | + the raw response object instead of the parsed content. |
| 94 | +
|
| 95 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 96 | + """ |
| 97 | + return AsyncAccountResourceWithRawResponse(self) |
| 98 | + |
| 99 | + @cached_property |
| 100 | + def with_streaming_response(self) -> AsyncAccountResourceWithStreamingResponse: |
| 101 | + """ |
| 102 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 103 | +
|
| 104 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 105 | + """ |
| 106 | + return AsyncAccountResourceWithStreamingResponse(self) |
| 107 | + |
| 108 | + async def get( |
| 109 | + self, |
| 110 | + *, |
| 111 | + account_id: str, |
| 112 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 113 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 114 | + extra_headers: Headers | None = None, |
| 115 | + extra_query: Query | None = None, |
| 116 | + extra_body: Body | None = None, |
| 117 | + timeout: float | httpx.Timeout | None | NotGiven = not_given, |
| 118 | + ) -> Optional[AccountGetResponse]: |
| 119 | + """Get the current DNS record usage and quota for an account. |
| 120 | +
|
| 121 | + May include internal |
| 122 | + DNS usage and quota. |
| 123 | +
|
| 124 | + Args: |
| 125 | + account_id: Identifier. |
| 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 | + return await self._get( |
| 138 | + path_template("/accounts/{account_id}/dns_records/usage", account_id=account_id), |
| 139 | + options=make_request_options( |
| 140 | + extra_headers=extra_headers, |
| 141 | + extra_query=extra_query, |
| 142 | + extra_body=extra_body, |
| 143 | + timeout=timeout, |
| 144 | + post_parser=ResultWrapper[Optional[AccountGetResponse]]._unwrapper, |
| 145 | + ), |
| 146 | + cast_to=cast(Type[Optional[AccountGetResponse]], ResultWrapper[AccountGetResponse]), |
| 147 | + ) |
| 148 | + |
| 149 | + |
| 150 | +class AccountResourceWithRawResponse: |
| 151 | + def __init__(self, account: AccountResource) -> None: |
| 152 | + self._account = account |
| 153 | + |
| 154 | + self.get = to_raw_response_wrapper( |
| 155 | + account.get, |
| 156 | + ) |
| 157 | + |
| 158 | + |
| 159 | +class AsyncAccountResourceWithRawResponse: |
| 160 | + def __init__(self, account: AsyncAccountResource) -> None: |
| 161 | + self._account = account |
| 162 | + |
| 163 | + self.get = async_to_raw_response_wrapper( |
| 164 | + account.get, |
| 165 | + ) |
| 166 | + |
| 167 | + |
| 168 | +class AccountResourceWithStreamingResponse: |
| 169 | + def __init__(self, account: AccountResource) -> None: |
| 170 | + self._account = account |
| 171 | + |
| 172 | + self.get = to_streamed_response_wrapper( |
| 173 | + account.get, |
| 174 | + ) |
| 175 | + |
| 176 | + |
| 177 | +class AsyncAccountResourceWithStreamingResponse: |
| 178 | + def __init__(self, account: AsyncAccountResource) -> None: |
| 179 | + self._account = account |
| 180 | + |
| 181 | + self.get = async_to_streamed_response_wrapper( |
| 182 | + account.get, |
| 183 | + ) |
0 commit comments