Skip to main content

fattureincloud_rs/apis/
products_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_product`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateProductError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_product`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteProductError {
29    Status401(),
30    Status404(),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_product`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetProductError {
38    Status401(),
39    Status404(),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`list_products`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum ListProductsError {
47    Status401(),
48    UnknownValue(serde_json::Value),
49}
50
51/// struct for typed errors of method [`modify_product`]
52#[derive(Debug, Clone, Serialize, Deserialize)]
53#[serde(untagged)]
54pub enum ModifyProductError {
55    Status401(),
56    Status404(),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// Creates a new product.
62pub async fn create_product(configuration: &configuration::Configuration, company_id: i32, create_product_request: Option<models::CreateProductRequest>) -> Result<models::CreateProductResponse, Error<CreateProductError>> {
63    let local_var_configuration = configuration;
64
65    let local_var_client = &local_var_configuration.client;
66
67    let local_var_uri_str = format!("{}/c/{company_id}/products", local_var_configuration.base_path, company_id=company_id);
68    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
69
70    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
72    }
73    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
74        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
75    };
76    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
77        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
78    };
79    local_var_req_builder = local_var_req_builder.json(&create_product_request);
80
81    let local_var_req = local_var_req_builder.build()?;
82    let local_var_resp = local_var_client.execute(local_var_req).await?;
83
84    let local_var_status = local_var_resp.status();
85    let local_var_content = local_var_resp.text().await?;
86
87    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
88        serde_json::from_str(&local_var_content).map_err(Error::from)
89    } else {
90        let local_var_entity: Option<CreateProductError> = serde_json::from_str(&local_var_content).ok();
91        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
92        Err(Error::ResponseError(local_var_error))
93    }
94}
95
96/// Deletes the specified product.
97pub async fn delete_product(configuration: &configuration::Configuration, company_id: i32, product_id: i32) -> Result<(), Error<DeleteProductError>> {
98    let local_var_configuration = configuration;
99
100    let local_var_client = &local_var_configuration.client;
101
102    let local_var_uri_str = format!("{}/c/{company_id}/products/{product_id}", local_var_configuration.base_path, company_id=company_id, product_id=product_id);
103    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
104
105    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
106        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
107    }
108    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
109        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
110    };
111    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
112        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
113    };
114
115    let local_var_req = local_var_req_builder.build()?;
116    let local_var_resp = local_var_client.execute(local_var_req).await?;
117
118    let local_var_status = local_var_resp.status();
119    let local_var_content = local_var_resp.text().await?;
120
121    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
122        Ok(())
123    } else {
124        let local_var_entity: Option<DeleteProductError> = serde_json::from_str(&local_var_content).ok();
125        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
126        Err(Error::ResponseError(local_var_error))
127    }
128}
129
130/// Gets the specified product.
131pub async fn get_product(configuration: &configuration::Configuration, company_id: i32, product_id: i32, fields: Option<&str>, fieldset: Option<&str>) -> Result<models::GetProductResponse, Error<GetProductError>> {
132    let local_var_configuration = configuration;
133
134    let local_var_client = &local_var_configuration.client;
135
136    let local_var_uri_str = format!("{}/c/{company_id}/products/{product_id}", local_var_configuration.base_path, company_id=company_id, product_id=product_id);
137    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139    if let Some(ref local_var_str) = fields {
140        local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
141    }
142    if let Some(ref local_var_str) = fieldset {
143        local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
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        serde_json::from_str(&local_var_content).map_err(Error::from)
163    } else {
164        let local_var_entity: Option<GetProductError> = 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
170/// Lists the products.
171pub async fn list_products(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::ListProductsResponse, Error<ListProductsError>> {
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}/products", local_var_configuration.base_path, company_id=company_id);
177    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
178
179    if let Some(ref local_var_str) = fields {
180        local_var_req_builder = local_var_req_builder.query(&[("fields", &local_var_str.to_string())]);
181    }
182    if let Some(ref local_var_str) = fieldset {
183        local_var_req_builder = local_var_req_builder.query(&[("fieldset", &local_var_str.to_string())]);
184    }
185    if let Some(ref local_var_str) = sort {
186        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
187    }
188    if let Some(ref local_var_str) = page {
189        local_var_req_builder = local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
190    }
191    if let Some(ref local_var_str) = per_page {
192        local_var_req_builder = local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
193    }
194    if let Some(ref local_var_str) = q {
195        local_var_req_builder = local_var_req_builder.query(&[("q", &local_var_str.to_string())]);
196    }
197    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
198        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
199    }
200    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
201        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
202    };
203    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
204        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205    };
206
207    let local_var_req = local_var_req_builder.build()?;
208    let local_var_resp = local_var_client.execute(local_var_req).await?;
209
210    let local_var_status = local_var_resp.status();
211    let local_var_content = local_var_resp.text().await?;
212
213    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
214        serde_json::from_str(&local_var_content).map_err(Error::from)
215    } else {
216        let local_var_entity: Option<ListProductsError> = serde_json::from_str(&local_var_content).ok();
217        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
218        Err(Error::ResponseError(local_var_error))
219    }
220}
221
222/// Modifies the specified product.
223pub async fn modify_product(configuration: &configuration::Configuration, company_id: i32, product_id: i32, modify_product_request: Option<models::ModifyProductRequest>) -> Result<models::ModifyProductResponse, Error<ModifyProductError>> {
224    let local_var_configuration = configuration;
225
226    let local_var_client = &local_var_configuration.client;
227
228    let local_var_uri_str = format!("{}/c/{company_id}/products/{product_id}", local_var_configuration.base_path, company_id=company_id, product_id=product_id);
229    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
230
231    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
232        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
233    }
234    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
235        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
236    };
237    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
238        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
239    };
240    local_var_req_builder = local_var_req_builder.json(&modify_product_request);
241
242    let local_var_req = local_var_req_builder.build()?;
243    let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245    let local_var_status = local_var_resp.status();
246    let local_var_content = local_var_resp.text().await?;
247
248    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249        serde_json::from_str(&local_var_content).map_err(Error::from)
250    } else {
251        let local_var_entity: Option<ModifyProductError> = serde_json::from_str(&local_var_content).ok();
252        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
253        Err(Error::ResponseError(local_var_error))
254    }
255}
256