use crate::utils::request::{make_request, RequestParams, make_auth_request, AuthRequestParams};
use reqwest::Method;
use serde_json::Value;
use std::collections::HashMap;
use std::error::Error;
pub struct DeviceDefinitions {
base_url: String,
}
impl DeviceDefinitions {
pub fn new(base_url: &str) -> Self {
Self {
base_url: base_url.to_string(),
}
}
pub async fn decode_vin(
&self,
body: HashMap<String, String>,
) -> Result<Value, Box<dyn Error>> {
let path = "/device-definitions/decode-vin".to_string();
let request_params = AuthRequestParams {
method: Method::POST,
base_url: self.base_url.clone(),
path,
query_params: None,
body: Some(body.into_iter().map(|(k, v)| (k, Value::String(v))).collect()),
headers: None,
token_type: "developer".to_string(),
};
make_auth_request(request_params).await
}
pub async fn search(
&self,
query: &str,
additional_params: Option<HashMap<String, String>>,
) -> Result<Value, Box<dyn Error>> {
let path = "/device-definitions/search".to_string();
let mut query_params = HashMap::new();
query_params.insert("query".to_string(), query.to_string());
if let Some(additional) = additional_params {
query_params.extend(additional);
}
let request_params = RequestParams {
method: Method::GET,
base_url: self.base_url.clone(),
path,
query_params: Some(query_params),
body: None,
headers: None,
};
make_request(request_params).await
}
}