1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16use tokio::fs::File as TokioFile;
17use tokio_util::codec::{BytesCodec, FramedRead};
18
19
20#[derive(Debug, Clone, Serialize, Deserialize)]
22#[serde(untagged)]
23pub enum LibrariesDocumentsDeleteV1Error {
24 Status422(models::HttpValidationError),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum LibrariesDocumentsGetExtractedTextSignedUrlV1Error {
32 Status422(models::HttpValidationError),
33 UnknownValue(serde_json::Value),
34}
35
36#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum LibrariesDocumentsGetSignedUrlV1Error {
40 Status422(models::HttpValidationError),
41 UnknownValue(serde_json::Value),
42}
43
44#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum LibrariesDocumentsGetStatusV1Error {
48 Status422(models::HttpValidationError),
49 UnknownValue(serde_json::Value),
50}
51
52#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum LibrariesDocumentsGetTextContentV1Error {
56 Status422(models::HttpValidationError),
57 UnknownValue(serde_json::Value),
58}
59
60#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum LibrariesDocumentsGetV1Error {
64 Status422(models::HttpValidationError),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum LibrariesDocumentsListV1Error {
72 Status422(models::HttpValidationError),
73 UnknownValue(serde_json::Value),
74}
75
76#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum LibrariesDocumentsReprocessV1Error {
80 Status422(models::HttpValidationError),
81 UnknownValue(serde_json::Value),
82}
83
84#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum LibrariesDocumentsUpdateV1Error {
88 Status422(models::HttpValidationError),
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum LibrariesDocumentsUploadV1Error {
96 Status422(models::HttpValidationError),
97 UnknownValue(serde_json::Value),
98}
99
100
101pub async fn libraries_documents_delete_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<(), Error<LibrariesDocumentsDeleteV1Error>> {
103 let p_path_library_id = library_id;
105 let p_path_document_id = document_id;
106
107 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
108 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
109
110 if let Some(ref user_agent) = configuration.user_agent {
111 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
112 }
113 if let Some(ref token) = configuration.bearer_access_token {
114 req_builder = req_builder.bearer_auth(token.to_owned());
115 };
116
117 let req = req_builder.build()?;
118 let resp = configuration.client.execute(req).await?;
119
120 let status = resp.status();
121
122 if !status.is_client_error() && !status.is_server_error() {
123 Ok(())
124 } else {
125 let content = resp.text().await?;
126 let entity: Option<LibrariesDocumentsDeleteV1Error> = serde_json::from_str(&content).ok();
127 Err(Error::ResponseError(ResponseContent { status, content, entity }))
128 }
129}
130
131pub async fn libraries_documents_get_extracted_text_signed_url_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<String, Error<LibrariesDocumentsGetExtractedTextSignedUrlV1Error>> {
133 let p_path_library_id = library_id;
135 let p_path_document_id = document_id;
136
137 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/extracted-text-signed-url", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
138 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
139
140 if let Some(ref user_agent) = configuration.user_agent {
141 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142 }
143 if let Some(ref token) = configuration.bearer_access_token {
144 req_builder = req_builder.bearer_auth(token.to_owned());
145 };
146
147 let req = req_builder.build()?;
148 let resp = configuration.client.execute(req).await?;
149
150 let status = resp.status();
151 let content_type = resp
152 .headers()
153 .get("content-type")
154 .and_then(|v| v.to_str().ok())
155 .unwrap_or("application/octet-stream");
156 let content_type = super::ContentType::from(content_type);
157
158 if !status.is_client_error() && !status.is_server_error() {
159 let content = resp.text().await?;
160 match content_type {
161 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
163 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
164 }
165 } else {
166 let content = resp.text().await?;
167 let entity: Option<LibrariesDocumentsGetExtractedTextSignedUrlV1Error> = serde_json::from_str(&content).ok();
168 Err(Error::ResponseError(ResponseContent { status, content, entity }))
169 }
170}
171
172pub async fn libraries_documents_get_signed_url_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<String, Error<LibrariesDocumentsGetSignedUrlV1Error>> {
174 let p_path_library_id = library_id;
176 let p_path_document_id = document_id;
177
178 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/signed-url", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
179 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
180
181 if let Some(ref user_agent) = configuration.user_agent {
182 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
183 }
184 if let Some(ref token) = configuration.bearer_access_token {
185 req_builder = req_builder.bearer_auth(token.to_owned());
186 };
187
188 let req = req_builder.build()?;
189 let resp = configuration.client.execute(req).await?;
190
191 let status = resp.status();
192 let content_type = resp
193 .headers()
194 .get("content-type")
195 .and_then(|v| v.to_str().ok())
196 .unwrap_or("application/octet-stream");
197 let content_type = super::ContentType::from(content_type);
198
199 if !status.is_client_error() && !status.is_server_error() {
200 let content = resp.text().await?;
201 match content_type {
202 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
203 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `String`"))),
204 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `String`")))),
205 }
206 } else {
207 let content = resp.text().await?;
208 let entity: Option<LibrariesDocumentsGetSignedUrlV1Error> = serde_json::from_str(&content).ok();
209 Err(Error::ResponseError(ResponseContent { status, content, entity }))
210 }
211}
212
213pub async fn libraries_documents_get_status_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<models::ProcessingStatusOut, Error<LibrariesDocumentsGetStatusV1Error>> {
215 let p_path_library_id = library_id;
217 let p_path_document_id = document_id;
218
219 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/status", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
220 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
221
222 if let Some(ref user_agent) = configuration.user_agent {
223 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
224 }
225 if let Some(ref token) = configuration.bearer_access_token {
226 req_builder = req_builder.bearer_auth(token.to_owned());
227 };
228
229 let req = req_builder.build()?;
230 let resp = configuration.client.execute(req).await?;
231
232 let status = resp.status();
233 let content_type = resp
234 .headers()
235 .get("content-type")
236 .and_then(|v| v.to_str().ok())
237 .unwrap_or("application/octet-stream");
238 let content_type = super::ContentType::from(content_type);
239
240 if !status.is_client_error() && !status.is_server_error() {
241 let content = resp.text().await?;
242 match content_type {
243 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ProcessingStatusOut`"))),
245 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ProcessingStatusOut`")))),
246 }
247 } else {
248 let content = resp.text().await?;
249 let entity: Option<LibrariesDocumentsGetStatusV1Error> = serde_json::from_str(&content).ok();
250 Err(Error::ResponseError(ResponseContent { status, content, entity }))
251 }
252}
253
254pub async fn libraries_documents_get_text_content_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<models::DocumentTextContent, Error<LibrariesDocumentsGetTextContentV1Error>> {
256 let p_path_library_id = library_id;
258 let p_path_document_id = document_id;
259
260 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/text_content", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
261 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
262
263 if let Some(ref user_agent) = configuration.user_agent {
264 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
265 }
266 if let Some(ref token) = configuration.bearer_access_token {
267 req_builder = req_builder.bearer_auth(token.to_owned());
268 };
269
270 let req = req_builder.build()?;
271 let resp = configuration.client.execute(req).await?;
272
273 let status = resp.status();
274 let content_type = resp
275 .headers()
276 .get("content-type")
277 .and_then(|v| v.to_str().ok())
278 .unwrap_or("application/octet-stream");
279 let content_type = super::ContentType::from(content_type);
280
281 if !status.is_client_error() && !status.is_server_error() {
282 let content = resp.text().await?;
283 match content_type {
284 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
285 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DocumentTextContent`"))),
286 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DocumentTextContent`")))),
287 }
288 } else {
289 let content = resp.text().await?;
290 let entity: Option<LibrariesDocumentsGetTextContentV1Error> = serde_json::from_str(&content).ok();
291 Err(Error::ResponseError(ResponseContent { status, content, entity }))
292 }
293}
294
295pub async fn libraries_documents_get_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<models::DocumentOut, Error<LibrariesDocumentsGetV1Error>> {
297 let p_path_library_id = library_id;
299 let p_path_document_id = document_id;
300
301 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
302 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
303
304 if let Some(ref user_agent) = configuration.user_agent {
305 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
306 }
307 if let Some(ref token) = configuration.bearer_access_token {
308 req_builder = req_builder.bearer_auth(token.to_owned());
309 };
310
311 let req = req_builder.build()?;
312 let resp = configuration.client.execute(req).await?;
313
314 let status = resp.status();
315 let content_type = resp
316 .headers()
317 .get("content-type")
318 .and_then(|v| v.to_str().ok())
319 .unwrap_or("application/octet-stream");
320 let content_type = super::ContentType::from(content_type);
321
322 if !status.is_client_error() && !status.is_server_error() {
323 let content = resp.text().await?;
324 match content_type {
325 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
326 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DocumentOut`"))),
327 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DocumentOut`")))),
328 }
329 } else {
330 let content = resp.text().await?;
331 let entity: Option<LibrariesDocumentsGetV1Error> = serde_json::from_str(&content).ok();
332 Err(Error::ResponseError(ResponseContent { status, content, entity }))
333 }
334}
335
336pub async fn libraries_documents_list_v1(configuration: &configuration::Configuration, library_id: &str, search: Option<&str>, page_size: Option<i32>, page: Option<i32>, filters_attributes: Option<&str>, sort_by: Option<&str>, sort_order: Option<&str>) -> Result<models::ListDocumentOut, Error<LibrariesDocumentsListV1Error>> {
338 let p_path_library_id = library_id;
340 let p_query_search = search;
341 let p_query_page_size = page_size;
342 let p_query_page = page;
343 let p_query_filters_attributes = filters_attributes;
344 let p_query_sort_by = sort_by;
345 let p_query_sort_order = sort_order;
346
347 let uri_str = format!("{}/v1/libraries/{library_id}/documents", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
348 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
349
350 if let Some(ref param_value) = p_query_search {
351 req_builder = req_builder.query(&[("search", ¶m_value.to_string())]);
352 }
353 if let Some(ref param_value) = p_query_page_size {
354 req_builder = req_builder.query(&[("page_size", ¶m_value.to_string())]);
355 }
356 if let Some(ref param_value) = p_query_page {
357 req_builder = req_builder.query(&[("page", ¶m_value.to_string())]);
358 }
359 if let Some(ref param_value) = p_query_filters_attributes {
360 req_builder = req_builder.query(&[("filters_attributes", ¶m_value.to_string())]);
361 }
362 if let Some(ref param_value) = p_query_sort_by {
363 req_builder = req_builder.query(&[("sort_by", ¶m_value.to_string())]);
364 }
365 if let Some(ref param_value) = p_query_sort_order {
366 req_builder = req_builder.query(&[("sort_order", ¶m_value.to_string())]);
367 }
368 if let Some(ref user_agent) = configuration.user_agent {
369 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
370 }
371 if let Some(ref token) = configuration.bearer_access_token {
372 req_builder = req_builder.bearer_auth(token.to_owned());
373 };
374
375 let req = req_builder.build()?;
376 let resp = configuration.client.execute(req).await?;
377
378 let status = resp.status();
379 let content_type = resp
380 .headers()
381 .get("content-type")
382 .and_then(|v| v.to_str().ok())
383 .unwrap_or("application/octet-stream");
384 let content_type = super::ContentType::from(content_type);
385
386 if !status.is_client_error() && !status.is_server_error() {
387 let content = resp.text().await?;
388 match content_type {
389 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
390 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListDocumentOut`"))),
391 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListDocumentOut`")))),
392 }
393 } else {
394 let content = resp.text().await?;
395 let entity: Option<LibrariesDocumentsListV1Error> = serde_json::from_str(&content).ok();
396 Err(Error::ResponseError(ResponseContent { status, content, entity }))
397 }
398}
399
400pub async fn libraries_documents_reprocess_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str) -> Result<(), Error<LibrariesDocumentsReprocessV1Error>> {
402 let p_path_library_id = library_id;
404 let p_path_document_id = document_id;
405
406 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}/reprocess", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
407 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
408
409 if let Some(ref user_agent) = configuration.user_agent {
410 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
411 }
412 if let Some(ref token) = configuration.bearer_access_token {
413 req_builder = req_builder.bearer_auth(token.to_owned());
414 };
415
416 let req = req_builder.build()?;
417 let resp = configuration.client.execute(req).await?;
418
419 let status = resp.status();
420
421 if !status.is_client_error() && !status.is_server_error() {
422 Ok(())
423 } else {
424 let content = resp.text().await?;
425 let entity: Option<LibrariesDocumentsReprocessV1Error> = serde_json::from_str(&content).ok();
426 Err(Error::ResponseError(ResponseContent { status, content, entity }))
427 }
428}
429
430pub async fn libraries_documents_update_v1(configuration: &configuration::Configuration, library_id: &str, document_id: &str, document_update_in: models::DocumentUpdateIn) -> Result<models::DocumentOut, Error<LibrariesDocumentsUpdateV1Error>> {
432 let p_path_library_id = library_id;
434 let p_path_document_id = document_id;
435 let p_body_document_update_in = document_update_in;
436
437 let uri_str = format!("{}/v1/libraries/{library_id}/documents/{document_id}", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id), document_id=crate::apis::urlencode(p_path_document_id));
438 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
439
440 if let Some(ref user_agent) = configuration.user_agent {
441 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
442 }
443 if let Some(ref token) = configuration.bearer_access_token {
444 req_builder = req_builder.bearer_auth(token.to_owned());
445 };
446 req_builder = req_builder.json(&p_body_document_update_in);
447
448 let req = req_builder.build()?;
449 let resp = configuration.client.execute(req).await?;
450
451 let status = resp.status();
452 let content_type = resp
453 .headers()
454 .get("content-type")
455 .and_then(|v| v.to_str().ok())
456 .unwrap_or("application/octet-stream");
457 let content_type = super::ContentType::from(content_type);
458
459 if !status.is_client_error() && !status.is_server_error() {
460 let content = resp.text().await?;
461 match content_type {
462 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
463 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DocumentOut`"))),
464 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DocumentOut`")))),
465 }
466 } else {
467 let content = resp.text().await?;
468 let entity: Option<LibrariesDocumentsUpdateV1Error> = serde_json::from_str(&content).ok();
469 Err(Error::ResponseError(ResponseContent { status, content, entity }))
470 }
471}
472
473pub async fn libraries_documents_upload_v1(configuration: &configuration::Configuration, library_id: &str, file: std::path::PathBuf) -> Result<models::DocumentOut, Error<LibrariesDocumentsUploadV1Error>> {
475 let p_path_library_id = library_id;
477 let p_form_file = file;
478
479 let uri_str = format!("{}/v1/libraries/{library_id}/documents", configuration.base_path, library_id=crate::apis::urlencode(p_path_library_id));
480 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
481
482 if let Some(ref user_agent) = configuration.user_agent {
483 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
484 }
485 if let Some(ref token) = configuration.bearer_access_token {
486 req_builder = req_builder.bearer_auth(token.to_owned());
487 };
488 let mut multipart_form = reqwest::multipart::Form::new();
489 let file = TokioFile::open(&p_form_file).await?;
490 let stream = FramedRead::new(file, BytesCodec::new());
491 let file_name = p_form_file.file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or_default();
492 let file_part = reqwest::multipart::Part::stream(reqwest::Body::wrap_stream(stream)).file_name(file_name);
493 multipart_form = multipart_form.part("file", file_part);
494 req_builder = req_builder.multipart(multipart_form);
495
496 let req = req_builder.build()?;
497 let resp = configuration.client.execute(req).await?;
498
499 let status = resp.status();
500 let content_type = resp
501 .headers()
502 .get("content-type")
503 .and_then(|v| v.to_str().ok())
504 .unwrap_or("application/octet-stream");
505 let content_type = super::ContentType::from(content_type);
506
507 if !status.is_client_error() && !status.is_server_error() {
508 let content = resp.text().await?;
509 match content_type {
510 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
511 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DocumentOut`"))),
512 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DocumentOut`")))),
513 }
514 } else {
515 let content = resp.text().await?;
516 let entity: Option<LibrariesDocumentsUploadV1Error> = serde_json::from_str(&content).ok();
517 Err(Error::ResponseError(ResponseContent { status, content, entity }))
518 }
519}
520