paperless_api_client/
trash.rs

1use crate::Client;
2use anyhow::Result;
3#[derive(Clone, Debug)]
4pub struct Trash {
5    pub client: Client,
6}
7
8impl Trash {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Self { client }
12    }
13
14    #[doc = "Perform a `GET` request to `/api/trash/`.\n\n**Parameters:**\n\n- `page: Option<i64>`: A page number within the paginated result set.\n- `page_size: Option<i64>`: Number of results to return per page.\n\n```rust,no_run\nasync fn example_trash_list() -> anyhow::Result<()> {\n    let client = paperless_api_client::Client::new_from_env();\n    client.trash().list(Some(4 as i64), Some(4 as i64)).await?;\n    Ok(())\n}\n```"]
15    #[tracing::instrument]
16    #[allow(non_snake_case)]
17    pub async fn list<'a>(
18        &'a self,
19        page: Option<i64>,
20        page_size: Option<i64>,
21    ) -> Result<(), crate::types::error::Error> {
22        let mut req = self.client.client.request(
23            http::Method::GET,
24            format!("{}/{}", self.client.base_url, "api/trash/"),
25        );
26        req = req.header("Authorization", format!("Token {}", &self.client.token));
27        let mut query_params = vec![];
28        if let Some(p) = page {
29            query_params.push(("page", format!("{p}")));
30        }
31
32        if let Some(p) = page_size {
33            query_params.push(("page_size", format!("{p}")));
34        }
35
36        req = req.query(&query_params);
37        let resp = req.send().await?;
38        let status = resp.status();
39        if status.is_success() {
40            Ok(())
41        } else {
42            let text = resp.text().await.unwrap_or_default();
43            Err(crate::types::error::Error::Server {
44                body: text.to_string(),
45                status,
46            })
47        }
48    }
49
50    #[doc = "Perform a `POST` request to `/api/trash/`.\n\n```rust,no_run\nasync fn example_trash_create() -> anyhow::Result<()> {\n    let client = paperless_api_client::Client::new_from_env();\n    client\n        .trash()\n        .create(&paperless_api_client::types::TrashRequest {\n            documents: Some(vec![4 as i64]),\n            action: paperless_api_client::types::TrashActionEnum::Empty,\n        })\n        .await?;\n    Ok(())\n}\n```"]
51    #[tracing::instrument]
52    #[allow(non_snake_case)]
53    pub async fn create<'a>(
54        &'a self,
55        body: &crate::types::TrashRequest,
56    ) -> Result<(), crate::types::error::Error> {
57        let mut req = self.client.client.request(
58            http::Method::POST,
59            format!("{}/{}", self.client.base_url, "api/trash/"),
60        );
61        req = req.header("Authorization", format!("Token {}", &self.client.token));
62        req = req.json(body);
63        let resp = req.send().await?;
64        let status = resp.status();
65        if status.is_success() {
66            Ok(())
67        } else {
68            let text = resp.text().await.unwrap_or_default();
69            Err(crate::types::error::Error::Server {
70                body: text.to_string(),
71                status,
72            })
73        }
74    }
75}