paperless_api_client/
remote_version.rs

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