paperless_api_client/
logs.rs1use crate::Client;
2use anyhow::Result;
3#[derive(Clone, Debug)]
4pub struct Logs {
5 pub client: Client,
6}
7
8impl Logs {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Self { client }
12 }
13
14 #[doc = "Perform a `GET` request to `/api/logs/`.\n\nLogs view\n\n```rust,no_run\nasync fn example_logs_list() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: Vec<String> = client.logs().list().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
15 #[tracing::instrument]
16 #[allow(non_snake_case)]
17 pub async fn list<'a>(&'a self) -> Result<Vec<String>, crate::types::error::Error> {
18 let mut req = self.client.client.request(
19 http::Method::GET,
20 format!("{}/{}", self.client.base_url, "api/logs/"),
21 );
22 req = req.header("Authorization", format!("Token {}", &self.client.token));
23 let resp = req.send().await?;
24 let status = resp.status();
25 if status.is_success() {
26 let text = resp.text().await.unwrap_or_default();
27 serde_json::from_str(&text).map_err(|err| {
28 crate::types::error::Error::from_serde_error(
29 format_serde_error::SerdeError::new(text.to_string(), err),
30 status,
31 )
32 })
33 } else {
34 let text = resp.text().await.unwrap_or_default();
35 Err(crate::types::error::Error::Server {
36 body: text.to_string(),
37 status,
38 })
39 }
40 }
41
42 #[doc = "Perform a `GET` request to `/api/logs/{id}/`.\n\nSingle log view\n\n**Parameters:**\n\n- `id: &'astr` (required)\n\n```rust,no_run\nasync fn example_logs_retrieve() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: Vec<String> = client.logs().retrieve(\"some-string\").await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
43 #[tracing::instrument]
44 #[allow(non_snake_case)]
45 pub async fn retrieve<'a>(
46 &'a self,
47 id: &'a str,
48 ) -> Result<Vec<String>, crate::types::error::Error> {
49 let mut req = self.client.client.request(
50 http::Method::GET,
51 format!(
52 "{}/{}",
53 self.client.base_url,
54 "api/logs/{id}/".replace("{id}", id)
55 ),
56 );
57 req = req.header("Authorization", format!("Token {}", &self.client.token));
58 let resp = req.send().await?;
59 let status = resp.status();
60 if status.is_success() {
61 let text = resp.text().await.unwrap_or_default();
62 serde_json::from_str(&text).map_err(|err| {
63 crate::types::error::Error::from_serde_error(
64 format_serde_error::SerdeError::new(text.to_string(), err),
65 status,
66 )
67 })
68 } else {
69 let text = resp.text().await.unwrap_or_default();
70 Err(crate::types::error::Error::Server {
71 body: text.to_string(),
72 status,
73 })
74 }
75 }
76}