dimo_rust_sdk/graphql/
telemetry.rs1use crate::utils::request::{make_auth_request, AuthRequestParams};
2use serde_json::Value;
3use std::collections::HashMap;
4use std::error::Error;
5
6pub struct Telemetry {
7 base_url: String,
8}
9
10impl Telemetry {
11 pub fn new(base_url: &str) -> Self {
12 Self {
13 base_url: base_url.to_string(),
14 }
15 }
16
17 pub async fn query(&self, query: &str) -> Result<Value, Box<dyn Error>> {
18 let mut body = HashMap::new();
19 body.insert("query".to_string(), Value::String(query.to_string()));
20
21 let params = AuthRequestParams {
22 method: reqwest::Method::POST,
23 base_url: self.base_url.clone(),
24 path: "/telemetry".to_string(),
25 query_params: None,
26 body: Some(body),
27 headers: None,
28 token_type: "vehicle".to_string(),
29 };
30
31 make_auth_request(params).await
32 }
33
34 pub async fn get_latest_signals(&self, token_id: &str) -> Result<Value, Box<dyn Error>> {
35 let query = format!(
36 r#"
37 query {{
38 SignalsLatest(tokenID: "{}") {{
39 powertrainTransmissionTravelledDistance {{
40 timestamp
41 value
42 }}
43 exteriorAirTemperature {{
44 timestamp
45 value
46 }}
47 speed {{
48 timestamp
49 value
50 }}
51 powertrainType {{
52 timestamp
53 value
54 }}
55 }}
56 }}
57 "#,
58 token_id
59 );
60
61 self.query(&query).await
62 }
63}