/*
* Asana
*
* This is the interface for interacting with the [Asana Platform](https://developers.asana.com). Our API reference is generated from our [OpenAPI spec] (https://raw.githubusercontent.com/Asana/developer-docs/master/defs/asana_oas.yaml).
*
* The version of the OpenAPI document: 1.0
*
* Generated by: https://openapi-generator.tech
*/
use reqwest;
use super::{configuration, Error};
use crate::apis::ResponseContent;
/// struct for typed errors of method `create_attachment_for_task`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CreateAttachmentForTaskError {
Status400(crate::models::ErrorResponse),
Status401(crate::models::ErrorResponse),
Status403(crate::models::ErrorResponse),
Status404(crate::models::ErrorResponse),
Status500(crate::models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `delete_attachment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteAttachmentError {
Status400(crate::models::ErrorResponse),
Status401(crate::models::ErrorResponse),
Status403(crate::models::ErrorResponse),
Status404(crate::models::ErrorResponse),
Status500(crate::models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `get_attachment`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAttachmentError {
Status400(crate::models::ErrorResponse),
Status401(crate::models::ErrorResponse),
Status402(crate::models::ErrorResponse),
Status403(crate::models::ErrorResponse),
Status404(crate::models::ErrorResponse),
Status424(crate::models::ErrorResponse),
Status500(crate::models::ErrorResponse),
Status501(crate::models::ErrorResponse),
Status503(crate::models::ErrorResponse),
Status504(crate::models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method `get_attachments_for_task`
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetAttachmentsForTaskError {
Status400(crate::models::ErrorResponse),
Status401(crate::models::ErrorResponse),
Status403(crate::models::ErrorResponse),
Status404(crate::models::ErrorResponse),
Status500(crate::models::ErrorResponse),
UnknownValue(serde_json::Value),
}
/// Upload an attachment. This method uploads an attachment to a task and returns the compact record for the created attachment object. It is not possible to attach files from third party services such as Dropbox, Box & Google Drive via the API. You must download the file content first and then upload it as any other attachment. The 100MB size limit on attachments in Asana is enforced on this endpoint. This endpoint expects a multipart/form-data encoded request containing the full contents of the file to be uploaded. Requests made should follow the HTTP/1.1 specification that line terminators are of the form `CRLF` or `\\r\\n` outlined [here](http://www.w3.org/Protocols/HTTP/1.1/draft-ietf-http-v11-spec-01#Basic-Rules) in order for the server to reliably and properly handle the request.
pub async fn create_attachment_for_task(
configuration: &configuration::Configuration,
task_gid: &str,
opt_pretty: Option<bool>,
opt_fields: Option<Vec<String>>,
limit: Option<i32>,
offset: Option<&str>,
_file: Option<std::path::PathBuf>,
) -> Result<crate::models::InlineResponse200, Error<CreateAttachmentForTaskError>>
{
let local_var_client = &configuration.client;
let local_var_uri_str = format!(
"{}/tasks/{task_gid}/attachments",
configuration.base_path,
task_gid = crate::apis::urlencode(task_gid)
);
let mut local_var_req_builder =
local_var_client.post(local_var_uri_str.as_str());
if let Some(ref local_var_str) = opt_pretty {
local_var_req_builder = local_var_req_builder
.query(&[("opt_pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = opt_fields {
local_var_req_builder = local_var_req_builder.query(&[(
"opt_fields",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_str) = limit {
local_var_req_builder = local_var_req_builder
.query(&[("limit", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = offset {
local_var_req_builder = local_var_req_builder
.query(&[("offset", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = 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) = configuration.oauth_access_token {
local_var_req_builder =
local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_token) = configuration.bearer_access_token {
local_var_req_builder =
local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
let local_var_form = reqwest::multipart::Form::new();
// TODO: support file upload for 'file' parameter
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<CreateAttachmentForTaskError> =
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))
}
}
/// Deletes a specific, existing attachment. Returns an empty data record.
pub async fn delete_attachment(
configuration: &configuration::Configuration,
attachment_gid: &str,
opt_pretty: Option<bool>,
opt_fields: Option<Vec<String>>,
) -> Result<crate::models::InlineResponse2001, Error<DeleteAttachmentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!(
"{}/attachments/{attachment_gid}",
configuration.base_path,
attachment_gid = crate::apis::urlencode(attachment_gid)
);
let mut local_var_req_builder =
local_var_client.delete(local_var_uri_str.as_str());
if let Some(ref local_var_str) = opt_pretty {
local_var_req_builder = local_var_req_builder
.query(&[("opt_pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = opt_fields {
local_var_req_builder = local_var_req_builder.query(&[(
"opt_fields",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_user_agent) = 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) = configuration.oauth_access_token {
local_var_req_builder =
local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_token) = 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<DeleteAttachmentError> =
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))
}
}
/// Get the full record for a single attachment.
pub async fn get_attachment(
configuration: &configuration::Configuration,
attachment_gid: &str,
opt_pretty: Option<bool>,
opt_fields: Option<Vec<String>>,
) -> Result<crate::models::InlineResponse200, Error<GetAttachmentError>> {
let local_var_client = &configuration.client;
let local_var_uri_str = format!(
"{}/attachments/{attachment_gid}",
configuration.base_path,
attachment_gid = crate::apis::urlencode(attachment_gid)
);
let mut local_var_req_builder =
local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = opt_pretty {
local_var_req_builder = local_var_req_builder
.query(&[("opt_pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = opt_fields {
local_var_req_builder = local_var_req_builder.query(&[(
"opt_fields",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_user_agent) = 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) = configuration.oauth_access_token {
local_var_req_builder =
local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_token) = 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<GetAttachmentError> =
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))
}
}
/// Returns the compact records for all attachments on the task.
pub async fn get_attachments_for_task(
configuration: &configuration::Configuration,
task_gid: &str,
opt_pretty: Option<bool>,
opt_fields: Option<Vec<String>>,
limit: Option<i32>,
offset: Option<&str>,
) -> Result<crate::models::InlineResponse2002, Error<GetAttachmentsForTaskError>>
{
let local_var_client = &configuration.client;
let local_var_uri_str = format!(
"{}/tasks/{task_gid}/attachments",
configuration.base_path,
task_gid = crate::apis::urlencode(task_gid)
);
let mut local_var_req_builder =
local_var_client.get(local_var_uri_str.as_str());
if let Some(ref local_var_str) = opt_pretty {
local_var_req_builder = local_var_req_builder
.query(&[("opt_pretty", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = opt_fields {
local_var_req_builder = local_var_req_builder.query(&[(
"opt_fields",
&local_var_str
.into_iter()
.map(|p| p.to_string())
.collect::<Vec<String>>()
.join(",")
.to_string(),
)]);
}
if let Some(ref local_var_str) = limit {
local_var_req_builder = local_var_req_builder
.query(&[("limit", &local_var_str.to_string())]);
}
if let Some(ref local_var_str) = offset {
local_var_req_builder = local_var_req_builder
.query(&[("offset", &local_var_str.to_string())]);
}
if let Some(ref local_var_user_agent) = 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) = configuration.oauth_access_token {
local_var_req_builder =
local_var_req_builder.bearer_auth(local_var_token.to_owned());
};
if let Some(ref local_var_token) = 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<GetAttachmentsForTaskError> =
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))
}
}