Skip to content

Commit df6cbe9

Browse files
authored
Merge pull request #28 from DIMO-Network/ACC-414
ACC-414: Support for Vehicle Events API
2 parents 1679090 + 107a5f4 commit df6cbe9

File tree

5 files changed

+174
-1
lines changed

5 files changed

+174
-1
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,28 @@ my_query = """
209209
total_network_vehicles = dimo.identity.query(query=my_query)
210210
```
211211

212+
### Vehicle Events API (DIMO Webhooks)
213+
214+
The SDK supports calls to the Vehicle Events API, including: registering a new webhook, subscribing and unsubscribing vehicles, checking vehicles subscribed to a specific webhook, and more. To view all the available methods, check out the [Vehicle Events API Documentation here](https://docs.dimo.org/developer-platform/vehicle-events-api-webhooks).
215+
216+
Here's a sample of how you might register a new webhook:
217+
218+
```python
219+
220+
new_webhook_config = {
221+
"service": "Telemetry",
222+
"data": "powertrainTransmissionTravelledDistance",
223+
"trigger": "valueNumber > 10000",
224+
"setup": "Realtime",
225+
"description": "Trigger when odometer above 10000 km",
226+
"target_uri": "https://my-target-uri.com/webhook",
227+
"status": "Active",
228+
"verification_token": "abc"
229+
}
230+
231+
dimo.vehicle_events.register_webhook(developer_jwt=dev_jwt, request=new_webhook_config)
232+
```
233+
212234
## How to Contribute to the SDK
213235

214236
You can read more about contributing [here](https://github.com/DIMO-Network/dimo-python-sdk/blob/dev-barrettk/CONTRIBUTING.md)

dimo/api/vehicle_events.py

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
from dimo.errors import check_type
2+
3+
4+
class VehicleEvents:
5+
6+
def __init__(self, request_method, get_auth_headers):
7+
self._request = request_method
8+
self._get_auth_headers = get_auth_headers
9+
10+
def list_all_webhooks(self, developer_jwt: str):
11+
"""
12+
Lists all webhooks for a given developer license
13+
"""
14+
check_type("developer_jwt", developer_jwt, str)
15+
url = f"/v1/webhooks"
16+
return self._request(
17+
"GET", "VehicleEvents", url, headers=self._get_auth_headers(developer_jwt)
18+
)
19+
20+
def register_webhook(self, developer_jwt: str, request: object):
21+
"""
22+
Creates a new webhook under the developer license
23+
"""
24+
check_type("developer_jwt", developer_jwt, str)
25+
check_type("request", request, object)
26+
url = f"/v1/webhooks"
27+
return self._request(
28+
"POST",
29+
"VehicleEvents",
30+
url,
31+
headers=self._get_auth_headers(developer_jwt),
32+
data=request,
33+
)
34+
35+
def webhook_signals(self, developer_jwt: str):
36+
"""
37+
Fetches the list of signal names available for the data field
38+
"""
39+
check_type("developer_jwt", developer_jwt, str)
40+
url = f"/v1/webhooks/signals"
41+
return self._request(
42+
"GET", "VehicleEvents", url, headers=self._get_auth_headers(developer_jwt)
43+
)
44+
45+
def list_vehicle_subscriptions(self, developer_jwt: str, token_id: str):
46+
"""
47+
Lists all webhooks that a specified vehicle token id is subscribed to
48+
"""
49+
check_type("developer_jwt", developer_jwt, str)
50+
check_type("token_id", token_id, str)
51+
url = f"/v1/webhooks/vehicles/{token_id}"
52+
return self._request(
53+
"GET", "VehicleEvents", url, headers=self._get_auth_headers(developer_jwt)
54+
)
55+
56+
def list_vehicle_subscriptions_by_event(self, developer_jwt: str, webhook_id: str):
57+
"""
58+
Lists all vehicle subscriptions for a given webhook id
59+
"""
60+
check_type("developer_jwt", developer_jwt, str)
61+
check_type("webhook_id", webhook_id, str)
62+
url = f"/v1/webhooks/{webhook_id}"
63+
return self._request(
64+
"GET", "VehicleEvents", url, headers=self._get_auth_headers(developer_jwt)
65+
)
66+
67+
def update_webhook(self, developer_jwt: str, webhook_id: str, request: object):
68+
"""
69+
Updates a webhook by a provided webhook id
70+
"""
71+
check_type("developer_jwt", developer_jwt, str)
72+
check_type("webhook_id", webhook_id, str)
73+
check_type("request", request, object)
74+
url = f"/v1/webhooks/{webhook_id}"
75+
return self._request(
76+
"PUT",
77+
"VehicleEvents",
78+
url,
79+
headers=self._get_auth_headers(developer_jwt),
80+
data=request,
81+
)
82+
83+
def delete_webhook(self, developer_jwt: str, webhook_id: str):
84+
"""
85+
Deletes a webhook by a provided webhook id
86+
"""
87+
check_type("developer_jwt", developer_jwt, str)
88+
check_type("webhook_id", webhook_id, str)
89+
url = f"/v1/webhooks/{webhook_id}"
90+
return self._request(
91+
"DELETE",
92+
"VehicleEvents",
93+
url,
94+
headers=self._get_auth_headers(developer_jwt),
95+
)
96+
97+
def subscribe_all_vehicles(self, developer_jwt: str, webhook_id: str):
98+
"""
99+
Subscribes all vehicles to a specified webhook
100+
"""
101+
check_type("developer_jwt", developer_jwt, str)
102+
check_type("webhook_id", webhook_id, str)
103+
url = f"/v1/webhooks/{webhook_id}/subscribe/all"
104+
return self._request(
105+
"POST", "VehicleEvents", url, headers=self._get_auth_headers(developer_jwt)
106+
)
107+
108+
def subscribe_vehicle(self, developer_jwt: str, token_id: str, webhook_id: str):
109+
"""
110+
Subscribes a single vehicle to a specified webhook
111+
"""
112+
check_type("developer_jwt", developer_jwt, str)
113+
check_type("token_id", token_id, str)
114+
check_type("webhook_id", webhook_id, str)
115+
url = f"/v1/webhooks/{webhook_id}/subscribe/{token_id}"
116+
return self._request(
117+
"POST", "VehicleEvents", url, headers=self._get_auth_headers(developer_jwt)
118+
)
119+
120+
def unsubscribe_all_vehicles(self, developer_jwt: str, webhook_id: str):
121+
"""
122+
Unsubscribes all vehicles from a specified webhook
123+
"""
124+
check_type("developer_jwt", developer_jwt, str)
125+
check_type("webhook_id", webhook_id, str)
126+
url = f"/v1/webhooks/{webhook_id}/unsubscribe/all"
127+
return self._request(
128+
"DELETE",
129+
"VehicleEvents",
130+
url,
131+
headers=self._get_auth_headers(developer_jwt),
132+
)
133+
134+
def unsubscribe_vehicle(self, developer_jwt: str, token_id: str, webhook_id: str):
135+
"""
136+
Unsubscribes a single vehicle from a specified webhook
137+
"""
138+
check_type("developer_jwt", developer_jwt, str)
139+
check_type("token_id", token_id, str)
140+
check_type("webhook_id", webhook_id, str)
141+
url = f"/v1/webhooks/{webhook_id}/unsubscribe/{token_id}"
142+
return self._request(
143+
"DELETE",
144+
"VehicleEvents",
145+
url,
146+
headers=self._get_auth_headers(developer_jwt),
147+
)

dimo/dimo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .api.token_exchange import TokenExchange
77
from .api.trips import Trips
88
from .api.valuations import Valuations
9+
from .api.vehicle_events import VehicleEvents
910

1011
from .graphql.identity import Identity
1112
from .graphql.telemetry import Telemetry
@@ -83,6 +84,7 @@ def __getattr__(self, name: str) -> Any:
8384
"valuations": (Valuations, ("request", "_get_auth_headers")),
8485
"identity": (Identity, ("self",)),
8586
"telemetry": (Telemetry, ("self",)),
87+
"vehicle_events": (VehicleEvents, ("request", "_get_auth_headers")),
8688
}
8789
if name in mapping:
8890
cls, deps = mapping[name]

dimo/environments.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"Trips": "https://trips-api.dimo.zone",
1010
"User": "https://users-api.dimo.zone",
1111
"Valuations": "https://valuations-api.dimo.zone",
12+
"VehicleEvents": "https://vehicle-events-api.dimo.zone",
1213
},
1314
"Dev": {
1415
"Attestation": "https://attestation-api.dev.dimo.zone",
@@ -20,5 +21,6 @@
2021
"Trips": "https://trips-api.dev.dimo.zone",
2122
"User": "https://users-api.dev.dimo.zone",
2223
"Valuations": "https://valuations-api.dev.dimo.zone",
24+
"VehicleEvents": "https://vehicle-events-api.dev.dimo.zone",
2325
},
2426
}

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "dimo-python-sdk"
7-
version = "1.3.5"
7+
version = "1.4.0"
88
authors = [
99
{ name="Barrett Kowalsky", email="[email protected]" },
1010
]

0 commit comments

Comments
 (0)