1use crate::Client;
2use anyhow::Result;
3#[derive(Clone, Debug)]
4pub struct Config {
5 pub client: Client,
6}
7
8impl Config {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Self { client }
12 }
13
14 #[doc = "Perform a `GET` request to `/api/config/`.\n\nGet the application configuration\n\nSee <https://docs.paperless-ngx.com/configuration/|Application Configuration> for more information.\n\n```rust,no_run\nasync fn example_config_list() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: Vec<paperless_api_client::types::ApplicationConfiguration> = client.config().list().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
15 #[tracing::instrument]
16 #[allow(non_snake_case)]
17 pub async fn list<'a>(
18 &'a self,
19 ) -> Result<Vec<crate::types::ApplicationConfiguration>, crate::types::error::Error> {
20 let mut req = self.client.client.request(
21 http::Method::GET,
22 format!("{}/{}", self.client.base_url, "api/config/"),
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
44 #[doc = "Perform a `GET` request to `/api/config/{id}/`.\n\n**Parameters:**\n\n- `id: i64`: A unique integer value identifying this paperless application settings. (required)\n\n```rust,no_run\nasync fn example_config_retrieve() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::ApplicationConfiguration = client.config().retrieve(4 as i64).await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
45 #[tracing::instrument]
46 #[allow(non_snake_case)]
47 pub async fn retrieve<'a>(
48 &'a self,
49 id: i64,
50 ) -> Result<crate::types::ApplicationConfiguration, crate::types::error::Error> {
51 let mut req = self.client.client.request(
52 http::Method::GET,
53 format!(
54 "{}/{}",
55 self.client.base_url,
56 "api/config/{id}/".replace("{id}", &format!("{id}"))
57 ),
58 );
59 req = req.header("Authorization", format!("Token {}", &self.client.token));
60 let resp = req.send().await?;
61 let status = resp.status();
62 if status.is_success() {
63 let text = resp.text().await.unwrap_or_default();
64 serde_json::from_str(&text).map_err(|err| {
65 crate::types::error::Error::from_serde_error(
66 format_serde_error::SerdeError::new(text.to_string(), err),
67 status,
68 )
69 })
70 } else {
71 let text = resp.text().await.unwrap_or_default();
72 Err(crate::types::error::Error::Server {
73 body: text.to_string(),
74 status,
75 })
76 }
77 }
78
79 #[doc = "Perform a `PUT` request to `/api/config/{id}/`.\n\n**Parameters:**\n\n- `id: i64`: A unique integer value identifying this paperless application settings. (required)\n\n```rust,no_run\nasync fn example_config_update() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::ApplicationConfiguration = client\n .config()\n .update(\n 4 as i64,\n &paperless_api_client::types::ApplicationConfigurationRequest {\n user_args: Some(serde_json::Value::String(\"some-string\".to_string())),\n barcode_tag_mapping: Some(serde_json::Value::String(\"some-string\".to_string())),\n output_type: Some(paperless_api_client::types::OutputType::Pdfa2),\n pages: Some(4 as i64),\n language: Some(\"some-string\".to_string()),\n mode: Some(paperless_api_client::types::Mode::SkipNoarchive),\n skip_archive_file: Some(paperless_api_client::types::SkipArchiveFile::Always),\n image_dpi: Some(4 as i64),\n unpaper_clean: Some(paperless_api_client::types::UnpaperClean::None),\n deskew: Some(true),\n rotate_pages: Some(true),\n rotate_pages_threshold: Some(3.14 as f64),\n max_image_pixels: Some(3.14 as f64),\n color_conversion_strategy: Some(paperless_api_client::types::ColorConversionStrategy::Gray),\n app_title: Some(\"some-string\".to_string()),\n app_logo: Some(bytes::Bytes::from(\"some-string\")),\n barcodes_enabled: Some(true),\n barcode_enable_tiff_support: Some(true),\n barcode_string: Some(\"some-string\".to_string()),\n barcode_retain_split_pages: Some(true),\n barcode_enable_asn: Some(true),\n barcode_asn_prefix: Some(\"some-string\".to_string()),\n barcode_upscale: Some(3.14 as f64),\n barcode_dpi: Some(4 as i64),\n barcode_max_pages: Some(4 as i64),\n barcode_enable_tag: Some(true),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
80 #[tracing::instrument]
81 #[allow(non_snake_case)]
82 pub async fn update<'a>(
83 &'a self,
84 id: i64,
85 body: &crate::types::ApplicationConfigurationRequest,
86 ) -> Result<crate::types::ApplicationConfiguration, crate::types::error::Error> {
87 let mut req = self.client.client.request(
88 http::Method::PUT,
89 format!(
90 "{}/{}",
91 self.client.base_url,
92 "api/config/{id}/".replace("{id}", &format!("{id}"))
93 ),
94 );
95 req = req.header("Authorization", format!("Token {}", &self.client.token));
96 req = req.json(body);
97 let resp = req.send().await?;
98 let status = resp.status();
99 if status.is_success() {
100 let text = resp.text().await.unwrap_or_default();
101 serde_json::from_str(&text).map_err(|err| {
102 crate::types::error::Error::from_serde_error(
103 format_serde_error::SerdeError::new(text.to_string(), err),
104 status,
105 )
106 })
107 } else {
108 let text = resp.text().await.unwrap_or_default();
109 Err(crate::types::error::Error::Server {
110 body: text.to_string(),
111 status,
112 })
113 }
114 }
115
116 #[doc = "Perform a `DELETE` request to `/api/config/{id}/`.\n\n**Parameters:**\n\n- `id: i64`: A unique integer value identifying this paperless application settings. (required)\n\n```rust,no_run\nasync fn example_config_destroy() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n client.config().destroy(4 as i64).await?;\n Ok(())\n}\n```"]
117 #[tracing::instrument]
118 #[allow(non_snake_case)]
119 pub async fn destroy<'a>(&'a self, id: i64) -> Result<(), crate::types::error::Error> {
120 let mut req = self.client.client.request(
121 http::Method::DELETE,
122 format!(
123 "{}/{}",
124 self.client.base_url,
125 "api/config/{id}/".replace("{id}", &format!("{id}"))
126 ),
127 );
128 req = req.header("Authorization", format!("Token {}", &self.client.token));
129 let resp = req.send().await?;
130 let status = resp.status();
131 if status.is_success() {
132 Ok(())
133 } else {
134 let text = resp.text().await.unwrap_or_default();
135 Err(crate::types::error::Error::Server {
136 body: text.to_string(),
137 status,
138 })
139 }
140 }
141
142 #[doc = "Perform a `PATCH` request to `/api/config/{id}/`.\n\n**Parameters:**\n\n- `id: i64`: A unique integer value identifying this paperless application settings. (required)\n\n```rust,no_run\nasync fn example_config_partial_update() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::ApplicationConfiguration = client\n .config()\n .partial_update(\n 4 as i64,\n &paperless_api_client::types::PatchedApplicationConfigurationRequest {\n user_args: Some(serde_json::Value::String(\"some-string\".to_string())),\n barcode_tag_mapping: Some(serde_json::Value::String(\"some-string\".to_string())),\n output_type: Some(paperless_api_client::types::OutputType::Pdfa2),\n pages: Some(4 as i64),\n language: Some(\"some-string\".to_string()),\n mode: Some(paperless_api_client::types::Mode::SkipNoarchive),\n skip_archive_file: Some(paperless_api_client::types::SkipArchiveFile::Always),\n image_dpi: Some(4 as i64),\n unpaper_clean: Some(paperless_api_client::types::UnpaperClean::None),\n deskew: Some(true),\n rotate_pages: Some(true),\n rotate_pages_threshold: Some(3.14 as f64),\n max_image_pixels: Some(3.14 as f64),\n color_conversion_strategy: Some(paperless_api_client::types::ColorConversionStrategy::Gray),\n app_title: Some(\"some-string\".to_string()),\n app_logo: Some(bytes::Bytes::from(\"some-string\")),\n barcodes_enabled: Some(true),\n barcode_enable_tiff_support: Some(true),\n barcode_string: Some(\"some-string\".to_string()),\n barcode_retain_split_pages: Some(true),\n barcode_enable_asn: Some(true),\n barcode_asn_prefix: Some(\"some-string\".to_string()),\n barcode_upscale: Some(3.14 as f64),\n barcode_dpi: Some(4 as i64),\n barcode_max_pages: Some(4 as i64),\n barcode_enable_tag: Some(true),\n },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
143 #[tracing::instrument]
144 #[allow(non_snake_case)]
145 pub async fn partial_update<'a>(
146 &'a self,
147 id: i64,
148 body: &crate::types::PatchedApplicationConfigurationRequest,
149 ) -> Result<crate::types::ApplicationConfiguration, crate::types::error::Error> {
150 let mut req = self.client.client.request(
151 http::Method::PATCH,
152 format!(
153 "{}/{}",
154 self.client.base_url,
155 "api/config/{id}/".replace("{id}", &format!("{id}"))
156 ),
157 );
158 req = req.header("Authorization", format!("Token {}", &self.client.token));
159 req = req.json(body);
160 let resp = req.send().await?;
161 let status = resp.status();
162 if status.is_success() {
163 let text = resp.text().await.unwrap_or_default();
164 serde_json::from_str(&text).map_err(|err| {
165 crate::types::error::Error::from_serde_error(
166 format_serde_error::SerdeError::new(text.to_string(), err),
167 status,
168 )
169 })
170 } else {
171 let text = resp.text().await.unwrap_or_default();
172 Err(crate::types::error::Error::Server {
173 body: text.to_string(),
174 status,
175 })
176 }
177 }
178}