/*
* Hotdata API
*
* Powerful data platform API for datasets, queries, and analytics.
*
* The version of the OpenAPI document: 1.0.0
* Contact: developers@hotdata.dev
* Generated by: https://openapi-generator.tech
*/
use super::{configuration, ContentType, Error};
use crate::{apis::ResponseContent, models};
use reqwest;
use serde::{de::Error as _, Deserialize, Serialize};
/// struct for typed errors of method [`create_dataset`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateDatasetError {
Status400(models::ApiErrorResponse),
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_dataset`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteDatasetError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_dataset`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetDatasetError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_dataset_versions`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListDatasetVersionsError {
Status404(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`list_datasets`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ListDatasetsError {
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`update_dataset`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UpdateDatasetError {
Status404(models::ApiErrorResponse),
Status409(models::ApiErrorResponse),
UnknownValue(serde_json::Value),
}
/// Create a new dataset from an uploaded file, inline data, a URL, or a SQL/saved query. The dataset becomes a queryable table under the `datasets` schema (e.g., `SELECT * FROM datasets.my_table`). Supports CSV, JSON, and Parquet formats. Optionally specify explicit column types. For `sql_query` / `saved_query` sources the dataset materializes by running that SQL, so the `X-Database-Id` header is required and the query sees only that database's catalogs (the scope is also reused on refresh). Upload/url/inline sources ignore the header.
pub async fn create_dataset(
configuration: &configuration::Configuration,
create_dataset_request: models::CreateDatasetRequest,
x_database_id: Option<&str>,
) -> Result<models::CreateDatasetResponse, Error<CreateDatasetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_body_create_dataset_request = create_dataset_request;
let p_header_x_database_id = x_database_id;
let uri_str = format!("{}/v1/datasets", 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(param_value) = p_header_x_database_id {
req_builder = req_builder.header("X-Database-Id", param_value.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(apikey) = configuration.api_keys.get("X-Session-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-Session-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_dataset_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::CreateDatasetResponse`"))),
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::CreateDatasetResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<CreateDatasetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn delete_dataset(
configuration: &configuration::Configuration,
id: &str,
) -> Result<(), Error<DeleteDatasetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let uri_str = format!(
"{}/v1/datasets/{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(apikey) = configuration.api_keys.get("X-Session-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-Session-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<DeleteDatasetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn get_dataset(
configuration: &configuration::Configuration,
id: &str,
) -> Result<models::GetDatasetResponse, Error<GetDatasetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let uri_str = format!(
"{}/v1/datasets/{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::GetDatasetResponse`"))),
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::GetDatasetResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<GetDatasetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_dataset_versions(
configuration: &configuration::Configuration,
id: &str,
limit: Option<i32>,
offset: Option<i32>,
) -> Result<models::ListDatasetVersionsResponse, Error<ListDatasetVersionsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_query_limit = limit;
let p_query_offset = offset;
let uri_str = format!(
"{}/v1/datasets/{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::ListDatasetVersionsResponse`"))),
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::ListDatasetVersionsResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ListDatasetVersionsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn list_datasets(
configuration: &configuration::Configuration,
limit: Option<i32>,
offset: Option<i32>,
) -> Result<models::ListDatasetsResponse, Error<ListDatasetsError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_query_limit = limit;
let p_query_offset = offset;
let uri_str = format!("{}/v1/datasets", 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(apikey) = configuration.api_keys.get("X-Session-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-Session-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::ListDatasetsResponse`"))),
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::ListDatasetsResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<ListDatasetsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn update_dataset(
configuration: &configuration::Configuration,
id: &str,
update_dataset_request: models::UpdateDatasetRequest,
) -> Result<models::UpdateDatasetResponse, Error<UpdateDatasetError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_path_id = id;
let p_body_update_dataset_request = update_dataset_request;
let uri_str = format!(
"{}/v1/datasets/{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(apikey) = configuration.api_keys.get("X-Session-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-Session-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_dataset_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::UpdateDatasetResponse`"))),
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::UpdateDatasetResponse`")))),
}
} else {
let content = resp.text().await?;
crate::http_log::log_response_body(&content);
let entity: Option<UpdateDatasetError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}