Skip to main content

fattureincloud_rs/apis/
user_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 [`get_user_info`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetUserInfoError {
22    Status401(),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`list_user_companies`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum ListUserCompaniesError {
30    Status401(),
31    UnknownValue(serde_json::Value),
32}
33
34
35/// Gets the current user's info.
36pub async fn get_user_info(configuration: &configuration::Configuration, ) -> Result<models::GetUserInfoResponse, Error<GetUserInfoError>> {
37    let local_var_configuration = configuration;
38
39    let local_var_client = &local_var_configuration.client;
40
41    let local_var_uri_str = format!("{}/user/info", local_var_configuration.base_path);
42    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
43
44    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
45        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
46    }
47    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
48        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
49    };
50    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
51        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
52    };
53
54    let local_var_req = local_var_req_builder.build()?;
55    let local_var_resp = local_var_client.execute(local_var_req).await?;
56
57    let local_var_status = local_var_resp.status();
58    let local_var_content = local_var_resp.text().await?;
59
60    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
61        serde_json::from_str(&local_var_content).map_err(Error::from)
62    } else {
63        let local_var_entity: Option<GetUserInfoError> = serde_json::from_str(&local_var_content).ok();
64        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
65        Err(Error::ResponseError(local_var_error))
66    }
67}
68
69/// Lists the companies controlled by the current user.
70pub async fn list_user_companies(configuration: &configuration::Configuration, ) -> Result<models::ListUserCompaniesResponse, Error<ListUserCompaniesError>> {
71    let local_var_configuration = configuration;
72
73    let local_var_client = &local_var_configuration.client;
74
75    let local_var_uri_str = format!("{}/user/companies", local_var_configuration.base_path);
76    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
77
78    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
79        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
80    }
81    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
82        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
83    };
84    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
85        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
86    };
87
88    let local_var_req = local_var_req_builder.build()?;
89    let local_var_resp = local_var_client.execute(local_var_req).await?;
90
91    let local_var_status = local_var_resp.status();
92    let local_var_content = local_var_resp.text().await?;
93
94    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
95        serde_json::from_str(&local_var_content).map_err(Error::from)
96    } else {
97        let local_var_entity: Option<ListUserCompaniesError> = serde_json::from_str(&local_var_content).ok();
98        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
99        Err(Error::ResponseError(local_var_error))
100    }
101}
102