svix_webhook_with_clone/api/
message_attempt.rs

1use super::ListOptions;
2use crate::{apis::message_attempt_api, error::Result, models::*, Configuration};
3
4#[derive(Default)]
5pub struct MessageAttemptListOptions {
6    /// Limit the number of returned items
7    pub limit: Option<i32>,
8
9    /// The iterator returned from a prior invocation
10    pub iterator: Option<String>,
11
12    /// Filter response based on the status of the attempt: Success (0), Pending
13    /// (1), Failed (2), or Sending (3)
14    pub status: Option<MessageStatus>,
15
16    /// Filter response based on the HTTP status code
17    pub status_code_class: Option<StatusCodeClass>,
18
19    /// Filter response based on the channel
20    pub channel: Option<String>,
21
22    /// Filter response based on the tag
23    pub tag: Option<String>,
24
25    /// Filter the attempts based on the attempted endpoint
26    pub endpoint_id: Option<String>,
27
28    /// Only include items created before a certain date
29    ///
30    /// RFC3339 date string.
31    pub before: Option<String>,
32
33    /// Only include items created after a certain date
34    ///
35    /// RFC3339 date string.
36    pub after: Option<String>,
37
38    /// When `true` attempt content is included in the response
39    pub with_content: Option<bool>,
40
41    /// Filter response based on the event type
42    pub event_types: Option<Vec<String>>,
43}
44
45#[derive(Default)]
46pub struct MessageAttemptListByEndpointOptions {
47    /// Limit the number of returned items
48    pub limit: Option<i32>,
49
50    /// The iterator returned from a prior invocation
51    pub iterator: Option<String>,
52
53    /// Filter response based on the status of the attempt: Success (0), Pending
54    /// (1), Failed (2), or Sending (3)
55    pub status: Option<MessageStatus>,
56
57    /// Filter response based on the HTTP status code
58    pub status_code_class: Option<StatusCodeClass>,
59
60    /// Filter response based on the channel
61    pub channel: Option<String>,
62
63    /// Filter response based on the tag
64    pub tag: Option<String>,
65
66    /// Only include items created before a certain date
67    ///
68    /// RFC3339 date string.
69    pub before: Option<String>,
70
71    /// Only include items created after a certain date
72    ///
73    /// RFC3339 date string.
74    pub after: Option<String>,
75
76    /// When `true` attempt content is included in the response
77    pub with_content: Option<bool>,
78
79    /// When `true`, the message information is included in the response
80    pub with_msg: Option<bool>,
81
82    /// Filter response based on the event type
83    pub event_types: Option<Vec<String>>,
84}
85
86pub struct MessageAttempt<'a> {
87    cfg: &'a Configuration,
88}
89
90impl<'a> MessageAttempt<'a> {
91    pub(super) fn new(cfg: &'a Configuration) -> Self {
92        Self { cfg }
93    }
94
95    /// List attempts by message id
96    ///
97    /// Note that by default this endpoint is limited to retrieving 90 days'
98    /// worth of data relative to now or, if an iterator is provided, 90
99    /// days before/after the time indicated by the iterator ID. If you
100    /// require data beyond those time ranges, you will need to explicitly
101    /// set the `before` or `after` parameter as appropriate.
102    pub async fn list_by_msg(
103        &self,
104        app_id: String,
105        msg_id: String,
106        options: Option<MessageAttemptListOptions>,
107    ) -> Result<ListResponseMessageAttemptOut> {
108        let MessageAttemptListOptions {
109            limit,
110            iterator,
111            status,
112            status_code_class,
113            channel,
114            tag,
115            endpoint_id,
116            before,
117            after,
118            with_content,
119            event_types,
120        } = options.unwrap_or_default();
121
122        message_attempt_api::v1_period_message_attempt_period_list_by_msg(
123            self.cfg,
124            message_attempt_api::V1PeriodMessageAttemptPeriodListByMsgParams {
125                app_id,
126                msg_id,
127                limit,
128                iterator,
129                status,
130                status_code_class,
131                channel,
132                tag,
133                endpoint_id,
134                before,
135                after,
136                with_content,
137                event_types,
138            },
139        )
140        .await
141    }
142
143    /// List attempts by endpoint id
144    ///
145    /// Note that by default this endpoint is limited to retrieving 90 days'
146    /// worth of data relative to now or, if an iterator is provided, 90
147    /// days before/after the time indicated by the iterator ID. If you
148    /// require data beyond those time ranges, you will need to explicitly
149    /// set the `before` or `after` parameter as appropriate.
150    pub async fn list_by_endpoint(
151        &self,
152        app_id: String,
153        endpoint_id: String,
154        options: Option<MessageAttemptListByEndpointOptions>,
155    ) -> Result<ListResponseMessageAttemptOut> {
156        let MessageAttemptListByEndpointOptions {
157            limit,
158            iterator,
159            status,
160            status_code_class,
161            channel,
162            tag,
163            before,
164            after,
165            with_content,
166            with_msg,
167            event_types,
168        } = options.unwrap_or_default();
169
170        message_attempt_api::v1_period_message_attempt_period_list_by_endpoint(
171            self.cfg,
172            message_attempt_api::V1PeriodMessageAttemptPeriodListByEndpointParams {
173                app_id,
174                endpoint_id,
175                limit,
176                iterator,
177                status,
178                status_code_class,
179                channel,
180                tag,
181                before,
182                after,
183                with_content,
184                with_msg,
185                event_types,
186            },
187        )
188        .await
189    }
190
191    /// List messages for a particular endpoint. Additionally includes metadata
192    /// about the latest message attempt.
193    ///
194    /// The `before` parameter lets you filter all items created before a
195    /// certain date and is ignored if an iterator is passed.
196    ///
197    /// Note that by default this endpoint is limited to retrieving 90 days'
198    /// worth of data relative to now or, if an iterator is provided, 90
199    /// days before/after the time indicated by the iterator ID. If you
200    /// require data beyond those time ranges, you will need to explicitly
201    /// set the `before` or `after` parameter as appropriate.
202    pub async fn list_attempted_messages(
203        &self,
204        app_id: String,
205        endpoint_id: String,
206        options: Option<MessageAttemptListOptions>,
207    ) -> Result<ListResponseEndpointMessageOut> {
208        let MessageAttemptListOptions {
209            iterator,
210            limit,
211            event_types,
212            before,
213            after,
214            channel,
215            tag,
216            status,
217            status_code_class: _,
218            with_content,
219            endpoint_id: _,
220        } = options.unwrap_or_default();
221
222        message_attempt_api::v1_period_message_attempt_period_list_attempted_messages(
223            self.cfg,
224            message_attempt_api::V1PeriodMessageAttemptPeriodListAttemptedMessagesParams {
225                app_id,
226                endpoint_id,
227                limit,
228                iterator,
229                channel,
230                tag,
231                status,
232                before,
233                after,
234                with_content,
235                event_types,
236            },
237        )
238        .await
239    }
240
241    /// List endpoints attempted by a given message. Additionally includes
242    /// metadata about the latest message attempt. By default, endpoints are
243    /// listed in ascending order by ID.
244    pub async fn list_attempted_destinations(
245        &self,
246        app_id: String,
247        msg_id: String,
248        options: Option<ListOptions>,
249    ) -> Result<ListResponseMessageEndpointOut> {
250        let ListOptions { iterator, limit } = options.unwrap_or_default();
251        message_attempt_api::v1_period_message_attempt_period_list_attempted_destinations(
252            self.cfg,
253            message_attempt_api::V1PeriodMessageAttemptPeriodListAttemptedDestinationsParams {
254                app_id,
255                msg_id,
256                iterator,
257                limit,
258            },
259        )
260        .await
261    }
262
263    pub async fn list_attempts_for_endpoint(
264        &self,
265        app_id: String,
266        msg_id: String,
267        endpoint_id: String,
268        options: Option<MessageAttemptListOptions>,
269    ) -> Result<ListResponseMessageAttemptEndpointOut> {
270        let MessageAttemptListOptions {
271            iterator,
272            limit,
273            event_types,
274            before,
275            after,
276            channel,
277            tag,
278            status,
279            status_code_class: _,
280            endpoint_id: _,
281            with_content: _,
282        } = options.unwrap_or_default();
283        message_attempt_api::v1_period_message_attempt_period_list_by_endpoint_deprecated(
284            self.cfg,
285            message_attempt_api::V1PeriodMessageAttemptPeriodListByEndpointDeprecatedParams {
286                app_id,
287                endpoint_id,
288                msg_id,
289                iterator,
290                limit,
291                event_types,
292                before,
293                after,
294                channel,
295                tag,
296                status,
297            },
298        )
299        .await
300    }
301
302    /// `msg_id`: Use a message id or a message `eventId`
303    pub async fn get(
304        &self,
305        app_id: String,
306        msg_id: String,
307        attempt_id: String,
308    ) -> Result<MessageAttemptOut> {
309        message_attempt_api::v1_period_message_attempt_period_get(
310            self.cfg,
311            message_attempt_api::V1PeriodMessageAttemptPeriodGetParams {
312                app_id,
313                msg_id,
314                attempt_id,
315            },
316        )
317        .await
318    }
319
320    /// Resend a message to the specified endpoint.
321    pub async fn resend(&self, app_id: String, msg_id: String, endpoint_id: String) -> Result<()> {
322        message_attempt_api::v1_period_message_attempt_period_resend(
323            self.cfg,
324            message_attempt_api::V1PeriodMessageAttemptPeriodResendParams {
325                app_id,
326                msg_id,
327                endpoint_id,
328                idempotency_key: None,
329            },
330        )
331        .await
332    }
333
334    /// Deletes the given attempt's response body. Useful when an endpoint
335    /// accidentally returned sensitive content.
336    pub async fn expunge_content(
337        &self,
338        app_id: String,
339        msg_id: String,
340        attempt_id: String,
341    ) -> Result<()> {
342        message_attempt_api::v1_period_message_attempt_period_expunge_content(
343            self.cfg,
344            message_attempt_api::V1PeriodMessageAttemptPeriodExpungeContentParams {
345                app_id,
346                msg_id,
347                attempt_id,
348            },
349        )
350        .await
351    }
352}