Skip to main content

fattureincloud_rs/apis/
archive_api.rs

1/*
2 * Fatture in Cloud API v2 - API Reference
3 *
4 * Connect your software with Fatture in Cloud, the invoicing platform chosen by more than 500.000 businesses in Italy.   The Fatture in Cloud API is based on REST, and makes possible to interact with the user related data prior authorization via OAuth2 protocol.
5 *
6 * The version of the OpenAPI document: 2.0.32
7 * Contact: info@fattureincloud.it
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_archive_document`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateArchiveDocumentError {
22    Status401(),
23    Status404(),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`delete_archive_document`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum DeleteArchiveDocumentError {
31    Status401(),
32    Status404(),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`get_archive_document`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum GetArchiveDocumentError {
40    Status401(),
41    Status404(),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`list_archive_documents`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum ListArchiveDocumentsError {
49    Status401(),
50    Status404(),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`modify_archive_document`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ModifyArchiveDocumentError {
58    Status401(),
59    Status404(),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`upload_archive_document_attachment`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum UploadArchiveDocumentAttachmentError {
67    Status401(),
68    Status404(),
69    UnknownValue(serde_json::Value),
70}
71
72
73/// Creates a new archive document.
74pub async fn create_archive_document(configuration: &configuration::Configuration, company_id: i32, create_archive_document_request: Option<models::CreateArchiveDocumentRequest>) -> Result<models::CreateArchiveDocumentResponse, Error<CreateArchiveDocumentError>> {
75    let local_var_configuration = configuration;
76
77    let local_var_client = &local_var_configuration.client;
78
79    let local_var_uri_str = format!("{}/c/{company_id}/archive", local_var_configuration.base_path, company_id=company_id);
80    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
81
82    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
83        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
84    }
85    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
86        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
87    };
88    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
89        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
90    };
91    local_var_req_builder = local_var_req_builder.json(&create_archive_document_request);
92
93    let local_var_req = local_var_req_builder.build()?;
94    let local_var_resp = local_var_client.execute(local_var_req).await?;
95
96    let local_var_status = local_var_resp.status();
97    let local_var_content = local_var_resp.text().await?;
98
99    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
100        serde_json::from_str(&local_var_content).map_err(Error::from)
101    } else {
102        let local_var_entity: Option<CreateArchiveDocumentError> = serde_json::from_str(&local_var_content).ok();
103        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
104        Err(Error::ResponseError(local_var_error))
105    }
106}
107
108/// Deletes the specified archive document.
109pub async fn delete_archive_document(configuration: &configuration::Configuration, company_id: i32, document_id: i32) -> Result<(), Error<DeleteArchiveDocumentError>> {
110    let local_var_configuration = configuration;
111
112    let local_var_client = &local_var_configuration.client;
113
114    let local_var_uri_str = format!("{}/c/{company_id}/archive/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
115    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
116
117    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
118        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
119    }
120    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
121        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
122    };
123    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
124        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
125    };
126
127    let local_var_req = local_var_req_builder.build()?;
128    let local_var_resp = local_var_client.execute(local_var_req).await?;
129
130    let local_var_status = local_var_resp.status();
131    let local_var_content = local_var_resp.text().await?;
132
133    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
134        Ok(())
135    } else {
136        let local_var_entity: Option<DeleteArchiveDocumentError> = serde_json::from_str(&local_var_content).ok();
137        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
138        Err(Error::ResponseError(local_var_error))
139    }
140}
141
142/// Gets the specified archive document.
143pub async fn get_archive_document(configuration: &configuration::Configuration, company_id: i32, document_id: i32, fields: Option<&str>, fieldset: Option<&str>) -> Result<models::GetArchiveDocumentResponse, Error<GetArchiveDocumentError>> {
144    let local_var_configuration = configuration;
145
146    let local_var_client = &local_var_configuration.client;
147
148    let local_var_uri_str = format!("{}/c/{company_id}/archive/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
149    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
150
151    if let Some(ref local_var_str) = fields {
152        local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
153    }
154    if let Some(ref local_var_str) = fieldset {
155        local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
156    }
157    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
158        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
159    }
160    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
161        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
162    };
163    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
164        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
165    };
166
167    let local_var_req = local_var_req_builder.build()?;
168    let local_var_resp = local_var_client.execute(local_var_req).await?;
169
170    let local_var_status = local_var_resp.status();
171    let local_var_content = local_var_resp.text().await?;
172
173    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
174        serde_json::from_str(&local_var_content).map_err(Error::from)
175    } else {
176        let local_var_entity: Option<GetArchiveDocumentError> = serde_json::from_str(&local_var_content).ok();
177        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
178        Err(Error::ResponseError(local_var_error))
179    }
180}
181
182/// Lists the archive documents.
183pub async fn list_archive_documents(configuration: &configuration::Configuration, company_id: i32, fields: Option<&str>, fieldset: Option<&str>, sort: Option<&str>, page: Option<i32>, per_page: Option<u8>, q: Option<&str>) -> Result<models::ListArchiveDocumentsResponse, Error<ListArchiveDocumentsError>> {
184    let local_var_configuration = configuration;
185
186    let local_var_client = &local_var_configuration.client;
187
188    let local_var_uri_str = format!("{}/c/{company_id}/archive", local_var_configuration.base_path, company_id=company_id);
189    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
190
191    if let Some(ref local_var_str) = fields {
192        local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
193    }
194    if let Some(ref local_var_str) = fieldset {
195        local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
196    }
197    if let Some(ref local_var_str) = sort {
198        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
199    }
200    if let Some(ref local_var_str) = page {
201        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
202    }
203    if let Some(ref local_var_str) = per_page {
204        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
205    }
206    if let Some(ref local_var_str) = q {
207        local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
208    }
209    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
210        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
211    }
212    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
213        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
214    };
215    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
216        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
217    };
218
219    let local_var_req = local_var_req_builder.build()?;
220    let local_var_resp = local_var_client.execute(local_var_req).await?;
221
222    let local_var_status = local_var_resp.status();
223    let local_var_content = local_var_resp.text().await?;
224
225    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
226        serde_json::from_str(&local_var_content).map_err(Error::from)
227    } else {
228        let local_var_entity: Option<ListArchiveDocumentsError> = serde_json::from_str(&local_var_content).ok();
229        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
230        Err(Error::ResponseError(local_var_error))
231    }
232}
233
234/// Modifies the specified archive document.
235pub async fn modify_archive_document(configuration: &configuration::Configuration, company_id: i32, document_id: i32, modify_archive_document_request: Option<models::ModifyArchiveDocumentRequest>) -> Result<models::ModifyArchiveDocumentResponse, Error<ModifyArchiveDocumentError>> {
236    let local_var_configuration = configuration;
237
238    let local_var_client = &local_var_configuration.client;
239
240    let local_var_uri_str = format!("{}/c/{company_id}/archive/{document_id}", local_var_configuration.base_path, company_id=company_id, document_id=document_id);
241    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
242
243    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
244        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
245    }
246    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
247        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
248    };
249    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
250        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
251    };
252    local_var_req_builder = local_var_req_builder.json(&modify_archive_document_request);
253
254    let local_var_req = local_var_req_builder.build()?;
255    let local_var_resp = local_var_client.execute(local_var_req).await?;
256
257    let local_var_status = local_var_resp.status();
258    let local_var_content = local_var_resp.text().await?;
259
260    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
261        serde_json::from_str(&local_var_content).map_err(Error::from)
262    } else {
263        let local_var_entity: Option<ModifyArchiveDocumentError> = serde_json::from_str(&local_var_content).ok();
264        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
265        Err(Error::ResponseError(local_var_error))
266    }
267}
268
269/// Uploads an attachment destined to an archive document. The actual association between the document and the attachment must be implemented separately, using the returned token.
270pub async fn upload_archive_document_attachment(configuration: &configuration::Configuration, company_id: i32, filename: Option<&str>, attachment: Option<std::path::PathBuf>) -> Result<models::UploadArchiveAttachmentResponse, Error<UploadArchiveDocumentAttachmentError>> {
271    let local_var_configuration = configuration;
272
273    let local_var_client = &local_var_configuration.client;
274
275    let local_var_uri_str = format!("{}/c/{company_id}/archive/attachment", local_var_configuration.base_path, company_id=company_id);
276    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
277
278    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
279        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
280    }
281    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
282        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
283    };
284    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
285        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
286    };
287    let mut local_var_form = reqwest::multipart::Form::new();
288    if let Some(local_var_param_value) = filename {
289        local_var_form = local_var_form.text("filename", local_var_param_value.to_string());
290    }
291    // TODO: support file upload for 'attachment' parameter
292    local_var_req_builder = local_var_req_builder.multipart(local_var_form);
293
294    let local_var_req = local_var_req_builder.build()?;
295    let local_var_resp = local_var_client.execute(local_var_req).await?;
296
297    let local_var_status = local_var_resp.status();
298    let local_var_content = local_var_resp.text().await?;
299
300    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
301        serde_json::from_str(&local_var_content).map_err(Error::from)
302    } else {
303        let local_var_entity: Option<UploadArchiveDocumentAttachmentError> = serde_json::from_str(&local_var_content).ok();
304        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
305        Err(Error::ResponseError(local_var_error))
306    }
307}
308