vapi_client/apis/
analytics_api.rs1use std::sync::Arc;
12
13use async_trait::async_trait;
14use reqwest;
15use serde::{de::Error as _, Deserialize, Serialize};
16
17use super::{configuration, Error};
18use crate::{
19 apis::{ContentType, ResponseContent},
20 models,
21};
22
23#[async_trait]
24pub trait AnalyticsApi: Send + Sync {
25 async fn analytics_controller_query<'analytics_query_dto>(
27 &self,
28 analytics_query_dto: models::AnalyticsQueryDto,
29 ) -> Result<Vec<models::AnalyticsQueryResult>, Error<AnalyticsControllerQueryError>>;
30}
31
32pub struct AnalyticsApiClient {
33 configuration: Arc<configuration::Configuration>,
34}
35
36impl AnalyticsApiClient {
37 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
38 Self { configuration }
39 }
40}
41
42#[async_trait]
43impl AnalyticsApi for AnalyticsApiClient {
44 async fn analytics_controller_query<'analytics_query_dto>(
45 &self,
46 analytics_query_dto: models::AnalyticsQueryDto,
47 ) -> Result<Vec<models::AnalyticsQueryResult>, Error<AnalyticsControllerQueryError>> {
48 let local_var_configuration = &self.configuration;
49
50 let local_var_client = &local_var_configuration.client;
51
52 let local_var_uri_str = format!("{}/analytics", local_var_configuration.base_path);
53 let mut local_var_req_builder =
54 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
55
56 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
57 local_var_req_builder = local_var_req_builder
58 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
59 }
60 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
61 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
62 };
63 local_var_req_builder = local_var_req_builder.json(&analytics_query_dto);
64
65 let local_var_req = local_var_req_builder.build()?;
66 let local_var_resp = local_var_client.execute(local_var_req).await?;
67
68 let local_var_status = local_var_resp.status();
69 let local_var_content_type = local_var_resp
70 .headers()
71 .get("content-type")
72 .and_then(|v| v.to_str().ok())
73 .unwrap_or("application/octet-stream");
74 let local_var_content_type = super::ContentType::from(local_var_content_type);
75 let local_var_content = local_var_resp.text().await?;
76
77 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
78 match local_var_content_type {
79 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
80 ContentType::Text => {
81 return Err(Error::from(serde_json::Error::custom(
82 "Received `text/plain` content type response that cannot be converted to \
83 `Vec<models::AnalyticsQueryResult>`",
84 )))
85 }
86 ContentType::Unsupported(local_var_unknown_type) => {
87 return Err(Error::from(serde_json::Error::custom(format!(
88 "Received `{local_var_unknown_type}` content type response that cannot be \
89 converted to `Vec<models::AnalyticsQueryResult>`"
90 ))))
91 }
92 }
93 } else {
94 let local_var_entity: Option<AnalyticsControllerQueryError> =
95 serde_json::from_str(&local_var_content).ok();
96 let local_var_error = ResponseContent {
97 status: local_var_status,
98 content: local_var_content,
99 entity: local_var_entity,
100 };
101 Err(Error::ResponseError(local_var_error))
102 }
103 }
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum AnalyticsControllerQueryError {
110 UnknownValue(serde_json::Value),
111}