sendinblue_v3/apis/
webhooks_api.rs

1/*
2 * SendinBlue API
3 *
4 * SendinBlue provide a RESTFul API that can be used with any languages. With this API, you will be able to :   - Manage your campaigns and get the statistics   - Manage your contacts   - Send transactional Emails and SMS   - and much more...  You can download our wrappers at https://github.com/orgs/sendinblue  **Possible responses**   | Code | Message |   | :-------------: | ------------- |   | 200  | OK. Successful Request  |   | 201  | OK. Successful Creation |   | 202  | OK. Request accepted |   | 204  | OK. Successful Update/Deletion  |   | 400  | Error. Bad Request  |   | 401  | Error. Authentication Needed  |   | 402  | Error. Not enough credit, plan upgrade needed  |   | 403  | Error. Permission denied  |   | 404  | Error. Object does not exist |   | 405  | Error. Method not allowed  |   | 406  | Error. Not Acceptable  | 
5 *
6 * The version of the OpenAPI document: 3.0.0
7 * Contact: contact@sendinblue.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`create_webhook`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateWebhookError {
22    Status400(crate::models::ErrorModel),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_webhook`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteWebhookError {
30    Status404(crate::models::ErrorModel),
31    Status400(crate::models::ErrorModel),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method [`get_webhook`]
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum GetWebhookError {
39    Status404(crate::models::ErrorModel),
40    Status400(crate::models::ErrorModel),
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`get_webhooks`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum GetWebhooksError {
48    Status400(crate::models::ErrorModel),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`update_webhook`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum UpdateWebhookError {
56    Status400(crate::models::ErrorModel),
57    Status404(crate::models::ErrorModel),
58    UnknownValue(serde_json::Value),
59}
60
61
62pub async fn create_webhook(configuration: &configuration::Configuration, create_webhook: crate::models::CreateWebhook) -> Result<crate::models::CreateModel, Error<CreateWebhookError>> {
63    let local_var_configuration = configuration;
64
65    let local_var_client = &local_var_configuration.client;
66
67    let local_var_uri_str = format!("{}/webhooks", local_var_configuration.base_path);
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_apikey) = local_var_configuration.api_key {
74        let local_var_key = local_var_apikey.key.clone();
75        let local_var_value = match local_var_apikey.prefix {
76            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
77            None => local_var_key,
78        };
79        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
80    };
81    local_var_req_builder = local_var_req_builder.json(&create_webhook);
82
83    let local_var_req = local_var_req_builder.build()?;
84    let local_var_resp = local_var_client.execute(local_var_req).await?;
85
86    let local_var_status = local_var_resp.status();
87    let local_var_content = local_var_resp.text().await?;
88
89    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
90        serde_json::from_str(&local_var_content).map_err(Error::from)
91    } else {
92        let local_var_entity: Option<CreateWebhookError> = serde_json::from_str(&local_var_content).ok();
93        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
94        Err(Error::ResponseError(local_var_error))
95    }
96}
97
98pub async fn delete_webhook(configuration: &configuration::Configuration, webhook_id: i64) -> Result<(), Error<DeleteWebhookError>> {
99    let local_var_configuration = configuration;
100
101    let local_var_client = &local_var_configuration.client;
102
103    let local_var_uri_str = format!("{}/webhooks/{webhookId}", local_var_configuration.base_path, webhookId=webhook_id);
104    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
105
106    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
107        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
108    }
109    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
110        let local_var_key = local_var_apikey.key.clone();
111        let local_var_value = match local_var_apikey.prefix {
112            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
113            None => local_var_key,
114        };
115        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
116    };
117
118    let local_var_req = local_var_req_builder.build()?;
119    let local_var_resp = local_var_client.execute(local_var_req).await?;
120
121    let local_var_status = local_var_resp.status();
122    let local_var_content = local_var_resp.text().await?;
123
124    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
125        Ok(())
126    } else {
127        let local_var_entity: Option<DeleteWebhookError> = serde_json::from_str(&local_var_content).ok();
128        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
129        Err(Error::ResponseError(local_var_error))
130    }
131}
132
133pub async fn get_webhook(configuration: &configuration::Configuration, webhook_id: i64) -> Result<crate::models::GetWebhook, Error<GetWebhookError>> {
134    let local_var_configuration = configuration;
135
136    let local_var_client = &local_var_configuration.client;
137
138    let local_var_uri_str = format!("{}/webhooks/{webhookId}", local_var_configuration.base_path, webhookId=webhook_id);
139    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
140
141    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
142        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
143    }
144    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
145        let local_var_key = local_var_apikey.key.clone();
146        let local_var_value = match local_var_apikey.prefix {
147            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
148            None => local_var_key,
149        };
150        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
151    };
152
153    let local_var_req = local_var_req_builder.build()?;
154    let local_var_resp = local_var_client.execute(local_var_req).await?;
155
156    let local_var_status = local_var_resp.status();
157    let local_var_content = local_var_resp.text().await?;
158
159    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
160        serde_json::from_str(&local_var_content).map_err(Error::from)
161    } else {
162        let local_var_entity: Option<GetWebhookError> = serde_json::from_str(&local_var_content).ok();
163        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
164        Err(Error::ResponseError(local_var_error))
165    }
166}
167
168pub async fn get_webhooks(configuration: &configuration::Configuration, r#type: Option<&str>, sort: Option<&str>) -> Result<crate::models::GetWebhooks, Error<GetWebhooksError>> {
169    let local_var_configuration = configuration;
170
171    let local_var_client = &local_var_configuration.client;
172
173    let local_var_uri_str = format!("{}/webhooks", local_var_configuration.base_path);
174    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
175
176    if let Some(ref local_var_str) = r#type {
177        local_var_req_builder = local_var_req_builder.query(&[("type", &local_var_str.to_string())]);
178    }
179    if let Some(ref local_var_str) = sort {
180        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
181    }
182    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
183        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
184    }
185    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
186        let local_var_key = local_var_apikey.key.clone();
187        let local_var_value = match local_var_apikey.prefix {
188            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
189            None => local_var_key,
190        };
191        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
192    };
193
194    let local_var_req = local_var_req_builder.build()?;
195    let local_var_resp = local_var_client.execute(local_var_req).await?;
196
197    let local_var_status = local_var_resp.status();
198    let local_var_content = local_var_resp.text().await?;
199
200    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201        serde_json::from_str(&local_var_content).map_err(Error::from)
202    } else {
203        let local_var_entity: Option<GetWebhooksError> = serde_json::from_str(&local_var_content).ok();
204        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
205        Err(Error::ResponseError(local_var_error))
206    }
207}
208
209pub async fn update_webhook(configuration: &configuration::Configuration, webhook_id: i64, update_webhook: crate::models::UpdateWebhook) -> Result<(), Error<UpdateWebhookError>> {
210    let local_var_configuration = configuration;
211
212    let local_var_client = &local_var_configuration.client;
213
214    let local_var_uri_str = format!("{}/webhooks/{webhookId}", local_var_configuration.base_path, webhookId=webhook_id);
215    let mut local_var_req_builder = local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
216
217    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
218        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
219    }
220    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
221        let local_var_key = local_var_apikey.key.clone();
222        let local_var_value = match local_var_apikey.prefix {
223            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
224            None => local_var_key,
225        };
226        local_var_req_builder = local_var_req_builder.header("api-key", local_var_value);
227    };
228    local_var_req_builder = local_var_req_builder.json(&update_webhook);
229
230    let local_var_req = local_var_req_builder.build()?;
231    let local_var_resp = local_var_client.execute(local_var_req).await?;
232
233    let local_var_status = local_var_resp.status();
234    let local_var_content = local_var_resp.text().await?;
235
236    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237        Ok(())
238    } else {
239        let local_var_entity: Option<UpdateWebhookError> = serde_json::from_str(&local_var_content).ok();
240        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
241        Err(Error::ResponseError(local_var_error))
242    }
243}
244