use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateSavedQueryError {
Status400(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteSavedQueryError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ExecuteSavedQueryError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetSavedQueryError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSavedQueriesError {
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListSavedQueryVersionsError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateSavedQueryError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
pub async fn create_saved_query(
configuration: &configuration::Configuration,
create_saved_query_request: models::CreateSavedQueryRequest,
) -> Result<models::SavedQueryDetail, Error<CreateSavedQueryError>> {
let p_body_create_saved_query_request = create_saved_query_request;
let uri_str = format!("{}/v1/queries", configuration.base_path);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_create_saved_query_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&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::SavedQueryDetail`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SavedQueryDetail`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<CreateSavedQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn delete_saved_query(
configuration: &configuration::Configuration,
id: &str,
) -> Result<(), Error<DeleteSavedQueryError>> {
let p_path_id = id;
let uri_str = format!(
"{}/v1/queries/{id}",
configuration.base_path,
id = crate::apis::urlencode(p_path_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<DeleteSavedQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn execute_saved_query(
configuration: &configuration::Configuration,
id: &str,
x_database_id: &str,
execute_saved_query_request: Option<models::ExecuteSavedQueryRequest>,
) -> Result<models::QueryResponse, Error<ExecuteSavedQueryError>> {
let p_path_id = id;
let p_header_x_database_id = x_database_id;
let p_body_execute_saved_query_request = execute_saved_query_request;
let uri_str = format!(
"{}/v1/queries/{id}/execute",
configuration.base_path,
id = crate::apis::urlencode(p_path_id)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
req_builder = req_builder.header("X-Database-Id", p_header_x_database_id.to_string());
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_execute_saved_query_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&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::QueryResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::QueryResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ExecuteSavedQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_saved_query(
configuration: &configuration::Configuration,
id: &str,
) -> Result<models::SavedQueryDetail, Error<GetSavedQueryError>> {
let p_path_id = id;
let uri_str = format!(
"{}/v1/queries/{id}",
configuration.base_path,
id = crate::apis::urlencode(p_path_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&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::SavedQueryDetail`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SavedQueryDetail`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetSavedQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_saved_queries(
configuration: &configuration::Configuration,
limit: Option<i32>,
offset: Option<i32>,
) -> Result<models::ListSavedQueriesResponse, Error<ListSavedQueriesError>> {
let p_query_limit = limit;
let p_query_offset = offset;
let uri_str = format!("{}/v1/queries", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&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::ListSavedQueriesResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListSavedQueriesResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ListSavedQueriesError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_saved_query_versions(
configuration: &configuration::Configuration,
id: &str,
limit: Option<i32>,
offset: Option<i32>,
) -> Result<models::ListSavedQueryVersionsResponse, Error<ListSavedQueryVersionsError>> {
let p_path_id = id;
let p_query_limit = limit;
let p_query_offset = offset;
let uri_str = format!(
"{}/v1/queries/{id}/versions",
configuration.base_path,
id = crate::apis::urlencode(p_path_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_limit {
req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_offset {
req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&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::ListSavedQueryVersionsResponse`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListSavedQueryVersionsResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ListSavedQueryVersionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_saved_query(
configuration: &configuration::Configuration,
id: &str,
update_saved_query_request: models::UpdateSavedQueryRequest,
) -> Result<models::SavedQueryDetail, Error<UpdateSavedQueryError>> {
let p_path_id = id;
let p_body_update_saved_query_request = update_saved_query_request;
let uri_str = format!(
"{}/v1/queries/{id}",
configuration.base_path,
id = crate::apis::urlencode(p_path_id)
);
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(apikey) = configuration.api_keys.get("X-Workspace-Id") {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("X-Workspace-Id", value);
};
if let Some(token) = configuration.resolve_bearer_token().await {
req_builder = req_builder.bearer_auth(token);
};
req_builder = req_builder.json(&p_body_update_saved_query_request);
let req = req_builder.build()?;
crate::http_log::log_request(&req);
let resp = configuration.client.execute(req).await?;
let status = resp.status();
crate::http_log::log_response_status(status);
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
match content_type {
ContentType::Json => serde_json::from_str(&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::SavedQueryDetail`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::SavedQueryDetail`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<UpdateSavedQueryError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}