use async_trait::async_trait;
#[cfg(feature = "mockall")]
use mockall::automock;
use reqwest;
use std::sync::Arc;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
use crate::apis::ContentType;
#[cfg_attr(feature = "mockall", automock)]
#[async_trait]
pub trait ActivityApi: Send + Sync {
async fn activity_chart<'days>(&self, days: Option<u32>) -> Result<Vec<models::ActivityChartPoint>, Error<ActivityChartError>>;
async fn activity_stats<>(&self, ) -> Result<models::ActivityStats, Error<ActivityStatsError>>;
async fn engagement_stats<>(&self, ) -> Result<models::EngagementStats, Error<EngagementStatsError>>;
async fn get_activity_by_notification<'notification_id>(&self, notification_id: &str) -> Result<Vec<models::ActivityRecord>, Error<GetActivityByNotificationError>>;
async fn list_activity<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<u32>, offset: Option<u32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<models::PaginatedActivityRecord, Error<ListActivityError>>;
async fn list_activity_requests<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<u32>, offset: Option<u32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<Vec<models::ActivityRequestRecord>, Error<ListActivityRequestsError>>;
async fn list_workflow_runs<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<u32>, offset: Option<u32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<Vec<models::WorkflowRunRecord>, Error<ListWorkflowRunsError>>;
async fn workflow_stats<>(&self, ) -> Result<models::WorkflowStats, Error<WorkflowStatsError>>;
}
pub struct ActivityApiClient {
configuration: Arc<configuration::Configuration>
}
impl ActivityApiClient {
pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
Self { configuration }
}
}
#[async_trait]
impl ActivityApi for ActivityApiClient {
async fn activity_chart<'days>(&self, days: Option<u32>) -> Result<Vec<models::ActivityChartPoint>, Error<ActivityChartError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/chart/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref param_value) = days {
local_var_req_builder = local_var_req_builder.query(&[("days", ¶m_value.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ActivityChartPoint>`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::ActivityChartPoint>`")))),
}
} else {
let local_var_entity: Option<ActivityChartError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn activity_stats<>(&self, ) -> Result<models::ActivityStats, Error<ActivityStatsError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/stats/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ActivityStats`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ActivityStats`")))),
}
} else {
let local_var_entity: Option<ActivityStatsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn engagement_stats<>(&self, ) -> Result<models::EngagementStats, Error<EngagementStatsError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/engagement/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::EngagementStats`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::EngagementStats`")))),
}
} else {
let local_var_entity: Option<EngagementStatsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn get_activity_by_notification<'notification_id>(&self, notification_id: &str) -> Result<Vec<models::ActivityRecord>, Error<GetActivityByNotificationError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/{notification_id}/", local_var_configuration.base_path, notification_id=crate::apis::urlencode(notification_id));
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ActivityRecord>`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::ActivityRecord>`")))),
}
} else {
let local_var_entity: Option<GetActivityByNotificationError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn list_activity<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<u32>, offset: Option<u32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<models::PaginatedActivityRecord, Error<ListActivityError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref param_value) = limit {
local_var_req_builder = local_var_req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = offset {
local_var_req_builder = local_var_req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = q {
local_var_req_builder = local_var_req_builder.query(&[("q", ¶m_value.to_string())]);
}
if let Some(ref param_value) = filter_by {
local_var_req_builder = local_var_req_builder.query(&[("filter_by", ¶m_value.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::PaginatedActivityRecord`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::PaginatedActivityRecord`")))),
}
} else {
let local_var_entity: Option<ListActivityError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn list_activity_requests<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<u32>, offset: Option<u32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<Vec<models::ActivityRequestRecord>, Error<ListActivityRequestsError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/requests/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref param_value) = limit {
local_var_req_builder = local_var_req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = offset {
local_var_req_builder = local_var_req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = q {
local_var_req_builder = local_var_req_builder.query(&[("q", ¶m_value.to_string())]);
}
if let Some(ref param_value) = filter_by {
local_var_req_builder = local_var_req_builder.query(&[("filter_by", ¶m_value.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::ActivityRequestRecord>`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::ActivityRequestRecord>`")))),
}
} else {
let local_var_entity: Option<ListActivityRequestsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn list_workflow_runs<'limit, 'offset, 'q, 'filter_by>(&self, limit: Option<u32>, offset: Option<u32>, q: Option<&'q str>, filter_by: Option<&'filter_by str>) -> Result<Vec<models::WorkflowRunRecord>, Error<ListWorkflowRunsError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/workflow-runs/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref param_value) = limit {
local_var_req_builder = local_var_req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = offset {
local_var_req_builder = local_var_req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref param_value) = q {
local_var_req_builder = local_var_req_builder.query(&[("q", ¶m_value.to_string())]);
}
if let Some(ref param_value) = filter_by {
local_var_req_builder = local_var_req_builder.query(&[("filter_by", ¶m_value.to_string())]);
}
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::WorkflowRunRecord>`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<models::WorkflowRunRecord>`")))),
}
} else {
let local_var_entity: Option<ListWorkflowRunsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
async fn workflow_stats<>(&self, ) -> Result<models::WorkflowStats, Error<WorkflowStatsError>> {
let local_var_configuration = &self.configuration;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/v1/activity/workflows/stats/", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_req = local_var_req_builder.build()?;
let local_var_resp = local_var_client.execute(local_var_req).await?;
let local_var_status = local_var_resp.status();
let local_var_content_type = local_var_resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let local_var_content_type = super::ContentType::from(local_var_content_type);
let local_var_content = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
match local_var_content_type {
ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::WorkflowStats`"))),
ContentType::Unsupported(local_var_unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{local_var_unknown_type}` content type response that cannot be converted to `models::WorkflowStats`")))),
}
} else {
let local_var_entity: Option<WorkflowStatsError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
Err(Error::ResponseError(local_var_error))
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActivityChartError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ActivityStatsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EngagementStatsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetActivityByNotificationError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListActivityError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListActivityRequestsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListWorkflowRunsError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkflowStatsError {
UnknownValue(serde_json::Value),
}