vapi_client/apis/
analytics_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum AnalyticsControllerQueryError {
20 UnknownValue(serde_json::Value),
21}
22
23pub async fn analytics_controller_query(
24 configuration: &configuration::Configuration,
25 analytics_query_dto: models::AnalyticsQueryDto,
26) -> Result<Vec<models::AnalyticsQueryResult>, Error<AnalyticsControllerQueryError>> {
27 let p_analytics_query_dto = analytics_query_dto;
29
30 let uri_str = format!("{}/analytics", configuration.base_path);
31 let mut req_builder = configuration
32 .client
33 .request(reqwest::Method::POST, &uri_str);
34
35 if let Some(ref user_agent) = configuration.user_agent {
36 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
37 }
38 if let Some(ref token) = configuration.bearer_access_token {
39 req_builder = req_builder.bearer_auth(token.to_owned());
40 };
41 req_builder = req_builder.json(&p_analytics_query_dto);
42
43 let req = req_builder.build()?;
44 let resp = configuration.client.execute(req).await?;
45
46 let status = resp.status();
47 let content_type = resp
48 .headers()
49 .get("content-type")
50 .and_then(|v| v.to_str().ok())
51 .unwrap_or("application/octet-stream");
52 let content_type = super::ContentType::from(content_type);
53
54 if !status.is_client_error() && !status.is_server_error() {
55 let content = resp.text().await?;
56 match content_type {
57 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
58 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::AnalyticsQueryResult>`"))),
59 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec<models::AnalyticsQueryResult>`")))),
60 }
61 } else {
62 let content = resp.text().await?;
63 let entity: Option<AnalyticsControllerQueryError> = serde_json::from_str(&content).ok();
64 Err(Error::ResponseError(ResponseContent {
65 status,
66 content,
67 entity,
68 }))
69 }
70}