1use crate::Client;
2use anyhow::Result;
3#[derive(Clone, Debug)]
4pub struct Profile {
5 pub client: Client,
6}
7
8impl Profile {
9 #[doc(hidden)]
10 pub fn new(client: Client) -> Self {
11 Self { client }
12 }
13
14 #[doc = "Perform a `GET` request to `/api/profile/`.\n\nUser profile view, only available when logged in\n\n```rust,no_run\nasync fn example_profile_retrieve() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::Profile = client.profile().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::Profile, crate::types::error::Error> {
20 let mut req = self.client.client.request(
21 http::Method::GET,
22 format!("{}/{}", self.client.base_url, "api/profile/"),
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 `PATCH` request to `/api/profile/`.\n\nUser profile view, only available when logged in\n\n```rust,no_run\nasync fn example_profile_partial_update() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: paperless_api_client::types::Profile = client\n .profile()\n .partial_update(&paperless_api_client::types::PatchedProfileRequest {\n email: Some(\"email@example.com\".to_string()),\n password: Some(\"some-string\".to_string()),\n first_name: Some(\"some-string\".to_string()),\n last_name: Some(\"some-string\".to_string()),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
45 #[tracing::instrument]
46 #[allow(non_snake_case)]
47 pub async fn partial_update<'a>(
48 &'a self,
49 body: &crate::types::PatchedProfileRequest,
50 ) -> Result<crate::types::Profile, crate::types::error::Error> {
51 let mut req = self.client.client.request(
52 http::Method::PATCH,
53 format!("{}/{}", self.client.base_url, "api/profile/"),
54 );
55 req = req.header("Authorization", format!("Token {}", &self.client.token));
56 req = req.json(body);
57 let resp = req.send().await?;
58 let status = resp.status();
59 if status.is_success() {
60 let text = resp.text().await.unwrap_or_default();
61 serde_json::from_str(&text).map_err(|err| {
62 crate::types::error::Error::from_serde_error(
63 format_serde_error::SerdeError::new(text.to_string(), err),
64 status,
65 )
66 })
67 } else {
68 let text = resp.text().await.unwrap_or_default();
69 Err(crate::types::error::Error::Server {
70 body: text.to_string(),
71 status,
72 })
73 }
74 }
75
76 #[doc = "Perform a `POST` request to `/api/profile/disconnect_social_account/`.\n\nDisconnects a social account provider from the user account\n\n```rust,no_run\nasync fn example_profile_disconnect_social_account_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: i64 = client\n .profile()\n .disconnect_social_account_create(\n &paperless_api_client::types::ProfileDisconnectSocialAccountCreateRequestBody { id: 4 as i64 },\n )\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
77 #[tracing::instrument]
78 #[allow(non_snake_case)]
79 pub async fn disconnect_social_account_create<'a>(
80 &'a self,
81 body: &crate::types::ProfileDisconnectSocialAccountCreateRequestBody,
82 ) -> Result<i64, crate::types::error::Error> {
83 let mut req = self.client.client.request(
84 http::Method::POST,
85 format!(
86 "{}/{}",
87 self.client.base_url, "api/profile/disconnect_social_account/"
88 ),
89 );
90 req = req.header("Authorization", format!("Token {}", &self.client.token));
91 req = req.json(body);
92 let resp = req.send().await?;
93 let status = resp.status();
94 if status.is_success() {
95 let text = resp.text().await.unwrap_or_default();
96 serde_json::from_str(&text).map_err(|err| {
97 crate::types::error::Error::from_serde_error(
98 format_serde_error::SerdeError::new(text.to_string(), err),
99 status,
100 )
101 })
102 } else {
103 let text = resp.text().await.unwrap_or_default();
104 Err(crate::types::error::Error::Server {
105 body: text.to_string(),
106 status,
107 })
108 }
109 }
110
111 #[doc = "Perform a `POST` request to `/api/profile/generate_auth_token/`.\n\nGenerates (or re-generates) an auth token, requires a logged in user\nunlike the default DRF endpoint\n\n```rust,no_run\nasync fn example_profile_generate_auth_token_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: String = client.profile().generate_auth_token_create().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
112 #[tracing::instrument]
113 #[allow(non_snake_case)]
114 pub async fn generate_auth_token_create<'a>(
115 &'a self,
116 ) -> Result<String, crate::types::error::Error> {
117 let mut req = self.client.client.request(
118 http::Method::POST,
119 format!(
120 "{}/{}",
121 self.client.base_url, "api/profile/generate_auth_token/"
122 ),
123 );
124 req = req.header("Authorization", format!("Token {}", &self.client.token));
125 let resp = req.send().await?;
126 let status = resp.status();
127 if status.is_success() {
128 let text = resp.text().await.unwrap_or_default();
129 serde_json::from_str(&text).map_err(|err| {
130 crate::types::error::Error::from_serde_error(
131 format_serde_error::SerdeError::new(text.to_string(), err),
132 status,
133 )
134 })
135 } else {
136 let text = resp.text().await.unwrap_or_default();
137 Err(crate::types::error::Error::Server {
138 body: text.to_string(),
139 status,
140 })
141 }
142 }
143
144 #[doc = "Perform a `GET` request to `/api/profile/social_account_providers/`.\n\nList of social account providers\n\n```rust,no_run\nasync fn example_profile_social_account_providers_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.profile().social_account_providers_retrieve().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
145 #[tracing::instrument]
146 #[allow(non_snake_case)]
147 pub async fn social_account_providers_retrieve<'a>(
148 &'a self,
149 ) -> Result<std::collections::HashMap<String, serde_json::Value>, crate::types::error::Error>
150 {
151 let mut req = self.client.client.request(
152 http::Method::GET,
153 format!(
154 "{}/{}",
155 self.client.base_url, "api/profile/social_account_providers/"
156 ),
157 );
158 req = req.header("Authorization", format!("Token {}", &self.client.token));
159 let resp = req.send().await?;
160 let status = resp.status();
161 if status.is_success() {
162 let text = resp.text().await.unwrap_or_default();
163 serde_json::from_str(&text).map_err(|err| {
164 crate::types::error::Error::from_serde_error(
165 format_serde_error::SerdeError::new(text.to_string(), err),
166 status,
167 )
168 })
169 } else {
170 let text = resp.text().await.unwrap_or_default();
171 Err(crate::types::error::Error::Server {
172 body: text.to_string(),
173 status,
174 })
175 }
176 }
177
178 #[doc = "Perform a `GET` request to `/api/profile/totp/`.\n\nGenerates a new TOTP secret and returns the URL and SVG\n\n```rust,no_run\nasync fn example_profile_totp_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.profile().totp_retrieve().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
179 #[tracing::instrument]
180 #[allow(non_snake_case)]
181 pub async fn totp_retrieve<'a>(
182 &'a self,
183 ) -> Result<std::collections::HashMap<String, serde_json::Value>, crate::types::error::Error>
184 {
185 let mut req = self.client.client.request(
186 http::Method::GET,
187 format!("{}/{}", self.client.base_url, "api/profile/totp/"),
188 );
189 req = req.header("Authorization", format!("Token {}", &self.client.token));
190 let resp = req.send().await?;
191 let status = resp.status();
192 if status.is_success() {
193 let text = resp.text().await.unwrap_or_default();
194 serde_json::from_str(&text).map_err(|err| {
195 crate::types::error::Error::from_serde_error(
196 format_serde_error::SerdeError::new(text.to_string(), err),
197 status,
198 )
199 })
200 } else {
201 let text = resp.text().await.unwrap_or_default();
202 Err(crate::types::error::Error::Server {
203 body: text.to_string(),
204 status,
205 })
206 }
207 }
208
209 #[doc = "Perform a `POST` request to `/api/profile/totp/`.\n\nValidates a TOTP code and activates the TOTP authenticator\n\n```rust,no_run\nasync fn example_profile_totp_create() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: std::collections::HashMap<String, serde_json::Value> = client\n .profile()\n .totp_create(&paperless_api_client::types::ProfileTotpCreateRequestBody {\n secret: \"some-string\".to_string(),\n code: \"some-string\".to_string(),\n })\n .await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
210 #[tracing::instrument]
211 #[allow(non_snake_case)]
212 pub async fn totp_create<'a>(
213 &'a self,
214 body: &crate::types::ProfileTotpCreateRequestBody,
215 ) -> Result<std::collections::HashMap<String, serde_json::Value>, crate::types::error::Error>
216 {
217 let mut req = self.client.client.request(
218 http::Method::POST,
219 format!("{}/{}", self.client.base_url, "api/profile/totp/"),
220 );
221 req = req.header("Authorization", format!("Token {}", &self.client.token));
222 req = req.json(body);
223 let resp = req.send().await?;
224 let status = resp.status();
225 if status.is_success() {
226 let text = resp.text().await.unwrap_or_default();
227 serde_json::from_str(&text).map_err(|err| {
228 crate::types::error::Error::from_serde_error(
229 format_serde_error::SerdeError::new(text.to_string(), err),
230 status,
231 )
232 })
233 } else {
234 let text = resp.text().await.unwrap_or_default();
235 Err(crate::types::error::Error::Server {
236 body: text.to_string(),
237 status,
238 })
239 }
240 }
241
242 #[doc = "Perform a `DELETE` request to `/api/profile/totp/`.\n\nDeactivates the TOTP authenticator\n\n```rust,no_run\nasync fn example_profile_totp_destroy() -> anyhow::Result<()> {\n let client = paperless_api_client::Client::new_from_env();\n let result: bool = client.profile().totp_destroy().await?;\n println!(\"{:?}\", result);\n Ok(())\n}\n```"]
243 #[tracing::instrument]
244 #[allow(non_snake_case)]
245 pub async fn totp_destroy<'a>(&'a self) -> Result<bool, crate::types::error::Error> {
246 let mut req = self.client.client.request(
247 http::Method::DELETE,
248 format!("{}/{}", self.client.base_url, "api/profile/totp/"),
249 );
250 req = req.header("Authorization", format!("Token {}", &self.client.token));
251 let resp = req.send().await?;
252 let status = resp.status();
253 if status.is_success() {
254 let text = resp.text().await.unwrap_or_default();
255 serde_json::from_str(&text).map_err(|err| {
256 crate::types::error::Error::from_serde_error(
257 format_serde_error::SerdeError::new(text.to_string(), err),
258 status,
259 )
260 })
261 } else {
262 let text = resp.text().await.unwrap_or_default();
263 Err(crate::types::error::Error::Server {
264 body: text.to_string(),
265 status,
266 })
267 }
268 }
269}