/*
* Mattermost API Reference
*
* There is also a work-in-progress [Postman API reference](https://documenter.getpostman.com/view/4508214/RW8FERUn).
*
* The version of the OpenAPI document: 4.0.0
* Contact: feedback@mattermost.com
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use super::ResponseContent;
use super::{Error, configuration};
/// struct for passing parameters to the method [`get_file`]
#[derive(Clone, Debug, Default)]
pub struct GetFileParams {
/// The ID of the file to get
pub file_id: String,
}
/// struct for passing parameters to the method [`get_file_info`]
#[derive(Clone, Debug, Default)]
pub struct GetFileInfoParams {
/// The ID of the file info to get
pub file_id: String,
}
/// struct for passing parameters to the method [`get_file_link`]
#[derive(Clone, Debug, Default)]
pub struct GetFileLinkParams {
/// The ID of the file to get a link for
pub file_id: String,
}
/// struct for passing parameters to the method [`get_file_preview`]
#[derive(Clone, Debug, Default)]
pub struct GetFilePreviewParams {
/// The ID of the file to get
pub file_id: String,
}
/// struct for passing parameters to the method [`get_file_public`]
#[derive(Clone, Debug, Default)]
pub struct GetFilePublicParams {
/// The ID of the file to get
pub file_id: String,
/// File hash
pub h: String,
}
/// struct for passing parameters to the method [`get_file_thumbnail`]
#[derive(Clone, Debug, Default)]
pub struct GetFileThumbnailParams {
/// The ID of the file to get
pub file_id: String,
}
/// struct for passing parameters to the method [`search_files`]
#[derive(Clone, Debug, Default)]
pub struct SearchFilesParams {
/// Team GUID
pub team_id: String,
/// The search terms as inputed by the user. To search for files from a user include `from:someusername`, using a user's username. To search in a specific channel include `in:somechannel`, using the channel name (not the display name). To search for specific extensions included `ext:extension`.
pub terms: String,
/// Set to true if an Or search should be performed vs an And search.
pub is_or_search: bool,
/// Offset from UTC of user timezone for date searches.
pub time_zone_offset: Option<i32>,
/// Set to true if deleted channels should be included in the search. (archived channels)
pub include_deleted_channels: Option<bool>,
/// The page to select. (Only works with Elasticsearch)
pub page: Option<i32>,
/// The number of posts per page. (Only works with Elasticsearch)
pub per_page: Option<i32>,
}
/// struct for passing parameters to the method [`upload_file`]
#[derive(Clone, Debug, Default)]
pub struct UploadFileParams {
/// The ID of the channel that this file will be uploaded to
pub channel_id: Option<String>,
/// The name of the file to be uploaded
pub filename: Option<String>,
/// A file to be uploaded
pub files: Option<std::path::PathBuf>,
/// The ID of the channel that this file will be uploaded to
pub channel_id2: Option<String>,
/// A unique identifier for the file that will be returned in the response
pub client_ids: Option<String>,
}
/// struct for typed errors of method [`get_file`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFileError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_info`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFileInfoError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_link`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFileLinkError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_preview`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFilePreviewError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_public`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFilePublicError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_file_thumbnail`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum GetFileThumbnailError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status404(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_files`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum SearchFilesError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`upload_file`]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(untagged)]
pub enum UploadFileError {
Status400(crate::openapi::models::AppError),
Status401(crate::openapi::models::AppError),
Status403(crate::openapi::models::AppError),
Status413(crate::openapi::models::AppError),
Status501(crate::openapi::models::AppError),
UnknownValue(serde_json::Value),
}
/// Gets a file that has been uploaded previously. ##### Permissions Must have `read_channel` permission or be uploader of the file.
pub async fn get_file(
configuration: &configuration::Configuration,
params: GetFileParams,
) -> Result<(), Error<GetFileError>> {
let local_var_configuration = configuration;
// unbox the parameters
let file_id = params.file_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/files/{file_id}",
local_var_configuration.base_path,
file_id = super::urlencode(file_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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<GetFileError> = 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))
}
}
/// Gets a file's info. ##### Permissions Must have `read_channel` permission or be uploader of the file.
pub async fn get_file_info(
configuration: &configuration::Configuration,
params: GetFileInfoParams,
) -> Result<crate::openapi::models::FileInfo, Error<GetFileInfoError>> {
let local_var_configuration = configuration;
// unbox the parameters
let file_id = params.file_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/files/{file_id}/info",
local_var_configuration.base_path,
file_id = super::urlencode(file_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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetFileInfoError> =
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))
}
}
/// Gets a public link for a file that can be accessed without logging into Mattermost. ##### Permissions Must have `read_channel` permission or be uploader of the file.
pub async fn get_file_link(
configuration: &configuration::Configuration,
params: GetFileLinkParams,
) -> Result<crate::openapi::models::GetFileLink200Response, Error<GetFileLinkError>> {
let local_var_configuration = configuration;
// unbox the parameters
let file_id = params.file_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/files/{file_id}/link",
local_var_configuration.base_path,
file_id = super::urlencode(file_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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<GetFileLinkError> =
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))
}
}
/// Gets a file's preview. ##### Permissions Must have `read_channel` permission or be uploader of the file.
pub async fn get_file_preview(
configuration: &configuration::Configuration,
params: GetFilePreviewParams,
) -> Result<(), Error<GetFilePreviewError>> {
let local_var_configuration = configuration;
// unbox the parameters
let file_id = params.file_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/files/{file_id}/preview",
local_var_configuration.base_path,
file_id = super::urlencode(file_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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<GetFilePreviewError> =
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))
}
}
/// ##### Permissions No permissions required.
pub async fn get_file_public(
configuration: &configuration::Configuration,
params: GetFilePublicParams,
) -> Result<(), Error<GetFilePublicError>> {
let local_var_configuration = configuration;
// unbox the parameters
let file_id = params.file_id;
let h = params.h;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/files/{file_id}/public",
local_var_configuration.base_path,
file_id = super::urlencode(file_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
local_var_req_builder = local_var_req_builder.query(&[("h", &h.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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<GetFilePublicError> =
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))
}
}
/// Gets a file's thumbnail. ##### Permissions Must have `read_channel` permission or be uploader of the file.
pub async fn get_file_thumbnail(
configuration: &configuration::Configuration,
params: GetFileThumbnailParams,
) -> Result<(), Error<GetFileThumbnailError>> {
let local_var_configuration = configuration;
// unbox the parameters
let file_id = params.file_id;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/files/{file_id}/thumbnail",
local_var_configuration.base_path,
file_id = super::urlencode(file_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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
Ok(())
} else {
let local_var_entity: Option<GetFileThumbnailError> =
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))
}
}
/// Search for files in a team based on file name, extention and file content (if file content extraction is enabled and supported for the files). __Minimum server version__: 5.34 ##### Permissions Must be authenticated and have the `view_team` permission.
pub async fn search_files(
configuration: &configuration::Configuration,
params: SearchFilesParams,
) -> Result<crate::openapi::models::FileInfoList, Error<SearchFilesError>> {
let local_var_configuration = configuration;
// unbox the parameters
let team_id = params.team_id;
let terms = params.terms;
let is_or_search = params.is_or_search;
let time_zone_offset = params.time_zone_offset;
let include_deleted_channels = params.include_deleted_channels;
let page = params.page;
let per_page = params.per_page;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!(
"{}/api/v4/teams/{team_id}/files/search",
local_var_configuration.base_path,
team_id = super::urlencode(team_id)
);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, 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 mut local_var_form = reqwest::multipart::Form::new();
local_var_form = local_var_form.text("terms", terms.to_string());
local_var_form = local_var_form.text("is_or_search", is_or_search.to_string());
if let Some(local_var_param_value) = time_zone_offset {
local_var_form = local_var_form.text("time_zone_offset", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = include_deleted_channels {
local_var_form = local_var_form.text(
"include_deleted_channels",
local_var_param_value.to_string(),
);
}
if let Some(local_var_param_value) = page {
local_var_form = local_var_form.text("page", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = per_page {
local_var_form = local_var_form.text("per_page", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.multipart(local_var_form);
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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<SearchFilesError> =
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))
}
}
/// Uploads a file that can later be attached to a post. This request can either be a multipart/form-data request with a channel_id, files and optional client_ids defined in the FormData, or it can be a request with the channel_id and filename defined as query parameters with the contents of a single file in the body of the request. Only multipart/form-data requests are supported by server versions up to and including 4.7. Server versions 4.8 and higher support both types of requests. ##### Permissions Must have `upload_file` permission.
pub async fn upload_file(
configuration: &configuration::Configuration,
params: UploadFileParams,
) -> Result<crate::openapi::models::UploadFile201Response, Error<UploadFileError>> {
let local_var_configuration = configuration;
// unbox the parameters
let channel_id = params.channel_id;
let filename = params.filename;
let _files = params.files;
let channel_id2 = params.channel_id2;
let client_ids = params.client_ids;
let local_var_client = &local_var_configuration.client;
let local_var_uri_str = format!("{}/api/v4/files", local_var_configuration.base_path);
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
if let Some(ref local_var_str) = channel_id {
local_var_req_builder =
local_var_req_builder.query(&[("channel_id", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = filename {
local_var_req_builder =
local_var_req_builder.query(&[("filename", &local_var_str.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 mut local_var_form = reqwest::multipart::Form::new();
// TODO: support file upload for 'files' parameter
if let Some(local_var_param_value) = channel_id2 {
local_var_form = local_var_form.text("channel_id", local_var_param_value.to_string());
}
if let Some(local_var_param_value) = client_ids {
local_var_form = local_var_form.text("client_ids", local_var_param_value.to_string());
}
local_var_req_builder = local_var_req_builder.multipart(local_var_form);
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 = local_var_resp.text().await?;
if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<UploadFileError> =
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))
}
}