Skip to main content

fattureincloud_rs/apis/
webhooks_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_webhooks_subscription`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateWebhooksSubscriptionError {
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_webhooks_subscription`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteWebhooksSubscriptionError {
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`get_webhooks_subscription`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum GetWebhooksSubscriptionError {
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`list_webhooks_subscriptions`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum ListWebhooksSubscriptionsError {
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`modify_webhooks_subscription`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ModifyWebhooksSubscriptionError {
50    UnknownValue(serde_json::Value),
51}
52
53
54/// Register some webhooks Subscriptions.
55pub async fn create_webhooks_subscription(configuration: &configuration::Configuration, company_id: i32, create_webhooks_subscription_request: Option<models::CreateWebhooksSubscriptionRequest>) -> Result<models::CreateWebhooksSubscriptionResponse, Error<CreateWebhooksSubscriptionError>> {
56    let local_var_configuration = configuration;
57
58    let local_var_client = &local_var_configuration.client;
59
60    let local_var_uri_str = format!("{}/c/{company_id}/subscriptions", local_var_configuration.base_path, company_id=company_id);
61    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
62
63    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
64        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
65    }
66    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
67        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
68    };
69    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
70        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
71    };
72    local_var_req_builder = local_var_req_builder.json(&create_webhooks_subscription_request);
73
74    let local_var_req = local_var_req_builder.build()?;
75    let local_var_resp = local_var_client.execute(local_var_req).await?;
76
77    let local_var_status = local_var_resp.status();
78    let local_var_content = local_var_resp.text().await?;
79
80    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
81        serde_json::from_str(&local_var_content).map_err(Error::from)
82    } else {
83        let local_var_entity: Option<CreateWebhooksSubscriptionError> = serde_json::from_str(&local_var_content).ok();
84        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
85        Err(Error::ResponseError(local_var_error))
86    }
87}
88
89/// Delete a webhooks subscription.
90pub async fn delete_webhooks_subscription(configuration: &configuration::Configuration, company_id: i32, subscription_id: &str) -> Result<(), Error<DeleteWebhooksSubscriptionError>> {
91    let local_var_configuration = configuration;
92
93    let local_var_client = &local_var_configuration.client;
94
95    let local_var_uri_str = format!("{}/c/{company_id}/subscriptions/{subscription_id}", local_var_configuration.base_path, company_id=company_id, subscription_id=crate::apis::urlencode(subscription_id));
96    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
97
98    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
99        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
100    }
101    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
102        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
103    };
104    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
105        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
106    };
107
108    let local_var_req = local_var_req_builder.build()?;
109    let local_var_resp = local_var_client.execute(local_var_req).await?;
110
111    let local_var_status = local_var_resp.status();
112    let local_var_content = local_var_resp.text().await?;
113
114    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
115        Ok(())
116    } else {
117        let local_var_entity: Option<DeleteWebhooksSubscriptionError> = serde_json::from_str(&local_var_content).ok();
118        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
119        Err(Error::ResponseError(local_var_error))
120    }
121}
122
123/// Get a webhooks subscription.
124pub async fn get_webhooks_subscription(configuration: &configuration::Configuration, company_id: i32, subscription_id: &str) -> Result<models::GetWebhooksSubscriptionResponse, Error<GetWebhooksSubscriptionError>> {
125    let local_var_configuration = configuration;
126
127    let local_var_client = &local_var_configuration.client;
128
129    let local_var_uri_str = format!("{}/c/{company_id}/subscriptions/{subscription_id}", local_var_configuration.base_path, company_id=company_id, subscription_id=crate::apis::urlencode(subscription_id));
130    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
131
132    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
133        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
134    }
135    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
136        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
137    };
138    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
139        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
140    };
141
142    let local_var_req = local_var_req_builder.build()?;
143    let local_var_resp = local_var_client.execute(local_var_req).await?;
144
145    let local_var_status = local_var_resp.status();
146    let local_var_content = local_var_resp.text().await?;
147
148    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
149        serde_json::from_str(&local_var_content).map_err(Error::from)
150    } else {
151        let local_var_entity: Option<GetWebhooksSubscriptionError> = serde_json::from_str(&local_var_content).ok();
152        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
153        Err(Error::ResponseError(local_var_error))
154    }
155}
156
157/// List active webhooks subscriptions.
158pub async fn list_webhooks_subscriptions(configuration: &configuration::Configuration, company_id: i32) -> Result<models::ListWebhooksSubscriptionsResponse, Error<ListWebhooksSubscriptionsError>> {
159    let local_var_configuration = configuration;
160
161    let local_var_client = &local_var_configuration.client;
162
163    let local_var_uri_str = format!("{}/c/{company_id}/subscriptions", local_var_configuration.base_path, company_id=company_id);
164    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
165
166    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
167        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
168    }
169    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
170        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
171    };
172    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
173        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
174    };
175
176    let local_var_req = local_var_req_builder.build()?;
177    let local_var_resp = local_var_client.execute(local_var_req).await?;
178
179    let local_var_status = local_var_resp.status();
180    let local_var_content = local_var_resp.text().await?;
181
182    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
183        serde_json::from_str(&local_var_content).map_err(Error::from)
184    } else {
185        let local_var_entity: Option<ListWebhooksSubscriptionsError> = serde_json::from_str(&local_var_content).ok();
186        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
187        Err(Error::ResponseError(local_var_error))
188    }
189}
190
191/// Edit a webhooks subscription.
192pub async fn modify_webhooks_subscription(configuration: &configuration::Configuration, company_id: i32, subscription_id: &str, modify_webhooks_subscription_request: Option<models::ModifyWebhooksSubscriptionRequest>) -> Result<models::CreateWebhooksSubscriptionRequest1, Error<ModifyWebhooksSubscriptionError>> {
193    let local_var_configuration = configuration;
194
195    let local_var_client = &local_var_configuration.client;
196
197    let local_var_uri_str = format!("{}/c/{company_id}/subscriptions/{subscription_id}", local_var_configuration.base_path, company_id=company_id, subscription_id=crate::apis::urlencode(subscription_id));
198    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
199
200    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
201        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
202    }
203    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
204        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
205    };
206    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
207        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
208    };
209    local_var_req_builder = local_var_req_builder.json(&modify_webhooks_subscription_request);
210
211    let local_var_req = local_var_req_builder.build()?;
212    let local_var_resp = local_var_client.execute(local_var_req).await?;
213
214    let local_var_status = local_var_resp.status();
215    let local_var_content = local_var_resp.text().await?;
216
217    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
218        serde_json::from_str(&local_var_content).map_err(Error::from)
219    } else {
220        let local_var_entity: Option<ModifyWebhooksSubscriptionError> = serde_json::from_str(&local_var_content).ok();
221        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
222        Err(Error::ResponseError(local_var_error))
223    }
224}
225