|
| 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 ...._utils import ( |
| 9 | + maybe_transform, |
| 10 | + async_maybe_transform, |
| 11 | +) |
| 12 | +from ...._compat import cached_property |
| 13 | +from ...._resource import SyncAPIResource, AsyncAPIResource |
| 14 | +from ...._response import ( |
| 15 | + to_raw_response_wrapper, |
| 16 | + to_streamed_response_wrapper, |
| 17 | + async_to_raw_response_wrapper, |
| 18 | + async_to_streamed_response_wrapper, |
| 19 | +) |
| 20 | +from ...._base_client import make_request_options |
| 21 | +from ....types.zero_trust.devices import fleet_status_get_params |
| 22 | +from ....types.zero_trust.devices.fleet_status_get_response import FleetStatusGetResponse |
| 23 | + |
| 24 | +__all__ = ["FleetStatusResource", "AsyncFleetStatusResource"] |
| 25 | + |
| 26 | + |
| 27 | +class FleetStatusResource(SyncAPIResource): |
| 28 | + @cached_property |
| 29 | + def with_raw_response(self) -> FleetStatusResourceWithRawResponse: |
| 30 | + """ |
| 31 | + This property can be used as a prefix for any HTTP method call to return the |
| 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 FleetStatusResourceWithRawResponse(self) |
| 37 | + |
| 38 | + @cached_property |
| 39 | + def with_streaming_response(self) -> FleetStatusResourceWithStreamingResponse: |
| 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 FleetStatusResourceWithStreamingResponse(self) |
| 46 | + |
| 47 | + def get( |
| 48 | + self, |
| 49 | + device_id: str, |
| 50 | + *, |
| 51 | + account_id: str, |
| 52 | + since_minutes: float, |
| 53 | + colo: str | NotGiven = NOT_GIVEN, |
| 54 | + time_now: str | 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 | + ) -> FleetStatusGetResponse: |
| 62 | + """ |
| 63 | + Get the live status of a latest device given device_id from the device_state |
| 64 | + table |
| 65 | +
|
| 66 | + Args: |
| 67 | + device_id: Device-specific ID, given as UUID v4 |
| 68 | +
|
| 69 | + since_minutes: Number of minutes before current time |
| 70 | +
|
| 71 | + colo: List of data centers to filter results |
| 72 | +
|
| 73 | + time_now: Number of minutes before current time |
| 74 | +
|
| 75 | + extra_headers: Send extra headers |
| 76 | +
|
| 77 | + extra_query: Add additional query parameters to the request |
| 78 | +
|
| 79 | + extra_body: Add additional JSON properties to the request |
| 80 | +
|
| 81 | + timeout: Override the client-level default timeout for this request, in seconds |
| 82 | + """ |
| 83 | + if not account_id: |
| 84 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 85 | + if not device_id: |
| 86 | + raise ValueError(f"Expected a non-empty value for `device_id` but received {device_id!r}") |
| 87 | + return self._get( |
| 88 | + f"/accounts/{account_id}/devices/{device_id}/fleet-status/live", |
| 89 | + options=make_request_options( |
| 90 | + extra_headers=extra_headers, |
| 91 | + extra_query=extra_query, |
| 92 | + extra_body=extra_body, |
| 93 | + timeout=timeout, |
| 94 | + query=maybe_transform( |
| 95 | + { |
| 96 | + "since_minutes": since_minutes, |
| 97 | + "colo": colo, |
| 98 | + "time_now": time_now, |
| 99 | + }, |
| 100 | + fleet_status_get_params.FleetStatusGetParams, |
| 101 | + ), |
| 102 | + ), |
| 103 | + cast_to=FleetStatusGetResponse, |
| 104 | + ) |
| 105 | + |
| 106 | + |
| 107 | +class AsyncFleetStatusResource(AsyncAPIResource): |
| 108 | + @cached_property |
| 109 | + def with_raw_response(self) -> AsyncFleetStatusResourceWithRawResponse: |
| 110 | + """ |
| 111 | + This property can be used as a prefix for any HTTP method call to return the |
| 112 | + the raw response object instead of the parsed content. |
| 113 | +
|
| 114 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 115 | + """ |
| 116 | + return AsyncFleetStatusResourceWithRawResponse(self) |
| 117 | + |
| 118 | + @cached_property |
| 119 | + def with_streaming_response(self) -> AsyncFleetStatusResourceWithStreamingResponse: |
| 120 | + """ |
| 121 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 122 | +
|
| 123 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 124 | + """ |
| 125 | + return AsyncFleetStatusResourceWithStreamingResponse(self) |
| 126 | + |
| 127 | + async def get( |
| 128 | + self, |
| 129 | + device_id: str, |
| 130 | + *, |
| 131 | + account_id: str, |
| 132 | + since_minutes: float, |
| 133 | + colo: str | NotGiven = NOT_GIVEN, |
| 134 | + time_now: str | NotGiven = NOT_GIVEN, |
| 135 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 136 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 137 | + extra_headers: Headers | None = None, |
| 138 | + extra_query: Query | None = None, |
| 139 | + extra_body: Body | None = None, |
| 140 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 141 | + ) -> FleetStatusGetResponse: |
| 142 | + """ |
| 143 | + Get the live status of a latest device given device_id from the device_state |
| 144 | + table |
| 145 | +
|
| 146 | + Args: |
| 147 | + device_id: Device-specific ID, given as UUID v4 |
| 148 | +
|
| 149 | + since_minutes: Number of minutes before current time |
| 150 | +
|
| 151 | + colo: List of data centers to filter results |
| 152 | +
|
| 153 | + time_now: Number of minutes before current time |
| 154 | +
|
| 155 | + extra_headers: Send extra headers |
| 156 | +
|
| 157 | + extra_query: Add additional query parameters to the request |
| 158 | +
|
| 159 | + extra_body: Add additional JSON properties to the request |
| 160 | +
|
| 161 | + timeout: Override the client-level default timeout for this request, in seconds |
| 162 | + """ |
| 163 | + if not account_id: |
| 164 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 165 | + if not device_id: |
| 166 | + raise ValueError(f"Expected a non-empty value for `device_id` but received {device_id!r}") |
| 167 | + return await self._get( |
| 168 | + f"/accounts/{account_id}/devices/{device_id}/fleet-status/live", |
| 169 | + options=make_request_options( |
| 170 | + extra_headers=extra_headers, |
| 171 | + extra_query=extra_query, |
| 172 | + extra_body=extra_body, |
| 173 | + timeout=timeout, |
| 174 | + query=await async_maybe_transform( |
| 175 | + { |
| 176 | + "since_minutes": since_minutes, |
| 177 | + "colo": colo, |
| 178 | + "time_now": time_now, |
| 179 | + }, |
| 180 | + fleet_status_get_params.FleetStatusGetParams, |
| 181 | + ), |
| 182 | + ), |
| 183 | + cast_to=FleetStatusGetResponse, |
| 184 | + ) |
| 185 | + |
| 186 | + |
| 187 | +class FleetStatusResourceWithRawResponse: |
| 188 | + def __init__(self, fleet_status: FleetStatusResource) -> None: |
| 189 | + self._fleet_status = fleet_status |
| 190 | + |
| 191 | + self.get = to_raw_response_wrapper( |
| 192 | + fleet_status.get, |
| 193 | + ) |
| 194 | + |
| 195 | + |
| 196 | +class AsyncFleetStatusResourceWithRawResponse: |
| 197 | + def __init__(self, fleet_status: AsyncFleetStatusResource) -> None: |
| 198 | + self._fleet_status = fleet_status |
| 199 | + |
| 200 | + self.get = async_to_raw_response_wrapper( |
| 201 | + fleet_status.get, |
| 202 | + ) |
| 203 | + |
| 204 | + |
| 205 | +class FleetStatusResourceWithStreamingResponse: |
| 206 | + def __init__(self, fleet_status: FleetStatusResource) -> None: |
| 207 | + self._fleet_status = fleet_status |
| 208 | + |
| 209 | + self.get = to_streamed_response_wrapper( |
| 210 | + fleet_status.get, |
| 211 | + ) |
| 212 | + |
| 213 | + |
| 214 | +class AsyncFleetStatusResourceWithStreamingResponse: |
| 215 | + def __init__(self, fleet_status: AsyncFleetStatusResource) -> None: |
| 216 | + self._fleet_status = fleet_status |
| 217 | + |
| 218 | + self.get = async_to_streamed_response_wrapper( |
| 219 | + fleet_status.get, |
| 220 | + ) |
0 commit comments