paperless_api_client/
status.rs

1use crate::Client;
2use anyhow::Result;
3#[derive(Clone, Debug)]
4pub struct Status {
5    pub client: Client,
6}
7
8impl Status {
9    #[doc(hidden)]
10    pub fn new(client: Client) -> Self {
11        Self { client }
12    }
13
14    #[doc = "Perform a `GET` request to `/api/status/`.\n\nGet the current system status of the Paperless-NGX server\n\n```rust,no_run\nasync fn example_status_retrieve() -> anyhow::Result<()> {\n    let client = paperless_api_client::Client::new_from_env();\n    let result: paperless_api_client::types::SystemStatus = client.status().retrieve().await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
15    #[tracing::instrument]
16    #[allow(non_snake_case)]
17    pub async fn retrieve<'a>(
18        &'a self,
19    ) -> Result<crate::types::SystemStatus, crate::types::error::Error> {
20        let mut req = self.client.client.request(
21            http::Method::GET,
22            format!("{}/{}", self.client.base_url, "api/status/"),
23        );
24        req = req.header("Authorization", format!("Token {}", &self.client.token));
25        let resp = req.send().await?;
26        let status = resp.status();
27        if status.is_success() {
28            let text = resp.text().await.unwrap_or_default();
29            serde_json::from_str(&text).map_err(|err| {
30                crate::types::error::Error::from_serde_error(
31                    format_serde_error::SerdeError::new(text.to_string(), err),
32                    status,
33                )
34            })
35        } else {
36            let text = resp.text().await.unwrap_or_default();
37            Err(crate::types::error::Error::Server {
38                body: text.to_string(),
39                status,
40            })
41        }
42    }
43}