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- `limit: Option<i64>`: Return only the last N entries from the log file\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\n .logs()\n .retrieve(\"some-string\", Some(4 as i64))\n .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 limit: Option<i64>,
49 ) -> Result<Vec<String>, crate::types::error::Error> {
50 let mut req = self.client.client.request(
51 http::Method::GET,
52 format!(
53 "{}/{}",
54 self.client.base_url,
55 "api/logs/{id}/".replace("{id}", id)
56 ),
57 );
58 req = req.header("Authorization", format!("Token {}", &self.client.token));
59 let mut query_params = vec![];
60 if let Some(p) = limit {
61 query_params.push(("limit", format!("{p}")));
62 }
63
64 req = req.query(&query_params);
65 let resp = req.send().await?;
66 let status = resp.status();
67 if status.is_success() {
68 let text = resp.text().await.unwrap_or_default();
69 serde_json::from_str(&text).map_err(|err| {
70 crate::types::error::Error::from_serde_error(
71 format_serde_error::SerdeError::new(text.to_string(), err),
72 status,
73 )
74 })
75 } else {
76 let text = resp.text().await.unwrap_or_default();
77 Err(crate::types::error::Error::Server {
78 body: text.to_string(),
79 status,
80 })
81 }
82 }
83}