1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Attachments {
6 pub client: Client,
7}
8
9impl Attachments {
10 #[doc(hidden)]
11 pub fn new(client: Client) -> Self {
12 Self { client }
13 }
14
15 #[doc = "Download attachment\n\nDownload an attachment file.\n\n**Parameters:**\n\n- \
16 `attachment_link_id: &'astr`: The Attachment ID (required)\n\n```rust,no_run\nasync \
17 fn example_attachments_download() -> anyhow::Result<()> {\n let client = \
18 front_api::Client::new_from_env();\n let result: front_api::types::Attachment = \
19 client.attachments().download(\"some-string\").await?;\n println!(\"{:?}\", \
20 result);\n Ok(())\n}\n```"]
21 #[tracing::instrument]
22 pub async fn download<'a>(
23 &'a self,
24 attachment_link_id: &'a str,
25 ) -> Result<crate::types::Attachment, crate::types::error::Error> {
26 let mut req = self.client.client.request(
27 http::Method::GET,
28 &format!(
29 "{}/{}",
30 self.client.base_url,
31 "download/{attachment_link_id}"
32 .replace("{attachment_link_id}", attachment_link_id)
33 ),
34 );
35 req = req.bearer_auth(&self.client.token);
36 let resp = req.send().await?;
37 let status = resp.status();
38 if status.is_success() {
39 let text = resp.text().await.unwrap_or_default();
40 serde_json::from_str(&text).map_err(|err| {
41 crate::types::error::Error::from_serde_error(
42 format_serde_error::SerdeError::new(text.to_string(), err),
43 status,
44 )
45 })
46 } else {
47 Err(crate::types::error::Error::UnexpectedResponse(resp))
48 }
49 }
50}