samsara-api 4.1.1__py3-none-any.whl → 4.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- samsara/__init__.py +84 -15
- samsara/addresses/client.py +7 -14
- samsara/addresses/raw_client.py +7 -11
- samsara/alerts/client.py +2 -10
- samsara/alerts/raw_client.py +180 -180
- samsara/assets/__init__.py +3 -3
- samsara/assets/client.py +14 -45
- samsara/assets/raw_client.py +156 -160
- samsara/assets/types/__init__.py +3 -3
- samsara/assets/types/{assets_list_request_type.py → list_assets_request_type.py} +1 -1
- samsara/attributes/client.py +0 -4
- samsara/beta_ap_is/client.py +139 -189
- samsara/beta_ap_is/raw_client.py +2035 -1702
- samsara/carrier_proposed_assignments/client.py +2 -10
- samsara/client.py +5 -0
- samsara/coaching/client.py +2 -22
- samsara/coaching/raw_client.py +108 -108
- samsara/contacts/client.py +2 -8
- samsara/core/__init__.py +5 -0
- samsara/core/client_wrapper.py +18 -10
- samsara/core/custom_pagination.py +152 -0
- samsara/core/http_client.py +176 -90
- samsara/core/http_sse/__init__.py +42 -0
- samsara/core/http_sse/_api.py +112 -0
- samsara/core/http_sse/_decoders.py +61 -0
- samsara/core/http_sse/_exceptions.py +7 -0
- samsara/core/http_sse/_models.py +17 -0
- samsara/core/pagination.py +14 -14
- samsara/core/pydantic_utilities.py +3 -1
- samsara/documents/client.py +2 -12
- samsara/documents/raw_client.py +180 -180
- samsara/driver_qr_codes/raw_client.py +108 -108
- samsara/driver_vehicle_assignments/client.py +0 -12
- samsara/driver_vehicle_assignments/raw_client.py +144 -144
- samsara/drivers/__init__.py +3 -3
- samsara/drivers/client.py +12 -23
- samsara/drivers/raw_client.py +48 -52
- samsara/drivers/types/__init__.py +3 -3
- samsara/drivers/types/{drivers_list_request_driver_activation_status.py → list_drivers_request_driver_activation_status.py} +1 -1
- samsara/equipment/client.py +6 -22
- samsara/errors/bad_gateway_error.py +1 -1
- samsara/errors/gateway_timeout_error.py +1 -1
- samsara/errors/internal_server_error.py +1 -1
- samsara/errors/method_not_allowed_error.py +1 -1
- samsara/errors/not_found_error.py +1 -1
- samsara/errors/not_implemented_error.py +1 -1
- samsara/errors/service_unavailable_error.py +1 -1
- samsara/errors/too_many_requests_error.py +1 -1
- samsara/errors/unauthorized_error.py +1 -1
- samsara/forms/__init__.py +9 -3
- samsara/forms/client.py +17 -10
- samsara/forms/raw_client.py +265 -254
- samsara/forms/types/__init__.py +6 -2
- samsara/forms/types/form_submissions_post_form_submission_request_body_status.py +5 -0
- samsara/fuel_and_energy/client.py +0 -30
- samsara/fuel_and_energy/raw_client.py +180 -180
- samsara/gateways/client.py +2 -6
- samsara/gateways/raw_client.py +108 -108
- samsara/hours_of_service/__init__.py +6 -3
- samsara/hours_of_service/client.py +13 -52
- samsara/hours_of_service/raw_client.py +77 -76
- samsara/hours_of_service/types/__init__.py +4 -2
- samsara/hours_of_service/types/get_hos_daily_logs_request_expand.py +5 -0
- samsara/hubs/client.py +2 -94
- samsara/hubs/raw_client.py +216 -216
- samsara/idling/client.py +10 -16
- samsara/idling/raw_client.py +46 -36
- samsara/ifta/client.py +4 -34
- samsara/ifta/raw_client.py +144 -144
- samsara/industrial/client.py +12 -56
- samsara/industrial/raw_client.py +40 -48
- samsara/issues/client.py +0 -4
- samsara/issues/raw_client.py +108 -108
- samsara/legacy_ap_is/client.py +4 -56
- samsara/legacy_ap_is/raw_client.py +108 -108
- samsara/live_sharing_links/client.py +2 -10
- samsara/live_sharing_links/raw_client.py +144 -144
- samsara/location_and_speed/client.py +2 -20
- samsara/location_and_speed/raw_client.py +36 -36
- samsara/maintenance/__init__.py +3 -3
- samsara/maintenance/client.py +15 -30
- samsara/maintenance/raw_client.py +191 -182
- samsara/maintenance/types/__init__.py +6 -2
- samsara/maintenance/types/create_dvir_request_type.py +5 -0
- samsara/media/client.py +2 -16
- samsara/media/raw_client.py +108 -108
- samsara/messages/client.py +2 -8
- samsara/plans/client.py +0 -21
- samsara/plans/raw_client.py +72 -72
- samsara/preview_ap_is/client.py +0 -140
- samsara/preview_ap_is/raw_client.py +72 -430
- samsara/route_events/client.py +2 -12
- samsara/route_events/raw_client.py +36 -36
- samsara/routes/__init__.py +30 -0
- samsara/routes/client.py +7 -35
- samsara/routes/raw_client.py +257 -256
- samsara/routes/types/__init__.py +34 -0
- samsara/routes/types/get_routes_feed_request_expand.py +5 -0
- samsara/safety/client.py +2 -10
- samsara/safety/raw_client.py +36 -36
- samsara/settings/raw_client.py +180 -180
- samsara/speeding_intervals/raw_client.py +36 -36
- samsara/tachograph_eu_only/client.py +0 -6
- samsara/tags/client.py +2 -8
- samsara/trailer_assignments/client.py +2 -18
- samsara/trailers/client.py +2 -12
- samsara/trailers/raw_client.py +180 -180
- samsara/types/__init__.py +71 -6
- samsara/types/advanced_idling_get_idling_events_response_body.py +2 -2
- samsara/types/create_routes_stop_request_object_request_body.py +7 -0
- samsara/types/driver_assignment_object_response_body.py +2 -1
- samsara/types/driver_assignment_object_response_body_assignment_type.py +5 -0
- samsara/types/driver_external_ids.py +1 -1
- samsara/types/forms_approval_config_object_response_body.py +2 -1
- samsara/types/forms_approval_config_object_response_body_type.py +5 -0
- samsara/types/fuel_level_trigger_details_object_request_body.py +2 -1
- samsara/types/fuel_level_trigger_details_object_request_body_operation.py +5 -0
- samsara/types/fuel_level_trigger_details_object_response_body.py +4 -1
- samsara/types/fuel_level_trigger_details_object_response_body_operation.py +5 -0
- samsara/types/harsh_event_trigger_details_object_request_body_types_item.py +1 -0
- samsara/types/harsh_event_trigger_details_object_response_body_types_item.py +1 -0
- samsara/types/idling_event_address_object_response_body.py +46 -0
- samsara/types/{idling_event_object_response_body_address_type.py → idling_event_address_object_response_body_address_types_item.py} +1 -1
- samsara/types/idling_event_asset_object_response_body.py +35 -0
- samsara/types/{idling_event_object_response_body.py → idling_event_object_v_20251023_response_body.py} +18 -28
- samsara/types/idling_event_object_v_20251023_response_body_pto_state.py +5 -0
- samsara/types/idling_event_operator_object_response_body.py +35 -0
- samsara/types/patch_issue_request_body_assigned_to_request_body.py +2 -1
- samsara/types/patch_issue_request_body_assigned_to_request_body_type.py +5 -0
- samsara/types/reading_datapoint_request_body.py +5 -4
- samsara/types/reading_datapoint_request_body_entity_type.py +5 -0
- samsara/types/reading_history_response_body.py +1 -1
- samsara/types/reading_snapshot_response_body.py +1 -1
- samsara/types/resolved_by.py +2 -1
- samsara/types/resolved_by_type.py +5 -0
- samsara/types/route_feed_object_response_body.py +2 -1
- samsara/types/route_feed_object_response_body_type.py +5 -0
- samsara/types/route_settings_request_body.py +8 -0
- samsara/types/route_settings_request_body_sequencing_method.py +7 -0
- samsara/types/route_settings_response_body.py +8 -0
- samsara/types/route_settings_response_body_sequencing_method.py +7 -0
- samsara/types/route_stop_details_object_response_body.py +2 -1
- samsara/types/route_stop_details_object_response_body_type.py +5 -0
- samsara/types/routes_stop_response_object_response_body.py +7 -0
- samsara/types/training_learner_object_response_body.py +2 -1
- samsara/types/training_learner_object_response_body_type.py +5 -0
- samsara/types/update_routes_stop_request_object_request_body.py +7 -0
- samsara/types/vehicle_assignment_object_response_body.py +4 -3
- samsara/types/vehicle_assignment_object_response_body_assignment_type.py +5 -0
- samsara/types/vehicle_external_ids.py +1 -1
- samsara/types/work_order_money_object_request_body.py +2 -1
- samsara/types/work_order_money_object_request_body_currency.py +5 -0
- samsara/types/work_order_money_object_response_body.py +2 -1
- samsara/types/work_order_money_object_response_body_currency.py +5 -0
- samsara/users/client.py +4 -16
- samsara/vehicle_locations/client.py +4 -16
- samsara/vehicles/client.py +7 -22
- samsara/vehicles/raw_client.py +43 -47
- samsara/webhooks/client.py +2 -10
- samsara/webhooks/raw_client.py +180 -180
- samsara/work_orders/client.py +4 -18
- samsara/work_orders/raw_client.py +216 -216
- {samsara_api-4.1.1.dist-info → samsara_api-4.3.0.dist-info}/METADATA +2 -1
- {samsara_api-4.1.1.dist-info → samsara_api-4.3.0.dist-info}/RECORD +166 -136
- {samsara_api-4.1.1.dist-info → samsara_api-4.3.0.dist-info}/LICENSE +0 -0
- {samsara_api-4.1.1.dist-info → samsara_api-4.3.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
# isort: skip_file
|
|
4
|
+
|
|
5
|
+
import typing
|
|
6
|
+
from importlib import import_module
|
|
7
|
+
|
|
8
|
+
if typing.TYPE_CHECKING:
|
|
9
|
+
from ._api import EventSource, aconnect_sse, connect_sse
|
|
10
|
+
from ._exceptions import SSEError
|
|
11
|
+
from ._models import ServerSentEvent
|
|
12
|
+
_dynamic_imports: typing.Dict[str, str] = {
|
|
13
|
+
"EventSource": "._api",
|
|
14
|
+
"SSEError": "._exceptions",
|
|
15
|
+
"ServerSentEvent": "._models",
|
|
16
|
+
"aconnect_sse": "._api",
|
|
17
|
+
"connect_sse": "._api",
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def __getattr__(attr_name: str) -> typing.Any:
|
|
22
|
+
module_name = _dynamic_imports.get(attr_name)
|
|
23
|
+
if module_name is None:
|
|
24
|
+
raise AttributeError(f"No {attr_name} found in _dynamic_imports for module name -> {__name__}")
|
|
25
|
+
try:
|
|
26
|
+
module = import_module(module_name, __package__)
|
|
27
|
+
if module_name == f".{attr_name}":
|
|
28
|
+
return module
|
|
29
|
+
else:
|
|
30
|
+
return getattr(module, attr_name)
|
|
31
|
+
except ImportError as e:
|
|
32
|
+
raise ImportError(f"Failed to import {attr_name} from {module_name}: {e}") from e
|
|
33
|
+
except AttributeError as e:
|
|
34
|
+
raise AttributeError(f"Failed to get {attr_name} from {module_name}: {e}") from e
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def __dir__():
|
|
38
|
+
lazy_attrs = list(_dynamic_imports.keys())
|
|
39
|
+
return sorted(lazy_attrs)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
__all__ = ["EventSource", "SSEError", "ServerSentEvent", "aconnect_sse", "connect_sse"]
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from contextlib import asynccontextmanager, contextmanager
|
|
5
|
+
from typing import Any, AsyncGenerator, AsyncIterator, Iterator, cast
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from ._decoders import SSEDecoder
|
|
9
|
+
from ._exceptions import SSEError
|
|
10
|
+
from ._models import ServerSentEvent
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class EventSource:
|
|
14
|
+
def __init__(self, response: httpx.Response) -> None:
|
|
15
|
+
self._response = response
|
|
16
|
+
|
|
17
|
+
def _check_content_type(self) -> None:
|
|
18
|
+
content_type = self._response.headers.get("content-type", "").partition(";")[0]
|
|
19
|
+
if "text/event-stream" not in content_type:
|
|
20
|
+
raise SSEError(
|
|
21
|
+
f"Expected response header Content-Type to contain 'text/event-stream', got {content_type!r}"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
def _get_charset(self) -> str:
|
|
25
|
+
"""Extract charset from Content-Type header, fallback to UTF-8."""
|
|
26
|
+
content_type = self._response.headers.get("content-type", "")
|
|
27
|
+
|
|
28
|
+
# Parse charset parameter using regex
|
|
29
|
+
charset_match = re.search(r"charset=([^;\s]+)", content_type, re.IGNORECASE)
|
|
30
|
+
if charset_match:
|
|
31
|
+
charset = charset_match.group(1).strip("\"'")
|
|
32
|
+
# Validate that it's a known encoding
|
|
33
|
+
try:
|
|
34
|
+
# Test if the charset is valid by trying to encode/decode
|
|
35
|
+
"test".encode(charset).decode(charset)
|
|
36
|
+
return charset
|
|
37
|
+
except (LookupError, UnicodeError):
|
|
38
|
+
# If charset is invalid, fall back to UTF-8
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
# Default to UTF-8 if no charset specified or invalid charset
|
|
42
|
+
return "utf-8"
|
|
43
|
+
|
|
44
|
+
@property
|
|
45
|
+
def response(self) -> httpx.Response:
|
|
46
|
+
return self._response
|
|
47
|
+
|
|
48
|
+
def iter_sse(self) -> Iterator[ServerSentEvent]:
|
|
49
|
+
self._check_content_type()
|
|
50
|
+
decoder = SSEDecoder()
|
|
51
|
+
charset = self._get_charset()
|
|
52
|
+
|
|
53
|
+
buffer = ""
|
|
54
|
+
for chunk in self._response.iter_bytes():
|
|
55
|
+
# Decode chunk using detected charset
|
|
56
|
+
text_chunk = chunk.decode(charset, errors="replace")
|
|
57
|
+
buffer += text_chunk
|
|
58
|
+
|
|
59
|
+
# Process complete lines
|
|
60
|
+
while "\n" in buffer:
|
|
61
|
+
line, buffer = buffer.split("\n", 1)
|
|
62
|
+
line = line.rstrip("\r")
|
|
63
|
+
sse = decoder.decode(line)
|
|
64
|
+
# when we reach a "\n\n" => line = ''
|
|
65
|
+
# => decoder will attempt to return an SSE Event
|
|
66
|
+
if sse is not None:
|
|
67
|
+
yield sse
|
|
68
|
+
|
|
69
|
+
# Process any remaining data in buffer
|
|
70
|
+
if buffer.strip():
|
|
71
|
+
line = buffer.rstrip("\r")
|
|
72
|
+
sse = decoder.decode(line)
|
|
73
|
+
if sse is not None:
|
|
74
|
+
yield sse
|
|
75
|
+
|
|
76
|
+
async def aiter_sse(self) -> AsyncGenerator[ServerSentEvent, None]:
|
|
77
|
+
self._check_content_type()
|
|
78
|
+
decoder = SSEDecoder()
|
|
79
|
+
lines = cast(AsyncGenerator[str, None], self._response.aiter_lines())
|
|
80
|
+
try:
|
|
81
|
+
async for line in lines:
|
|
82
|
+
line = line.rstrip("\n")
|
|
83
|
+
sse = decoder.decode(line)
|
|
84
|
+
if sse is not None:
|
|
85
|
+
yield sse
|
|
86
|
+
finally:
|
|
87
|
+
await lines.aclose()
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@contextmanager
|
|
91
|
+
def connect_sse(client: httpx.Client, method: str, url: str, **kwargs: Any) -> Iterator[EventSource]:
|
|
92
|
+
headers = kwargs.pop("headers", {})
|
|
93
|
+
headers["Accept"] = "text/event-stream"
|
|
94
|
+
headers["Cache-Control"] = "no-store"
|
|
95
|
+
|
|
96
|
+
with client.stream(method, url, headers=headers, **kwargs) as response:
|
|
97
|
+
yield EventSource(response)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@asynccontextmanager
|
|
101
|
+
async def aconnect_sse(
|
|
102
|
+
client: httpx.AsyncClient,
|
|
103
|
+
method: str,
|
|
104
|
+
url: str,
|
|
105
|
+
**kwargs: Any,
|
|
106
|
+
) -> AsyncIterator[EventSource]:
|
|
107
|
+
headers = kwargs.pop("headers", {})
|
|
108
|
+
headers["Accept"] = "text/event-stream"
|
|
109
|
+
headers["Cache-Control"] = "no-store"
|
|
110
|
+
|
|
111
|
+
async with client.stream(method, url, headers=headers, **kwargs) as response:
|
|
112
|
+
yield EventSource(response)
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional
|
|
4
|
+
|
|
5
|
+
from ._models import ServerSentEvent
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SSEDecoder:
|
|
9
|
+
def __init__(self) -> None:
|
|
10
|
+
self._event = ""
|
|
11
|
+
self._data: List[str] = []
|
|
12
|
+
self._last_event_id = ""
|
|
13
|
+
self._retry: Optional[int] = None
|
|
14
|
+
|
|
15
|
+
def decode(self, line: str) -> Optional[ServerSentEvent]:
|
|
16
|
+
# See: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation # noqa: E501
|
|
17
|
+
|
|
18
|
+
if not line:
|
|
19
|
+
if not self._event and not self._data and not self._last_event_id and self._retry is None:
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
sse = ServerSentEvent(
|
|
23
|
+
event=self._event,
|
|
24
|
+
data="\n".join(self._data),
|
|
25
|
+
id=self._last_event_id,
|
|
26
|
+
retry=self._retry,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# NOTE: as per the SSE spec, do not reset last_event_id.
|
|
30
|
+
self._event = ""
|
|
31
|
+
self._data = []
|
|
32
|
+
self._retry = None
|
|
33
|
+
|
|
34
|
+
return sse
|
|
35
|
+
|
|
36
|
+
if line.startswith(":"):
|
|
37
|
+
return None
|
|
38
|
+
|
|
39
|
+
fieldname, _, value = line.partition(":")
|
|
40
|
+
|
|
41
|
+
if value.startswith(" "):
|
|
42
|
+
value = value[1:]
|
|
43
|
+
|
|
44
|
+
if fieldname == "event":
|
|
45
|
+
self._event = value
|
|
46
|
+
elif fieldname == "data":
|
|
47
|
+
self._data.append(value)
|
|
48
|
+
elif fieldname == "id":
|
|
49
|
+
if "\0" in value:
|
|
50
|
+
pass
|
|
51
|
+
else:
|
|
52
|
+
self._last_event_id = value
|
|
53
|
+
elif fieldname == "retry":
|
|
54
|
+
try:
|
|
55
|
+
self._retry = int(value)
|
|
56
|
+
except (TypeError, ValueError):
|
|
57
|
+
pass
|
|
58
|
+
else:
|
|
59
|
+
pass # Field is ignored.
|
|
60
|
+
|
|
61
|
+
return None
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# This file was auto-generated by Fern from our API Definition.
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any, Optional
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@dataclass(frozen=True)
|
|
9
|
+
class ServerSentEvent:
|
|
10
|
+
event: str = "message"
|
|
11
|
+
data: str = ""
|
|
12
|
+
id: str = ""
|
|
13
|
+
retry: Optional[int] = None
|
|
14
|
+
|
|
15
|
+
def json(self) -> Any:
|
|
16
|
+
"""Parse the data field as JSON."""
|
|
17
|
+
return json.loads(self.data)
|
samsara/core/pagination.py
CHANGED
|
@@ -5,10 +5,10 @@ from __future__ import annotations
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import AsyncIterator, Awaitable, Callable, Generic, Iterator, List, Optional, TypeVar
|
|
7
7
|
|
|
8
|
-
from .http_response import BaseHttpResponse
|
|
9
|
-
|
|
10
8
|
# Generic to represent the underlying type of the results within a page
|
|
11
9
|
T = TypeVar("T")
|
|
10
|
+
# Generic to represent the type of the API response
|
|
11
|
+
R = TypeVar("R")
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
# SDKs implement a Page ABC per-pagination request, the endpoint then returns a pager that wraps this type
|
|
@@ -23,11 +23,11 @@ T = TypeVar("T")
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
@dataclass(frozen=True)
|
|
26
|
-
class SyncPager(Generic[T]):
|
|
27
|
-
get_next: Optional[Callable[[], Optional[SyncPager[T]]]]
|
|
26
|
+
class SyncPager(Generic[T, R]):
|
|
27
|
+
get_next: Optional[Callable[[], Optional[SyncPager[T, R]]]]
|
|
28
28
|
has_next: bool
|
|
29
29
|
items: Optional[List[T]]
|
|
30
|
-
response:
|
|
30
|
+
response: R
|
|
31
31
|
|
|
32
32
|
# Here we type ignore the iterator to avoid a mypy error
|
|
33
33
|
# caused by the type conflict with Pydanitc's __iter__ method
|
|
@@ -37,8 +37,8 @@ class SyncPager(Generic[T]):
|
|
|
37
37
|
if page.items is not None:
|
|
38
38
|
yield from page.items
|
|
39
39
|
|
|
40
|
-
def iter_pages(self) -> Iterator[SyncPager[T]]:
|
|
41
|
-
page: Optional[SyncPager[T]] = self
|
|
40
|
+
def iter_pages(self) -> Iterator[SyncPager[T, R]]:
|
|
41
|
+
page: Optional[SyncPager[T, R]] = self
|
|
42
42
|
while page is not None:
|
|
43
43
|
yield page
|
|
44
44
|
|
|
@@ -49,16 +49,16 @@ class SyncPager(Generic[T]):
|
|
|
49
49
|
if page is None or page.items is None or len(page.items) == 0:
|
|
50
50
|
return
|
|
51
51
|
|
|
52
|
-
def next_page(self) -> Optional[SyncPager[T]]:
|
|
52
|
+
def next_page(self) -> Optional[SyncPager[T, R]]:
|
|
53
53
|
return self.get_next() if self.get_next is not None else None
|
|
54
54
|
|
|
55
55
|
|
|
56
56
|
@dataclass(frozen=True)
|
|
57
|
-
class AsyncPager(Generic[T]):
|
|
58
|
-
get_next: Optional[Callable[[], Awaitable[Optional[AsyncPager[T]]]]]
|
|
57
|
+
class AsyncPager(Generic[T, R]):
|
|
58
|
+
get_next: Optional[Callable[[], Awaitable[Optional[AsyncPager[T, R]]]]]
|
|
59
59
|
has_next: bool
|
|
60
60
|
items: Optional[List[T]]
|
|
61
|
-
response:
|
|
61
|
+
response: R
|
|
62
62
|
|
|
63
63
|
async def __aiter__(self) -> AsyncIterator[T]:
|
|
64
64
|
async for page in self.iter_pages():
|
|
@@ -66,8 +66,8 @@ class AsyncPager(Generic[T]):
|
|
|
66
66
|
for item in page.items:
|
|
67
67
|
yield item
|
|
68
68
|
|
|
69
|
-
async def iter_pages(self) -> AsyncIterator[AsyncPager[T]]:
|
|
70
|
-
page: Optional[AsyncPager[T]] = self
|
|
69
|
+
async def iter_pages(self) -> AsyncIterator[AsyncPager[T, R]]:
|
|
70
|
+
page: Optional[AsyncPager[T, R]] = self
|
|
71
71
|
while page is not None:
|
|
72
72
|
yield page
|
|
73
73
|
|
|
@@ -78,5 +78,5 @@ class AsyncPager(Generic[T]):
|
|
|
78
78
|
if page is None or page.items is None or len(page.items) == 0:
|
|
79
79
|
return
|
|
80
80
|
|
|
81
|
-
async def next_page(self) -> Optional[AsyncPager[T]]:
|
|
81
|
+
async def next_page(self) -> Optional[AsyncPager[T, R]]:
|
|
82
82
|
return await self.get_next() if self.get_next is not None else None
|
|
@@ -220,7 +220,9 @@ def universal_root_validator(
|
|
|
220
220
|
) -> Callable[[AnyCallable], AnyCallable]:
|
|
221
221
|
def decorator(func: AnyCallable) -> AnyCallable:
|
|
222
222
|
if IS_PYDANTIC_V2:
|
|
223
|
-
|
|
223
|
+
# In Pydantic v2, for RootModel we always use "before" mode
|
|
224
|
+
# The custom validators transform the input value before the model is created
|
|
225
|
+
return cast(AnyCallable, pydantic.model_validator(mode="before")(func)) # type: ignore[attr-defined]
|
|
224
226
|
return cast(AnyCallable, pydantic.root_validator(pre=pre)(func)) # type: ignore[call-overload]
|
|
225
227
|
|
|
226
228
|
return decorator
|
samsara/documents/client.py
CHANGED
|
@@ -66,9 +66,7 @@ class DocumentsClient:
|
|
|
66
66
|
client = Samsara(
|
|
67
67
|
token="YOUR_TOKEN",
|
|
68
68
|
)
|
|
69
|
-
client.documents.get_document_types(
|
|
70
|
-
after="after",
|
|
71
|
-
)
|
|
69
|
+
client.documents.get_document_types()
|
|
72
70
|
"""
|
|
73
71
|
_response = self._raw_client.get_document_types(after=after, request_options=request_options)
|
|
74
72
|
return _response.data
|
|
@@ -128,9 +126,6 @@ class DocumentsClient:
|
|
|
128
126
|
client.documents.get_documents(
|
|
129
127
|
start_time="startTime",
|
|
130
128
|
end_time="endTime",
|
|
131
|
-
after="after",
|
|
132
|
-
document_type_id="documentTypeId",
|
|
133
|
-
query_by="queryBy",
|
|
134
129
|
)
|
|
135
130
|
"""
|
|
136
131
|
_response = self._raw_client.get_documents(
|
|
@@ -430,9 +425,7 @@ class AsyncDocumentsClient:
|
|
|
430
425
|
|
|
431
426
|
|
|
432
427
|
async def main() -> None:
|
|
433
|
-
await client.documents.get_document_types(
|
|
434
|
-
after="after",
|
|
435
|
-
)
|
|
428
|
+
await client.documents.get_document_types()
|
|
436
429
|
|
|
437
430
|
|
|
438
431
|
asyncio.run(main())
|
|
@@ -500,9 +493,6 @@ class AsyncDocumentsClient:
|
|
|
500
493
|
await client.documents.get_documents(
|
|
501
494
|
start_time="startTime",
|
|
502
495
|
end_time="endTime",
|
|
503
|
-
after="after",
|
|
504
|
-
document_type_id="documentTypeId",
|
|
505
|
-
query_by="queryBy",
|
|
506
496
|
)
|
|
507
497
|
|
|
508
498
|
|