use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
use tokio::fs::File as TokioFile;
use tokio_util::codec::{BytesCodec, FramedRead};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsDeleteV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsGetExtractedTextSignedUrlV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsGetSignedUrlV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsGetStatusV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsGetTextContentV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsGetV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsListV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsReprocessV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsUpdateV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum LibrariesDocumentsUploadV1Error {
Status422(models::HttpValidationError),
UnknownValue(serde_json::Value),
}
pub async fn libraries_documents_delete_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<(), Error<LibrariesDocumentsDeleteV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsDeleteV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_get_extracted_text_signed_url_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<String, Error<LibrariesDocumentsGetExtractedTextSignedUrlV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/extracted-text-signed-url", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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 `String`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsGetExtractedTextSignedUrlV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_get_signed_url_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<String, Error<LibrariesDocumentsGetSignedUrlV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/signed-url", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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 `String`"))),
ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsGetSignedUrlV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_get_status_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<models::ProcessingStatusOut, Error<LibrariesDocumentsGetStatusV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/status", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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::ProcessingStatusOut`"))),
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::ProcessingStatusOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsGetStatusV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_get_text_content_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<models::DocumentTextContent, Error<LibrariesDocumentsGetTextContentV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/text_content", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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::DocumentTextContent`"))),
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::DocumentTextContent`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsGetTextContentV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_get_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<models::DocumentOut, Error<LibrariesDocumentsGetV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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::DocumentOut`"))),
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::DocumentOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsGetV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_list_v1(configuration: &configuration::Configuration, library_id: &str, search: Option<&str>, page_size: Option<i32>, page: Option<i32>, filters_attributes: Option<&str>, sort_by: Option<&str>, sort_order: Option<&str>) -> Result<models::ListDocumentOut, Error<LibrariesDocumentsListV1Error>> {
let p_path_library_id = library_id;
let p_query_search = search;
let p_query_page_size = page_size;
let p_query_page = page;
let p_query_filters_attributes = filters_attributes;
let p_query_sort_by = sort_by;
let p_query_sort_order = sort_order;
let uri_str = format!("{}/v1/libraries/{library_id}/documents", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref param_value) = p_query_search {
req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page_size {
req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_page {
req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_filters_attributes {
req_builder = req_builder.query(&[("filters_attributes", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_by {
req_builder = req_builder.query(&[("sort_by", ¶m_value.to_string())]);
}
if let Some(ref param_value) = p_query_sort_order {
req_builder = req_builder.query(&[("sort_order", ¶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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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::ListDocumentOut`"))),
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::ListDocumentOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsListV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_reprocess_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<(), Error<LibrariesDocumentsReprocessV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/reprocess", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
if !status.is_client_error() && !status.is_server_error() {
Ok(())
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsReprocessV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_update_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str, document_update_in: models::DocumentUpdateIn) -> Result<models::DocumentOut, Error<LibrariesDocumentsUpdateV1Error>> {
let p_path_library_id = library_id;
let p_path_document_id = document_id;
let p_body_document_update_in = document_update_in;
let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_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(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_body_document_update_in);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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::DocumentOut`"))),
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::DocumentOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsUpdateV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn libraries_documents_upload_v1(configuration: &configuration::Configuration, library_id: &str, file: std::path::PathBuf) -> Result<models::DocumentOut, Error<LibrariesDocumentsUploadV1Error>> {
let p_path_library_id = library_id;
let p_form_file = file;
let uri_str = format!("{}/v1/libraries/{library_id}/documents", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_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());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let mut multipart_form = reqwest::multipart::Form::new();
let file = TokioFile::open(&p_form_file).await?;
let stream = FramedRead::new(file, BytesCodec::new());
let file_name = p_form_file.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
multipart_form = multipart_form.part("file", file_part);
req_builder = req_builder.multipart(multipart_form);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.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?;
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::DocumentOut`"))),
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::DocumentOut`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<LibrariesDocumentsUploadV1Error> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}