Skip to main content

hook0_client/generated/
api.rs

1// Generated by hook0-sdkgen from the OpenAPI snapshot the API crate commits.
2// Do not edit by hand: run `UPDATE_SDK=rust cargo test -p hook0-sdkgen sdk_targets` and commit the result.
3//! One method per operation the API declares, grouped by the entity its operation id
4//! names, and the seam every one of them is issued through.
5//!
6//! How many arguments a method takes is the document's business rather than this crate's:
7//! an operation declaring a dozen parameters is asked for with a dozen arguments.
8#![allow(clippy::too_many_arguments)]
9
10use super::errors::RequestError;
11use super::errors::problem_for;
12use super::models::Application;
13use super::models::ApplicationInfo;
14use super::models::ApplicationPost;
15use super::models::ApplicationSecret;
16use super::models::ApplicationSecretPost;
17use super::models::Event;
18use super::models::EventPost;
19use super::models::EventType;
20use super::models::EventTypePost;
21use super::models::EventWithPayload;
22use super::models::EventsPerDayEntry;
23use super::models::IngestedEvent;
24use super::models::InstanceConfig;
25use super::models::Problem;
26use super::models::QuotasResponse;
27use super::models::ReplayEvent;
28use super::models::RequestAttempt;
29use super::models::Response;
30use super::models::ServiceToken;
31use super::models::ServiceTokenPost;
32use super::models::Subscription;
33use super::models::SubscriptionPost;
34
35/// What a generated method issues its request through.
36///
37/// It is declared here rather than imported: the half of this crate that reaches the
38/// network is hand-written and implements it, so neither half has to name what the other
39/// declares, and nothing here carries a socket.
40pub trait Transport {
41    /// What this transport reports when it could not reach the API at all.
42    type Error: std::error::Error + Send + Sync + 'static;
43
44    /// Issues one request, answering the status the API replied with and the body it sent.
45    fn request(
46        &self,
47        method: &str,
48        path: &str,
49        query: &[(&str, String)],
50        body: Option<Vec<u8>>,
51    ) -> impl std::future::Future<Output = Result<(u16, Vec<u8>), Self::Error>> + Send;
52}
53
54/// Writes a value the way a request line carries it, which is not always how it
55/// is printed.
56fn query_value(value: &dyn std::fmt::Display) -> String {
57    value.to_string()
58}
59
60/// Writes a value as one segment of a path, with nothing left in it that could
61/// name another one.
62fn path_segment(value: &dyn std::fmt::Display) -> String {
63    let rendered = query_value(value);
64    let mut escaped = String::with_capacity(rendered.len());
65
66    for byte in rendered.bytes() {
67        let bare = byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'.' | b'_' | b'~');
68        if bare {
69            escaped.push(char::from(byte));
70        } else {
71            escaped.push_str(&format!("%{byte:02X}"));
72        }
73    }
74
75    escaped
76}
77
78/// What the API declares under `applicationSecrets`.
79///
80/// Every method of it is issued through the transport it is handed.
81#[derive(Debug, Clone)]
82pub struct ApplicationSecretsApi<T> {
83    transport: T,
84}
85
86impl<T: Transport> ApplicationSecretsApi<T> {
87    /// Reaches what the API declares under `applicationSecrets`.
88    pub fn new(transport: T) -> Self {
89        Self { transport }
90    }
91
92    /// `applicationSecrets.create`, `POST /api/v1/application_secrets/`.
93    ///
94    /// Create a new application secret
95    pub async fn create(
96        &self,
97        body: ApplicationSecretPost,
98    ) -> Result<ApplicationSecret, RequestError> {
99        let path = "/api/v1/application_secrets/".to_owned();
100        let query: Vec<(&str, String)> = Vec::new();
101        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
102        let issued = self.transport.request("POST", &path, &query, Some(body));
103        let (status, payload) = issued.await.map_err(RequestError::transport)?;
104
105        if let Some(failure) = problem_for(status, &payload) {
106            return Err(RequestError::Api(Box::new(failure)));
107        }
108
109        let read = serde_json::from_slice(&payload);
110        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
111    }
112
113    /// `applicationSecrets.delete`, `DELETE /api/v1/application_secrets/{application_secret_token}`.
114    ///
115    /// Delete an application secret
116    pub async fn delete(
117        &self,
118        application_secret_token: &str,
119        application_id: &str,
120    ) -> Result<(), RequestError> {
121        let mut path = "/api/v1/application_secrets/{application_secret_token}".to_owned();
122        path = path.replace(
123            "{application_secret_token}",
124            &path_segment(&application_secret_token),
125        );
126        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
127        let issued = self.transport.request("DELETE", &path, &query, None);
128        let (status, payload) = issued.await.map_err(RequestError::transport)?;
129
130        if let Some(failure) = problem_for(status, &payload) {
131            return Err(RequestError::Api(Box::new(failure)));
132        }
133
134        Ok(())
135    }
136
137    /// `applicationSecrets.read`, `GET /api/v1/application_secrets/`.
138    ///
139    /// List application secrets
140    pub async fn read(&self, application_id: &str) -> Result<Vec<ApplicationSecret>, RequestError> {
141        let path = "/api/v1/application_secrets/".to_owned();
142        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
143        let issued = self.transport.request("GET", &path, &query, None);
144        let (status, payload) = issued.await.map_err(RequestError::transport)?;
145
146        if let Some(failure) = problem_for(status, &payload) {
147            return Err(RequestError::Api(Box::new(failure)));
148        }
149
150        let read = serde_json::from_slice(&payload);
151        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
152    }
153
154    /// `applicationSecrets.update`, `PUT /api/v1/application_secrets/{application_secret_token}`.
155    ///
156    /// Update an application secret
157    pub async fn update(
158        &self,
159        application_secret_token: &str,
160        body: ApplicationSecretPost,
161    ) -> Result<ApplicationSecret, RequestError> {
162        let mut path = "/api/v1/application_secrets/{application_secret_token}".to_owned();
163        path = path.replace(
164            "{application_secret_token}",
165            &path_segment(&application_secret_token),
166        );
167        let query: Vec<(&str, String)> = Vec::new();
168        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
169        let issued = self.transport.request("PUT", &path, &query, Some(body));
170        let (status, payload) = issued.await.map_err(RequestError::transport)?;
171
172        if let Some(failure) = problem_for(status, &payload) {
173            return Err(RequestError::Api(Box::new(failure)));
174        }
175
176        let read = serde_json::from_slice(&payload);
177        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
178    }
179}
180
181/// What the API declares under `applications`.
182///
183/// Every method of it is issued through the transport it is handed.
184#[derive(Debug, Clone)]
185pub struct ApplicationsApi<T> {
186    transport: T,
187}
188
189impl<T: Transport> ApplicationsApi<T> {
190    /// Reaches what the API declares under `applications`.
191    pub fn new(transport: T) -> Self {
192        Self { transport }
193    }
194
195    /// `applications.create`, `POST /api/v1/applications/`.
196    ///
197    /// Create a new application
198    pub async fn create(&self, body: ApplicationPost) -> Result<Application, RequestError> {
199        let path = "/api/v1/applications/".to_owned();
200        let query: Vec<(&str, String)> = Vec::new();
201        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
202        let issued = self.transport.request("POST", &path, &query, Some(body));
203        let (status, payload) = issued.await.map_err(RequestError::transport)?;
204
205        if let Some(failure) = problem_for(status, &payload) {
206            return Err(RequestError::Api(Box::new(failure)));
207        }
208
209        let read = serde_json::from_slice(&payload);
210        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
211    }
212
213    /// `applications.delete`, `DELETE /api/v1/applications/{application_id}`.
214    ///
215    /// Delete an application
216    pub async fn delete(&self, application_id: &str) -> Result<(), RequestError> {
217        let mut path = "/api/v1/applications/{application_id}".to_owned();
218        path = path.replace("{application_id}", &path_segment(&application_id));
219        let query: Vec<(&str, String)> = Vec::new();
220        let issued = self.transport.request("DELETE", &path, &query, None);
221        let (status, payload) = issued.await.map_err(RequestError::transport)?;
222
223        if let Some(failure) = problem_for(status, &payload) {
224            return Err(RequestError::Api(Box::new(failure)));
225        }
226
227        Ok(())
228    }
229
230    /// `applications.get`, `GET /api/v1/applications/{application_id}`.
231    ///
232    /// Get an application by its ID
233    pub async fn get(&self, application_id: &str) -> Result<ApplicationInfo, RequestError> {
234        let mut path = "/api/v1/applications/{application_id}".to_owned();
235        path = path.replace("{application_id}", &path_segment(&application_id));
236        let query: Vec<(&str, String)> = Vec::new();
237        let issued = self.transport.request("GET", &path, &query, None);
238        let (status, payload) = issued.await.map_err(RequestError::transport)?;
239
240        if let Some(failure) = problem_for(status, &payload) {
241            return Err(RequestError::Api(Box::new(failure)));
242        }
243
244        let read = serde_json::from_slice(&payload);
245        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
246    }
247
248    /// `applications.list`, `GET /api/v1/applications/`.
249    ///
250    /// List applications
251    pub async fn list(&self, organization_id: &str) -> Result<Vec<Application>, RequestError> {
252        let path = "/api/v1/applications/".to_owned();
253        let query: Vec<(&str, String)> = vec![("organization_id", query_value(&organization_id))];
254        let issued = self.transport.request("GET", &path, &query, None);
255        let (status, payload) = issued.await.map_err(RequestError::transport)?;
256
257        if let Some(failure) = problem_for(status, &payload) {
258            return Err(RequestError::Api(Box::new(failure)));
259        }
260
261        let read = serde_json::from_slice(&payload);
262        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
263    }
264
265    /// `applications.update`, `PUT /api/v1/applications/{application_id}`.
266    ///
267    /// Edit an application
268    pub async fn update(
269        &self,
270        application_id: &str,
271        body: ApplicationPost,
272    ) -> Result<Application, RequestError> {
273        let mut path = "/api/v1/applications/{application_id}".to_owned();
274        path = path.replace("{application_id}", &path_segment(&application_id));
275        let query: Vec<(&str, String)> = Vec::new();
276        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
277        let issued = self.transport.request("PUT", &path, &query, Some(body));
278        let (status, payload) = issued.await.map_err(RequestError::transport)?;
279
280        if let Some(failure) = problem_for(status, &payload) {
281            return Err(RequestError::Api(Box::new(failure)));
282        }
283
284        let read = serde_json::from_slice(&payload);
285        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
286    }
287}
288
289/// What the API declares under `errors`.
290///
291/// Every method of it is issued through the transport it is handed.
292#[derive(Debug, Clone)]
293pub struct ErrorsApi<T> {
294    transport: T,
295}
296
297impl<T: Transport> ErrorsApi<T> {
298    /// Reaches what the API declares under `errors`.
299    pub fn new(transport: T) -> Self {
300        Self { transport }
301    }
302
303    /// `errors.list`, `GET /api/v1/errors/`.
304    ///
305    /// List errors
306    pub async fn list(&self) -> Result<Vec<Problem>, RequestError> {
307        let path = "/api/v1/errors/".to_owned();
308        let query: Vec<(&str, String)> = Vec::new();
309        let issued = self.transport.request("GET", &path, &query, None);
310        let (status, payload) = issued.await.map_err(RequestError::transport)?;
311
312        if let Some(failure) = problem_for(status, &payload) {
313            return Err(RequestError::Api(Box::new(failure)));
314        }
315
316        let read = serde_json::from_slice(&payload);
317        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
318    }
319}
320
321/// What the API declares under `eventTypes`.
322///
323/// Every method of it is issued through the transport it is handed.
324#[derive(Debug, Clone)]
325pub struct EventTypesApi<T> {
326    transport: T,
327}
328
329impl<T: Transport> EventTypesApi<T> {
330    /// Reaches what the API declares under `eventTypes`.
331    pub fn new(transport: T) -> Self {
332        Self { transport }
333    }
334
335    /// `eventTypes.create`, `POST /api/v1/event_types/`.
336    ///
337    /// Create a new event type
338    pub async fn create(&self, body: EventTypePost) -> Result<EventType, RequestError> {
339        let path = "/api/v1/event_types/".to_owned();
340        let query: Vec<(&str, String)> = Vec::new();
341        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
342        let issued = self.transport.request("POST", &path, &query, Some(body));
343        let (status, payload) = issued.await.map_err(RequestError::transport)?;
344
345        if let Some(failure) = problem_for(status, &payload) {
346            return Err(RequestError::Api(Box::new(failure)));
347        }
348
349        let read = serde_json::from_slice(&payload);
350        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
351    }
352
353    /// `eventTypes.delete`, `DELETE /api/v1/event_types/{event_type_name}`.
354    ///
355    /// Delete an event type
356    pub async fn delete(
357        &self,
358        event_type_name: &str,
359        application_id: &str,
360    ) -> Result<(), RequestError> {
361        let mut path = "/api/v1/event_types/{event_type_name}".to_owned();
362        path = path.replace("{event_type_name}", &path_segment(&event_type_name));
363        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
364        let issued = self.transport.request("DELETE", &path, &query, None);
365        let (status, payload) = issued.await.map_err(RequestError::transport)?;
366
367        if let Some(failure) = problem_for(status, &payload) {
368            return Err(RequestError::Api(Box::new(failure)));
369        }
370
371        Ok(())
372    }
373
374    /// `eventTypes.get`, `GET /api/v1/event_types/{event_type_name}`.
375    ///
376    /// Get an event type by its name
377    pub async fn get(
378        &self,
379        event_type_name: &str,
380        application_id: &str,
381    ) -> Result<EventType, RequestError> {
382        let mut path = "/api/v1/event_types/{event_type_name}".to_owned();
383        path = path.replace("{event_type_name}", &path_segment(&event_type_name));
384        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
385        let issued = self.transport.request("GET", &path, &query, None);
386        let (status, payload) = issued.await.map_err(RequestError::transport)?;
387
388        if let Some(failure) = problem_for(status, &payload) {
389            return Err(RequestError::Api(Box::new(failure)));
390        }
391
392        let read = serde_json::from_slice(&payload);
393        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
394    }
395
396    /// `eventTypes.list`, `GET /api/v1/event_types/`.
397    ///
398    /// List event types
399    pub async fn list(&self, application_id: &str) -> Result<Vec<EventType>, RequestError> {
400        let path = "/api/v1/event_types/".to_owned();
401        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
402        let issued = self.transport.request("GET", &path, &query, None);
403        let (status, payload) = issued.await.map_err(RequestError::transport)?;
404
405        if let Some(failure) = problem_for(status, &payload) {
406            return Err(RequestError::Api(Box::new(failure)));
407        }
408
409        let read = serde_json::from_slice(&payload);
410        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
411    }
412}
413
414/// What the API declares under `events`.
415///
416/// Every method of it is issued through the transport it is handed.
417#[derive(Debug, Clone)]
418pub struct EventsApi<T> {
419    transport: T,
420}
421
422impl<T: Transport> EventsApi<T> {
423    /// Reaches what the API declares under `events`.
424    pub fn new(transport: T) -> Self {
425        Self { transport }
426    }
427
428    /// `events.get`, `GET /api/v1/events/{event_id}`.
429    ///
430    /// Get an event by its ID
431    pub async fn get(
432        &self,
433        event_id: &str,
434        application_id: &str,
435    ) -> Result<EventWithPayload, RequestError> {
436        let mut path = "/api/v1/events/{event_id}".to_owned();
437        path = path.replace("{event_id}", &path_segment(&event_id));
438        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
439        let issued = self.transport.request("GET", &path, &query, None);
440        let (status, payload) = issued.await.map_err(RequestError::transport)?;
441
442        if let Some(failure) = problem_for(status, &payload) {
443            return Err(RequestError::Api(Box::new(failure)));
444        }
445
446        let read = serde_json::from_slice(&payload);
447        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
448    }
449
450    /// `events.ingest`, `POST /api/v1/event/`.
451    ///
452    /// Ingest an event
453    pub async fn ingest(&self, body: EventPost) -> Result<IngestedEvent, RequestError> {
454        let path = "/api/v1/event/".to_owned();
455        let query: Vec<(&str, String)> = Vec::new();
456        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
457        let issued = self.transport.request("POST", &path, &query, Some(body));
458        let (status, payload) = issued.await.map_err(RequestError::transport)?;
459
460        if let Some(failure) = problem_for(status, &payload) {
461            return Err(RequestError::Api(Box::new(failure)));
462        }
463
464        let read = serde_json::from_slice(&payload);
465        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
466    }
467
468    /// `events.list`, `GET /api/v1/events/`.
469    ///
470    /// List latest events
471    pub async fn list(&self, application_id: &str) -> Result<Vec<Event>, RequestError> {
472        let path = "/api/v1/events/".to_owned();
473        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
474        let issued = self.transport.request("GET", &path, &query, None);
475        let (status, payload) = issued.await.map_err(RequestError::transport)?;
476
477        if let Some(failure) = problem_for(status, &payload) {
478            return Err(RequestError::Api(Box::new(failure)));
479        }
480
481        let read = serde_json::from_slice(&payload);
482        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
483    }
484
485    /// `events.replay`, `POST /api/v1/events/{event_id}/replay`.
486    ///
487    /// Replay an event
488    pub async fn replay(&self, event_id: &str, body: ReplayEvent) -> Result<(), RequestError> {
489        let mut path = "/api/v1/events/{event_id}/replay".to_owned();
490        path = path.replace("{event_id}", &path_segment(&event_id));
491        let query: Vec<(&str, String)> = Vec::new();
492        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
493        let issued = self.transport.request("POST", &path, &query, Some(body));
494        let (status, payload) = issued.await.map_err(RequestError::transport)?;
495
496        if let Some(failure) = problem_for(status, &payload) {
497            return Err(RequestError::Api(Box::new(failure)));
498        }
499
500        Ok(())
501    }
502}
503
504/// What the API declares under `events_per_day`.
505///
506/// Every method of it is issued through the transport it is handed.
507#[derive(Debug, Clone)]
508pub struct EventsPerDayApi<T> {
509    transport: T,
510}
511
512impl<T: Transport> EventsPerDayApi<T> {
513    /// Reaches what the API declares under `events_per_day`.
514    pub fn new(transport: T) -> Self {
515        Self { transport }
516    }
517
518    /// `events_per_day.list_for_application`, `GET /api/v1/events_per_day/application`.
519    ///
520    /// List events per day for an application
521    pub async fn list_for_application(
522        &self,
523        application_id: &str,
524        from: Option<&str>,
525        to: Option<&str>,
526    ) -> Result<Vec<EventsPerDayEntry>, RequestError> {
527        let path = "/api/v1/events_per_day/application".to_owned();
528        let mut query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
529        if let Some(from) = from {
530            query.push(("from", query_value(&from)));
531        }
532        if let Some(to) = to {
533            query.push(("to", query_value(&to)));
534        }
535        let issued = self.transport.request("GET", &path, &query, None);
536        let (status, payload) = issued.await.map_err(RequestError::transport)?;
537
538        if let Some(failure) = problem_for(status, &payload) {
539            return Err(RequestError::Api(Box::new(failure)));
540        }
541
542        let read = serde_json::from_slice(&payload);
543        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
544    }
545
546    /// `events_per_day.list_for_organization`, `GET /api/v1/events_per_day/organization`.
547    ///
548    /// List events per day for an organization
549    pub async fn list_for_organization(
550        &self,
551        organization_id: &str,
552        from: Option<&str>,
553        to: Option<&str>,
554    ) -> Result<Vec<EventsPerDayEntry>, RequestError> {
555        let path = "/api/v1/events_per_day/organization".to_owned();
556        let mut query: Vec<(&str, String)> =
557            vec![("organization_id", query_value(&organization_id))];
558        if let Some(from) = from {
559            query.push(("from", query_value(&from)));
560        }
561        if let Some(to) = to {
562            query.push(("to", query_value(&to)));
563        }
564        let issued = self.transport.request("GET", &path, &query, None);
565        let (status, payload) = issued.await.map_err(RequestError::transport)?;
566
567        if let Some(failure) = problem_for(status, &payload) {
568            return Err(RequestError::Api(Box::new(failure)));
569        }
570
571        let read = serde_json::from_slice(&payload);
572        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
573    }
574}
575
576/// What the API declares under `instance`.
577///
578/// Every method of it is issued through the transport it is handed.
579#[derive(Debug, Clone)]
580pub struct InstanceApi<T> {
581    transport: T,
582}
583
584impl<T: Transport> InstanceApi<T> {
585    /// Reaches what the API declares under `instance`.
586    pub fn new(transport: T) -> Self {
587        Self { transport }
588    }
589
590    /// `instance.get`, `GET /api/v1/instance/`.
591    ///
592    /// Get instance configuration
593    pub async fn get(&self) -> Result<InstanceConfig, RequestError> {
594        let path = "/api/v1/instance/".to_owned();
595        let query: Vec<(&str, String)> = Vec::new();
596        let issued = self.transport.request("GET", &path, &query, None);
597        let (status, payload) = issued.await.map_err(RequestError::transport)?;
598
599        if let Some(failure) = problem_for(status, &payload) {
600            return Err(RequestError::Api(Box::new(failure)));
601        }
602
603        let read = serde_json::from_slice(&payload);
604        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
605    }
606}
607
608/// What the API declares under `payload_content_types`.
609///
610/// Every method of it is issued through the transport it is handed.
611#[derive(Debug, Clone)]
612pub struct PayloadContentTypesApi<T> {
613    transport: T,
614}
615
616impl<T: Transport> PayloadContentTypesApi<T> {
617    /// Reaches what the API declares under `payload_content_types`.
618    pub fn new(transport: T) -> Self {
619        Self { transport }
620    }
621
622    /// `payload_content_types.list`, `GET /api/v1/payload_content_types/`.
623    ///
624    /// List supported event payload content types
625    pub async fn list(&self) -> Result<Vec<String>, RequestError> {
626        let path = "/api/v1/payload_content_types/".to_owned();
627        let query: Vec<(&str, String)> = Vec::new();
628        let issued = self.transport.request("GET", &path, &query, None);
629        let (status, payload) = issued.await.map_err(RequestError::transport)?;
630
631        if let Some(failure) = problem_for(status, &payload) {
632            return Err(RequestError::Api(Box::new(failure)));
633        }
634
635        let read = serde_json::from_slice(&payload);
636        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
637    }
638}
639
640/// What the API declares under `quotas`.
641///
642/// Every method of it is issued through the transport it is handed.
643#[derive(Debug, Clone)]
644pub struct QuotasApi<T> {
645    transport: T,
646}
647
648impl<T: Transport> QuotasApi<T> {
649    /// Reaches what the API declares under `quotas`.
650    pub fn new(transport: T) -> Self {
651        Self { transport }
652    }
653
654    /// `quotas.get`, `GET /api/v1/quotas/`.
655    ///
656    /// Get quotas
657    pub async fn get(&self) -> Result<QuotasResponse, RequestError> {
658        let path = "/api/v1/quotas/".to_owned();
659        let query: Vec<(&str, String)> = Vec::new();
660        let issued = self.transport.request("GET", &path, &query, None);
661        let (status, payload) = issued.await.map_err(RequestError::transport)?;
662
663        if let Some(failure) = problem_for(status, &payload) {
664            return Err(RequestError::Api(Box::new(failure)));
665        }
666
667        let read = serde_json::from_slice(&payload);
668        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
669    }
670}
671
672/// What the API declares under `requestAttempts`.
673///
674/// Every method of it is issued through the transport it is handed.
675#[derive(Debug, Clone)]
676pub struct RequestAttemptsApi<T> {
677    transport: T,
678}
679
680impl<T: Transport> RequestAttemptsApi<T> {
681    /// Reaches what the API declares under `requestAttempts`.
682    pub fn new(transport: T) -> Self {
683        Self { transport }
684    }
685
686    /// `requestAttempts.get`, `GET /api/v1/request_attempts/{request_attempt_id}`.
687    ///
688    /// Get a request attempt by its ID
689    pub async fn get(
690        &self,
691        request_attempt_id: &str,
692        application_id: &str,
693    ) -> Result<RequestAttempt, RequestError> {
694        let mut path = "/api/v1/request_attempts/{request_attempt_id}".to_owned();
695        path = path.replace("{request_attempt_id}", &path_segment(&request_attempt_id));
696        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
697        let issued = self.transport.request("GET", &path, &query, None);
698        let (status, payload) = issued.await.map_err(RequestError::transport)?;
699
700        if let Some(failure) = problem_for(status, &payload) {
701            return Err(RequestError::Api(Box::new(failure)));
702        }
703
704        let read = serde_json::from_slice(&payload);
705        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
706    }
707
708    /// `requestAttempts.read`, `GET /api/v1/request_attempts/`.
709    ///
710    /// List request attempts
711    pub async fn read(
712        &self,
713        application_id: &str,
714        event_event_type_names: Option<&str>,
715        event_id: Option<&str>,
716        max_created_at: Option<&str>,
717        min_created_at: Option<&str>,
718        pagination_cursor: Option<&str>,
719        subscription_id: Option<&str>,
720    ) -> Result<Vec<RequestAttempt>, RequestError> {
721        let path = "/api/v1/request_attempts/".to_owned();
722        let mut query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
723        if let Some(event_event_type_names) = event_event_type_names {
724            query.push((
725                "event.event_type_names",
726                query_value(&event_event_type_names),
727            ));
728        }
729        if let Some(event_id) = event_id {
730            query.push(("event_id", query_value(&event_id)));
731        }
732        if let Some(max_created_at) = max_created_at {
733            query.push(("max_created_at", query_value(&max_created_at)));
734        }
735        if let Some(min_created_at) = min_created_at {
736            query.push(("min_created_at", query_value(&min_created_at)));
737        }
738        if let Some(pagination_cursor) = pagination_cursor {
739            query.push(("pagination_cursor", query_value(&pagination_cursor)));
740        }
741        if let Some(subscription_id) = subscription_id {
742            query.push(("subscription_id", query_value(&subscription_id)));
743        }
744        let issued = self.transport.request("GET", &path, &query, None);
745        let (status, payload) = issued.await.map_err(RequestError::transport)?;
746
747        if let Some(failure) = problem_for(status, &payload) {
748            return Err(RequestError::Api(Box::new(failure)));
749        }
750
751        let read = serde_json::from_slice(&payload);
752        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
753    }
754}
755
756/// What the API declares under `response`.
757///
758/// Every method of it is issued through the transport it is handed.
759#[derive(Debug, Clone)]
760pub struct ResponseApi<T> {
761    transport: T,
762}
763
764impl<T: Transport> ResponseApi<T> {
765    /// Reaches what the API declares under `response`.
766    pub fn new(transport: T) -> Self {
767        Self { transport }
768    }
769
770    /// `response.get`, `GET /api/v1/responses/{response_id}`.
771    ///
772    /// Get a response by its ID
773    pub async fn get(
774        &self,
775        response_id: &str,
776        application_id: &str,
777    ) -> Result<Response, RequestError> {
778        let mut path = "/api/v1/responses/{response_id}".to_owned();
779        path = path.replace("{response_id}", &path_segment(&response_id));
780        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
781        let issued = self.transport.request("GET", &path, &query, None);
782        let (status, payload) = issued.await.map_err(RequestError::transport)?;
783
784        if let Some(failure) = problem_for(status, &payload) {
785            return Err(RequestError::Api(Box::new(failure)));
786        }
787
788        let read = serde_json::from_slice(&payload);
789        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
790    }
791}
792
793/// What the API declares under `serviceToken`.
794///
795/// Every method of it is issued through the transport it is handed.
796#[derive(Debug, Clone)]
797pub struct ServiceTokenApi<T> {
798    transport: T,
799}
800
801impl<T: Transport> ServiceTokenApi<T> {
802    /// Reaches what the API declares under `serviceToken`.
803    pub fn new(transport: T) -> Self {
804        Self { transport }
805    }
806
807    /// `serviceToken.create`, `POST /api/v1/service_token/`.
808    ///
809    /// Create a new service token
810    pub async fn create(&self, body: ServiceTokenPost) -> Result<ServiceToken, RequestError> {
811        let path = "/api/v1/service_token/".to_owned();
812        let query: Vec<(&str, String)> = Vec::new();
813        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
814        let issued = self.transport.request("POST", &path, &query, Some(body));
815        let (status, payload) = issued.await.map_err(RequestError::transport)?;
816
817        if let Some(failure) = problem_for(status, &payload) {
818            return Err(RequestError::Api(Box::new(failure)));
819        }
820
821        let read = serde_json::from_slice(&payload);
822        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
823    }
824
825    /// `serviceToken.delete`, `DELETE /api/v1/service_token/{service_token_id}`.
826    ///
827    /// Delete a service token
828    pub async fn delete(
829        &self,
830        service_token_id: &str,
831        organization_id: &str,
832    ) -> Result<(), RequestError> {
833        let mut path = "/api/v1/service_token/{service_token_id}".to_owned();
834        path = path.replace("{service_token_id}", &path_segment(&service_token_id));
835        let query: Vec<(&str, String)> = vec![("organization_id", query_value(&organization_id))];
836        let issued = self.transport.request("DELETE", &path, &query, None);
837        let (status, payload) = issued.await.map_err(RequestError::transport)?;
838
839        if let Some(failure) = problem_for(status, &payload) {
840            return Err(RequestError::Api(Box::new(failure)));
841        }
842
843        Ok(())
844    }
845
846    /// `serviceToken.edit`, `PUT /api/v1/service_token/{service_token_id}`.
847    ///
848    /// Edit a service token
849    pub async fn edit(
850        &self,
851        service_token_id: &str,
852        body: ServiceTokenPost,
853    ) -> Result<ServiceToken, RequestError> {
854        let mut path = "/api/v1/service_token/{service_token_id}".to_owned();
855        path = path.replace("{service_token_id}", &path_segment(&service_token_id));
856        let query: Vec<(&str, String)> = Vec::new();
857        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
858        let issued = self.transport.request("PUT", &path, &query, Some(body));
859        let (status, payload) = issued.await.map_err(RequestError::transport)?;
860
861        if let Some(failure) = problem_for(status, &payload) {
862            return Err(RequestError::Api(Box::new(failure)));
863        }
864
865        let read = serde_json::from_slice(&payload);
866        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
867    }
868
869    /// `serviceToken.get`, `GET /api/v1/service_token/{service_token_id}`.
870    ///
871    /// Get a service token
872    pub async fn get(
873        &self,
874        service_token_id: &str,
875        organization_id: &str,
876    ) -> Result<ServiceToken, RequestError> {
877        let mut path = "/api/v1/service_token/{service_token_id}".to_owned();
878        path = path.replace("{service_token_id}", &path_segment(&service_token_id));
879        let query: Vec<(&str, String)> = vec![("organization_id", query_value(&organization_id))];
880        let issued = self.transport.request("GET", &path, &query, None);
881        let (status, payload) = issued.await.map_err(RequestError::transport)?;
882
883        if let Some(failure) = problem_for(status, &payload) {
884            return Err(RequestError::Api(Box::new(failure)));
885        }
886
887        let read = serde_json::from_slice(&payload);
888        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
889    }
890
891    /// `serviceToken.list`, `GET /api/v1/service_token/`.
892    ///
893    /// List service tokens
894    pub async fn list(&self, organization_id: &str) -> Result<Vec<ServiceToken>, RequestError> {
895        let path = "/api/v1/service_token/".to_owned();
896        let query: Vec<(&str, String)> = vec![("organization_id", query_value(&organization_id))];
897        let issued = self.transport.request("GET", &path, &query, None);
898        let (status, payload) = issued.await.map_err(RequestError::transport)?;
899
900        if let Some(failure) = problem_for(status, &payload) {
901            return Err(RequestError::Api(Box::new(failure)));
902        }
903
904        let read = serde_json::from_slice(&payload);
905        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
906    }
907}
908
909/// What the API declares under `subscriptions`.
910///
911/// Every method of it is issued through the transport it is handed.
912#[derive(Debug, Clone)]
913pub struct SubscriptionsApi<T> {
914    transport: T,
915}
916
917impl<T: Transport> SubscriptionsApi<T> {
918    /// Reaches what the API declares under `subscriptions`.
919    pub fn new(transport: T) -> Self {
920        Self { transport }
921    }
922
923    /// `subscriptions.create`, `POST /api/v1/subscriptions/`.
924    ///
925    /// Create a new subscription
926    pub async fn create(&self, body: SubscriptionPost) -> Result<Subscription, RequestError> {
927        let path = "/api/v1/subscriptions/".to_owned();
928        let query: Vec<(&str, String)> = Vec::new();
929        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
930        let issued = self.transport.request("POST", &path, &query, Some(body));
931        let (status, payload) = issued.await.map_err(RequestError::transport)?;
932
933        if let Some(failure) = problem_for(status, &payload) {
934            return Err(RequestError::Api(Box::new(failure)));
935        }
936
937        let read = serde_json::from_slice(&payload);
938        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
939    }
940
941    /// `subscriptions.delete`, `DELETE /api/v1/subscriptions/{subscription_id}`.
942    ///
943    /// Delete a subscription
944    pub async fn delete(
945        &self,
946        subscription_id: &str,
947        application_id: &str,
948    ) -> Result<(), RequestError> {
949        let mut path = "/api/v1/subscriptions/{subscription_id}".to_owned();
950        path = path.replace("{subscription_id}", &path_segment(&subscription_id));
951        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
952        let issued = self.transport.request("DELETE", &path, &query, None);
953        let (status, payload) = issued.await.map_err(RequestError::transport)?;
954
955        if let Some(failure) = problem_for(status, &payload) {
956            return Err(RequestError::Api(Box::new(failure)));
957        }
958
959        Ok(())
960    }
961
962    /// `subscriptions.get`, `GET /api/v1/subscriptions/{subscription_id}`.
963    ///
964    /// Get a subscription by its ID
965    pub async fn get(&self, subscription_id: &str) -> Result<Subscription, RequestError> {
966        let mut path = "/api/v1/subscriptions/{subscription_id}".to_owned();
967        path = path.replace("{subscription_id}", &path_segment(&subscription_id));
968        let query: Vec<(&str, String)> = Vec::new();
969        let issued = self.transport.request("GET", &path, &query, None);
970        let (status, payload) = issued.await.map_err(RequestError::transport)?;
971
972        if let Some(failure) = problem_for(status, &payload) {
973            return Err(RequestError::Api(Box::new(failure)));
974        }
975
976        let read = serde_json::from_slice(&payload);
977        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
978    }
979
980    /// `subscriptions.list`, `GET /api/v1/subscriptions/`.
981    ///
982    /// List subscriptions
983    pub async fn list(&self, application_id: &str) -> Result<Vec<Subscription>, RequestError> {
984        let path = "/api/v1/subscriptions/".to_owned();
985        let query: Vec<(&str, String)> = vec![("application_id", query_value(&application_id))];
986        let issued = self.transport.request("GET", &path, &query, None);
987        let (status, payload) = issued.await.map_err(RequestError::transport)?;
988
989        if let Some(failure) = problem_for(status, &payload) {
990            return Err(RequestError::Api(Box::new(failure)));
991        }
992
993        let read = serde_json::from_slice(&payload);
994        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
995    }
996
997    /// `subscriptions.update`, `PUT /api/v1/subscriptions/{subscription_id}`.
998    ///
999    /// Update a subscription
1000    pub async fn update(
1001        &self,
1002        subscription_id: &str,
1003        body: SubscriptionPost,
1004    ) -> Result<Subscription, RequestError> {
1005        let mut path = "/api/v1/subscriptions/{subscription_id}".to_owned();
1006        path = path.replace("{subscription_id}", &path_segment(&subscription_id));
1007        let query: Vec<(&str, String)> = Vec::new();
1008        let body = serde_json::to_vec(&body).map_err(RequestError::unwritable)?;
1009        let issued = self.transport.request("PUT", &path, &query, Some(body));
1010        let (status, payload) = issued.await.map_err(RequestError::transport)?;
1011
1012        if let Some(failure) = problem_for(status, &payload) {
1013            return Err(RequestError::Api(Box::new(failure)));
1014        }
1015
1016        let read = serde_json::from_slice(&payload);
1017        read.map_err(|cause| RequestError::unreadable(status, &payload, &cause))
1018    }
1019}