Skip to main content

late/apis/
webhooks_api.rs

1/*
2 * Zernio API
3 *
4 * API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api
5 *
6 * The version of the OpenAPI document: 1.0.1
7 * Contact: support@zernio.com
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`create_webhook_settings`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateWebhookSettingsError {
20    Status400(),
21    Status401(models::InlineObject),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`delete_webhook_settings`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum DeleteWebhookSettingsError {
29    Status400(),
30    Status401(models::InlineObject),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_webhook_settings`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetWebhookSettingsError {
38    Status401(models::InlineObject),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`test_webhook`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum TestWebhookError {
46    Status400(),
47    Status401(models::InlineObject),
48    Status500(models::UnpublishPost200Response),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`update_webhook_settings`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum UpdateWebhookSettingsError {
56    Status400(),
57    Status401(models::InlineObject),
58    Status404(),
59    UnknownValue(serde_json::Value),
60}
61
62/// Create a new webhook configuration. Maximum 10 webhooks per user.  `name`, `url` and `events` are required. `url` must be a valid URL and `events` must contain at least one event. Whitespace is trimmed from `url` before validation.  Webhooks are automatically disabled after 10 consecutive delivery failures.
63pub async fn create_webhook_settings(
64    configuration: &configuration::Configuration,
65    create_webhook_settings_request: models::CreateWebhookSettingsRequest,
66) -> Result<models::UpdateWebhookSettings200Response, Error<CreateWebhookSettingsError>> {
67    // add a prefix to parameters to efficiently prevent name collisions
68    let p_body_create_webhook_settings_request = create_webhook_settings_request;
69
70    let uri_str = format!("{}/v1/webhooks/settings", configuration.base_path);
71    let mut req_builder = configuration
72        .client
73        .request(reqwest::Method::POST, &uri_str);
74
75    if let Some(ref user_agent) = configuration.user_agent {
76        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
77    }
78    if let Some(ref token) = configuration.bearer_access_token {
79        req_builder = req_builder.bearer_auth(token.to_owned());
80    };
81    req_builder = req_builder.json(&p_body_create_webhook_settings_request);
82
83    let req = req_builder.build()?;
84    let resp = configuration.client.execute(req).await?;
85
86    let status = resp.status();
87    let content_type = resp
88        .headers()
89        .get("content-type")
90        .and_then(|v| v.to_str().ok())
91        .unwrap_or("application/octet-stream");
92    let content_type = super::ContentType::from(content_type);
93
94    if !status.is_client_error() && !status.is_server_error() {
95        let content = resp.text().await?;
96        match content_type {
97            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
98            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateWebhookSettings200Response`"))),
99            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UpdateWebhookSettings200Response`")))),
100        }
101    } else {
102        let content = resp.text().await?;
103        let entity: Option<CreateWebhookSettingsError> = serde_json::from_str(&content).ok();
104        Err(Error::ResponseError(ResponseContent {
105            status,
106            content,
107            entity,
108        }))
109    }
110}
111
112/// Permanently delete a webhook configuration.
113pub async fn delete_webhook_settings(
114    configuration: &configuration::Configuration,
115    id: &str,
116) -> Result<models::UpdateYoutubeDefaultPlaylist200Response, Error<DeleteWebhookSettingsError>> {
117    // add a prefix to parameters to efficiently prevent name collisions
118    let p_query_id = id;
119
120    let uri_str = format!("{}/v1/webhooks/settings", configuration.base_path);
121    let mut req_builder = configuration
122        .client
123        .request(reqwest::Method::DELETE, &uri_str);
124
125    req_builder = req_builder.query(&[("id", &p_query_id.to_string())]);
126    if let Some(ref user_agent) = configuration.user_agent {
127        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
128    }
129    if let Some(ref token) = configuration.bearer_access_token {
130        req_builder = req_builder.bearer_auth(token.to_owned());
131    };
132
133    let req = req_builder.build()?;
134    let resp = configuration.client.execute(req).await?;
135
136    let status = resp.status();
137    let content_type = resp
138        .headers()
139        .get("content-type")
140        .and_then(|v| v.to_str().ok())
141        .unwrap_or("application/octet-stream");
142    let content_type = super::ContentType::from(content_type);
143
144    if !status.is_client_error() && !status.is_server_error() {
145        let content = resp.text().await?;
146        match content_type {
147            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateYoutubeDefaultPlaylist200Response`"))),
149            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UpdateYoutubeDefaultPlaylist200Response`")))),
150        }
151    } else {
152        let content = resp.text().await?;
153        let entity: Option<DeleteWebhookSettingsError> = serde_json::from_str(&content).ok();
154        Err(Error::ResponseError(ResponseContent {
155            status,
156            content,
157            entity,
158        }))
159    }
160}
161
162/// Retrieve all configured webhooks for the authenticated user. Supports up to 10 webhooks per user.
163pub async fn get_webhook_settings(
164    configuration: &configuration::Configuration,
165) -> Result<models::GetWebhookSettings200Response, Error<GetWebhookSettingsError>> {
166    let uri_str = format!("{}/v1/webhooks/settings", configuration.base_path);
167    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
168
169    if let Some(ref user_agent) = configuration.user_agent {
170        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
171    }
172    if let Some(ref token) = configuration.bearer_access_token {
173        req_builder = req_builder.bearer_auth(token.to_owned());
174    };
175
176    let req = req_builder.build()?;
177    let resp = configuration.client.execute(req).await?;
178
179    let status = resp.status();
180    let content_type = resp
181        .headers()
182        .get("content-type")
183        .and_then(|v| v.to_str().ok())
184        .unwrap_or("application/octet-stream");
185    let content_type = super::ContentType::from(content_type);
186
187    if !status.is_client_error() && !status.is_server_error() {
188        let content = resp.text().await?;
189        match content_type {
190            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
191            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWebhookSettings200Response`"))),
192            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetWebhookSettings200Response`")))),
193        }
194    } else {
195        let content = resp.text().await?;
196        let entity: Option<GetWebhookSettingsError> = serde_json::from_str(&content).ok();
197        Err(Error::ResponseError(ResponseContent {
198            status,
199            content,
200            entity,
201        }))
202    }
203}
204
205/// Send a test webhook to verify your endpoint is configured correctly. The test payload includes event: \"webhook.test\" to distinguish it from real events.
206pub async fn test_webhook(
207    configuration: &configuration::Configuration,
208    test_webhook_request: models::TestWebhookRequest,
209) -> Result<models::UnpublishPost200Response, Error<TestWebhookError>> {
210    // add a prefix to parameters to efficiently prevent name collisions
211    let p_body_test_webhook_request = test_webhook_request;
212
213    let uri_str = format!("{}/v1/webhooks/test", configuration.base_path);
214    let mut req_builder = configuration
215        .client
216        .request(reqwest::Method::POST, &uri_str);
217
218    if let Some(ref user_agent) = configuration.user_agent {
219        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
220    }
221    if let Some(ref token) = configuration.bearer_access_token {
222        req_builder = req_builder.bearer_auth(token.to_owned());
223    };
224    req_builder = req_builder.json(&p_body_test_webhook_request);
225
226    let req = req_builder.build()?;
227    let resp = configuration.client.execute(req).await?;
228
229    let status = resp.status();
230    let content_type = resp
231        .headers()
232        .get("content-type")
233        .and_then(|v| v.to_str().ok())
234        .unwrap_or("application/octet-stream");
235    let content_type = super::ContentType::from(content_type);
236
237    if !status.is_client_error() && !status.is_server_error() {
238        let content = resp.text().await?;
239        match content_type {
240            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
241            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UnpublishPost200Response`"))),
242            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UnpublishPost200Response`")))),
243        }
244    } else {
245        let content = resp.text().await?;
246        let entity: Option<TestWebhookError> = serde_json::from_str(&content).ok();
247        Err(Error::ResponseError(ResponseContent {
248            status,
249            content,
250            entity,
251        }))
252    }
253}
254
255/// Update an existing webhook configuration. All fields except `_id` are optional; only provided fields will be updated.  When provided, `name` must be 1-50 characters, `url` must be a valid URL, and `events` must contain at least one event. Whitespace is trimmed from `url` before validation.  Webhooks are automatically disabled after 10 consecutive delivery failures.
256pub async fn update_webhook_settings(
257    configuration: &configuration::Configuration,
258    update_webhook_settings_request: models::UpdateWebhookSettingsRequest,
259) -> Result<models::UpdateWebhookSettings200Response, Error<UpdateWebhookSettingsError>> {
260    // add a prefix to parameters to efficiently prevent name collisions
261    let p_body_update_webhook_settings_request = update_webhook_settings_request;
262
263    let uri_str = format!("{}/v1/webhooks/settings", configuration.base_path);
264    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
265
266    if let Some(ref user_agent) = configuration.user_agent {
267        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
268    }
269    if let Some(ref token) = configuration.bearer_access_token {
270        req_builder = req_builder.bearer_auth(token.to_owned());
271    };
272    req_builder = req_builder.json(&p_body_update_webhook_settings_request);
273
274    let req = req_builder.build()?;
275    let resp = configuration.client.execute(req).await?;
276
277    let status = resp.status();
278    let content_type = resp
279        .headers()
280        .get("content-type")
281        .and_then(|v| v.to_str().ok())
282        .unwrap_or("application/octet-stream");
283    let content_type = super::ContentType::from(content_type);
284
285    if !status.is_client_error() && !status.is_server_error() {
286        let content = resp.text().await?;
287        match content_type {
288            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
289            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateWebhookSettings200Response`"))),
290            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::UpdateWebhookSettings200Response`")))),
291        }
292    } else {
293        let content = resp.text().await?;
294        let entity: Option<UpdateWebhookSettingsError> = serde_json::from_str(&content).ok();
295        Err(Error::ResponseError(ResponseContent {
296            status,
297            content,
298            entity,
299        }))
300    }
301}