1use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateReceivedDocumentError {
22 UnknownValue(serde_json::Value),
23}
24
25#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteReceivedDocumentError {
29 Status401(),
30 Status404(),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum DeleteReceivedDocumentAttachmentError {
38 Status401(),
39 Status404(),
40 UnknownValue(serde_json::Value),
41}
42
43#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetExistingReceivedDocumentTotalsError {
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum GetNewReceivedDocumentTotalsError {
54 Status401(),
55 Status404(),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum GetReceivedDocumentError {
63 Status401(),
64 Status404(),
65 UnknownValue(serde_json::Value),
66}
67
68#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum GetReceivedDocumentPreCreateInfoError {
72 UnknownValue(serde_json::Value),
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum ListReceivedDocumentsError {
79 Status401(),
80 UnknownValue(serde_json::Value),
81}
82
83#[derive(Debug, Clone, Serialize, Deserialize)]
85#[serde(untagged)]
86pub enum ModifyReceivedDocumentError {
87 Status401(),
88 Status404(),
89 UnknownValue(serde_json::Value),
90}
91
92#[derive(Debug, Clone, Serialize, Deserialize)]
94#[serde(untagged)]
95pub enum UploadReceivedDocumentAttachmentError {
96 Status401(),
97 UnknownValue(serde_json::Value),
98}
99
100
101pub async fn create_received_document(configuration: &configuration::Configuration, company_id: i32, create_received_document_request: Option<models::CreateReceivedDocumentRequest>) -> Result<models::CreateReceivedDocumentResponse, Error<CreateReceivedDocumentError>> {
103 let local_var_configuration = configuration;
104
105 let local_var_client = &local_var_configuration.client;
106
107 let local_var_uri_str = format!("{}/c/{company_id}/received_documents", local_var_configuration.base_path, company_id=company_id);
108 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
109
110 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
111 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112 }
113 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
114 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
115 };
116 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
117 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
118 };
119 local_var_req_builder = local_var_req_builder.json(&create_received_document_request);
120
121 let local_var_req = local_var_req_builder.build()?;
122 let local_var_resp = local_var_client.execute(local_var_req).await?;
123
124 let local_var_status = local_var_resp.status();
125 let local_var_content = local_var_resp.text().await?;
126
127 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
128 serde_json::from_str(&local_var_content).map_err(Error::from)
129 } else {
130 let local_var_entity: Option<CreateReceivedDocumentError> = serde_json::from_str(&local_var_content).ok();
131 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
132 Err(Error::ResponseError(local_var_error))
133 }
134}
135
136pub async fn delete_received_document(configuration: &configuration::Configuration, company_id: i32, document_id: i32) -> Result<(), Error<DeleteReceivedDocumentError>> {
138 let local_var_configuration = configuration;
139
140 let local_var_client = &local_var_configuration.client;
141
142 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
143 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
144
145 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
146 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
147 }
148 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
149 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
150 };
151 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
152 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
153 };
154
155 let local_var_req = local_var_req_builder.build()?;
156 let local_var_resp = local_var_client.execute(local_var_req).await?;
157
158 let local_var_status = local_var_resp.status();
159 let local_var_content = local_var_resp.text().await?;
160
161 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
162 Ok(())
163 } else {
164 let local_var_entity: Option<DeleteReceivedDocumentError> = serde_json::from_str(&local_var_content).ok();
165 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
166 Err(Error::ResponseError(local_var_error))
167 }
168}
169
170pub async fn delete_received_document_attachment(configuration: &configuration::Configuration, company_id: i32, document_id: i32) -> Result<(), Error<DeleteReceivedDocumentAttachmentError>> {
172 let local_var_configuration = configuration;
173
174 let local_var_client = &local_var_configuration.client;
175
176 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/{document_id}/attachment", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
177 let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
178
179 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
180 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
181 }
182 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
183 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
184 };
185 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
186 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
187 };
188
189 let local_var_req = local_var_req_builder.build()?;
190 let local_var_resp = local_var_client.execute(local_var_req).await?;
191
192 let local_var_status = local_var_resp.status();
193 let local_var_content = local_var_resp.text().await?;
194
195 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
196 Ok(())
197 } else {
198 let local_var_entity: Option<DeleteReceivedDocumentAttachmentError> = serde_json::from_str(&local_var_content).ok();
199 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
200 Err(Error::ResponseError(local_var_error))
201 }
202}
203
204pub async fn get_existing_received_document_totals(configuration: &configuration::Configuration, company_id: i32, document_id: i32, get_existing_received_document_totals: Option<models::GetExistingReceivedDocumentTotals>) -> Result<models::GetExistingReceivedDocumentTotalsResponse, Error<GetExistingReceivedDocumentTotalsError>> {
206 let local_var_configuration = configuration;
207
208 let local_var_client = &local_var_configuration.client;
209
210 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/{document_id}/totals", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
211 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
212
213 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
214 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
215 }
216 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
217 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
218 };
219 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
220 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
221 };
222 local_var_req_builder = local_var_req_builder.json(&get_existing_received_document_totals);
223
224 let local_var_req = local_var_req_builder.build()?;
225 let local_var_resp = local_var_client.execute(local_var_req).await?;
226
227 let local_var_status = local_var_resp.status();
228 let local_var_content = local_var_resp.text().await?;
229
230 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
231 serde_json::from_str(&local_var_content).map_err(Error::from)
232 } else {
233 let local_var_entity: Option<GetExistingReceivedDocumentTotalsError> = serde_json::from_str(&local_var_content).ok();
234 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
235 Err(Error::ResponseError(local_var_error))
236 }
237}
238
239pub async fn get_new_received_document_totals(configuration: &configuration::Configuration, company_id: i32, get_new_received_document_totals_request: Option<models::GetNewReceivedDocumentTotalsRequest>) -> Result<models::GetNewReceivedDocumentTotalsResponse, Error<GetNewReceivedDocumentTotalsError>> {
241 let local_var_configuration = configuration;
242
243 let local_var_client = &local_var_configuration.client;
244
245 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/totals", local_var_configuration.base_path, company_id=company_id);
246 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
247
248 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
249 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
250 }
251 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
252 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
253 };
254 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
255 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
256 };
257 local_var_req_builder = local_var_req_builder.json(&get_new_received_document_totals_request);
258
259 let local_var_req = local_var_req_builder.build()?;
260 let local_var_resp = local_var_client.execute(local_var_req).await?;
261
262 let local_var_status = local_var_resp.status();
263 let local_var_content = local_var_resp.text().await?;
264
265 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
266 serde_json::from_str(&local_var_content).map_err(Error::from)
267 } else {
268 let local_var_entity: Option<GetNewReceivedDocumentTotalsError> = serde_json::from_str(&local_var_content).ok();
269 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
270 Err(Error::ResponseError(local_var_error))
271 }
272}
273
274pub async fn get_received_document(configuration: &configuration::Configuration, company_id: i32, document_id: i32, fields: Option<&str>, fieldset: Option<&str>) -> Result<models::GetReceivedDocumentResponse, Error<GetReceivedDocumentError>> {
276 let local_var_configuration = configuration;
277
278 let local_var_client = &local_var_configuration.client;
279
280 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
281 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
282
283 if let Some(ref local_var_str) = fields {
284 local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
285 }
286 if let Some(ref local_var_str) = fieldset {
287 local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
288 }
289 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
290 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
291 }
292 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
293 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
294 };
295 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
296 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
297 };
298
299 let local_var_req = local_var_req_builder.build()?;
300 let local_var_resp = local_var_client.execute(local_var_req).await?;
301
302 let local_var_status = local_var_resp.status();
303 let local_var_content = local_var_resp.text().await?;
304
305 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
306 serde_json::from_str(&local_var_content).map_err(Error::from)
307 } else {
308 let local_var_entity: Option<GetReceivedDocumentError> = serde_json::from_str(&local_var_content).ok();
309 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
310 Err(Error::ResponseError(local_var_error))
311 }
312}
313
314pub async fn get_received_document_pre_create_info(configuration: &configuration::Configuration, company_id: i32, r#type: &str) -> Result<models::GetReceivedDocumentPreCreateInfoResponse, Error<GetReceivedDocumentPreCreateInfoError>> {
316 let local_var_configuration = configuration;
317
318 let local_var_client = &local_var_configuration.client;
319
320 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/info", local_var_configuration.base_path, company_id=company_id);
321 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
322
323 local_var_req_builder = local_var_req_builder.query(&[("type", &r#type.to_string())]);
324 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
325 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
326 }
327 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
328 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
329 };
330 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
331 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
332 };
333
334 let local_var_req = local_var_req_builder.build()?;
335 let local_var_resp = local_var_client.execute(local_var_req).await?;
336
337 let local_var_status = local_var_resp.status();
338 let local_var_content = local_var_resp.text().await?;
339
340 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
341 serde_json::from_str(&local_var_content).map_err(Error::from)
342 } else {
343 let local_var_entity: Option<GetReceivedDocumentPreCreateInfoError> = serde_json::from_str(&local_var_content).ok();
344 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
345 Err(Error::ResponseError(local_var_error))
346 }
347}
348
349pub async fn list_received_documents(configuration: &configuration::Configuration, company_id: i32, r#type: &str, fields: Option<&str>, fieldset: Option<&str>, sort: Option<&str>, page: Option<i32>, per_page: Option<u8>, q: Option<&str>) -> Result<models::ListReceivedDocumentsResponse, Error<ListReceivedDocumentsError>> {
351 let local_var_configuration = configuration;
352
353 let local_var_client = &local_var_configuration.client;
354
355 let local_var_uri_str = format!("{}/c/{company_id}/received_documents", local_var_configuration.base_path, company_id=company_id);
356 let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
357
358 local_var_req_builder = local_var_req_builder.query(&[("type", &r#type.to_string())]);
359 if let Some(ref local_var_str) = fields {
360 local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
361 }
362 if let Some(ref local_var_str) = fieldset {
363 local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
364 }
365 if let Some(ref local_var_str) = sort {
366 local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
367 }
368 if let Some(ref local_var_str) = page {
369 local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
370 }
371 if let Some(ref local_var_str) = per_page {
372 local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
373 }
374 if let Some(ref local_var_str) = q {
375 local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
376 }
377 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
378 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
379 }
380 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
381 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
382 };
383 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
384 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
385 };
386
387 let local_var_req = local_var_req_builder.build()?;
388 let local_var_resp = local_var_client.execute(local_var_req).await?;
389
390 let local_var_status = local_var_resp.status();
391 let local_var_content = local_var_resp.text().await?;
392
393 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
394 serde_json::from_str(&local_var_content).map_err(Error::from)
395 } else {
396 let local_var_entity: Option<ListReceivedDocumentsError> = serde_json::from_str(&local_var_content).ok();
397 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
398 Err(Error::ResponseError(local_var_error))
399 }
400}
401
402pub async fn modify_received_document(configuration: &configuration::Configuration, company_id: i32, document_id: i32, modify_received_document_request: Option<models::ModifyReceivedDocumentRequest>) -> Result<models::ModifyReceivedDocumentResponse, Error<ModifyReceivedDocumentError>> {
404 let local_var_configuration = configuration;
405
406 let local_var_client = &local_var_configuration.client;
407
408 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
409 let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
410
411 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
412 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
413 }
414 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
415 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
416 };
417 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
418 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
419 };
420 local_var_req_builder = local_var_req_builder.json(&modify_received_document_request);
421
422 let local_var_req = local_var_req_builder.build()?;
423 let local_var_resp = local_var_client.execute(local_var_req).await?;
424
425 let local_var_status = local_var_resp.status();
426 let local_var_content = local_var_resp.text().await?;
427
428 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
429 serde_json::from_str(&local_var_content).map_err(Error::from)
430 } else {
431 let local_var_entity: Option<ModifyReceivedDocumentError> = serde_json::from_str(&local_var_content).ok();
432 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
433 Err(Error::ResponseError(local_var_error))
434 }
435}
436
437pub async fn upload_received_document_attachment(configuration: &configuration::Configuration, company_id: i32, filename: Option<&str>, attachment: Option<std::path::PathBuf>) -> Result<models::UploadReceivedDocumentAttachmentResponse, Error<UploadReceivedDocumentAttachmentError>> {
439 let local_var_configuration = configuration;
440
441 let local_var_client = &local_var_configuration.client;
442
443 let local_var_uri_str = format!("{}/c/{company_id}/received_documents/attachment", local_var_configuration.base_path, company_id=company_id);
444 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
445
446 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
447 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
448 }
449 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
450 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
451 };
452 if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
453 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
454 };
455 let mut local_var_form = reqwest::multipart::Form::new();
456 if let Some(local_var_param_value) = filename {
457 local_var_form = local_var_form.text("filename", local_var_param_value.to_string());
458 }
459 local_var_req_builder = local_var_req_builder.multipart(local_var_form);
461
462 let local_var_req = local_var_req_builder.build()?;
463 let local_var_resp = local_var_client.execute(local_var_req).await?;
464
465 let local_var_status = local_var_resp.status();
466 let local_var_content = local_var_resp.text().await?;
467
468 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
469 serde_json::from_str(&local_var_content).map_err(Error::from)
470 } else {
471 let local_var_entity: Option<UploadReceivedDocumentAttachmentError> = serde_json::from_str(&local_var_content).ok();
472 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
473 Err(Error::ResponseError(local_var_error))
474 }
475}
476