Skip to content

Commit

Permalink
rust: Some MessageAttempt API cleanup (#1568)
Browse files Browse the repository at this point in the history
Prepare for auto-generating this.
  • Loading branch information
svix-jplatte authored Dec 16, 2024
2 parents e9703bd + a3aeb84 commit 7b718fd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 51 deletions.
6 changes: 5 additions & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Changelog

## Next
*
* Libs/Rust: Add `api::MessageAttemptListAttemptedMessagesOptions` and use it for
`MessageAttempt::list_attempted_messages`, replacing `MessageAttemptListOptions` which contained
some extra parameters never used with this method / endpoint ([#1568])

[#1568]: https://github.com/svix/svix-webhooks/pull/1568

## Version 1.44.0
* Libs/JavaScript: Revert packaging-related change because it broke for some users ([#1556])
Expand Down
132 changes: 83 additions & 49 deletions rust/src/api/message_attempt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::ListOptions;
use crate::{apis::message_attempt_api, error::Result, models::*, Configuration};

#[derive(Default)]
pub struct MessageAttemptListOptions {
pub struct MessageAttemptListByEndpointOptions {
/// Limit the number of returned items
pub limit: Option<i32>,

Expand All @@ -22,9 +22,6 @@ pub struct MessageAttemptListOptions {
/// Filter response based on the tag
pub tag: Option<String>,

/// Filter the attempts based on the attempted endpoint
pub endpoint_id: Option<String>,

/// Only include items created before a certain date
///
/// RFC3339 date string.
Expand All @@ -38,12 +35,15 @@ pub struct MessageAttemptListOptions {
/// When `true` attempt content is included in the response
pub with_content: Option<bool>,

/// When `true`, the message information is included in the response
pub with_msg: Option<bool>,

/// Filter response based on the event type
pub event_types: Option<Vec<String>>,
}

#[derive(Default)]
pub struct MessageAttemptListByEndpointOptions {
pub struct MessageAttemptListOptions {
/// Limit the number of returned items
pub limit: Option<i32>,

Expand All @@ -63,6 +63,9 @@ pub struct MessageAttemptListByEndpointOptions {
/// Filter response based on the tag
pub tag: Option<String>,

/// Filter the attempts based on the attempted endpoint
pub endpoint_id: Option<String>,

/// Only include items created before a certain date
///
/// RFC3339 date string.
Expand All @@ -76,8 +79,40 @@ pub struct MessageAttemptListByEndpointOptions {
/// When `true` attempt content is included in the response
pub with_content: Option<bool>,

/// When `true`, the message information is included in the response
pub with_msg: Option<bool>,
/// Filter response based on the event type
pub event_types: Option<Vec<String>>,
}

#[derive(Default)]
pub struct MessageAttemptListAttemptedMessagesOptions {
/// Limit the number of returned items
pub limit: Option<i32>,

/// The iterator returned from a prior invocation
pub iterator: Option<String>,

/// Filter response based on the channel
pub channel: Option<String>,

/// Filter response based on the message tags
pub tag: Option<String>,

/// Filter response based on the status of the attempt: Success (0), Pending
/// (1), Failed (2), or Sending (3)
pub status: Option<MessageStatus>,

/// Only include items created before a certain date
///
/// RFC3339 date string.
pub before: Option<String>,

/// Only include items created after a certain date
///
/// RFC3339 date string.
pub after: Option<String>,

/// When `true` message payloads are included in the response
pub with_content: Option<bool>,

/// Filter response based on the event type
pub event_types: Option<Vec<String>>,
Expand All @@ -92,96 +127,96 @@ impl<'a> MessageAttempt<'a> {
Self { cfg }
}

/// List attempts by message id
/// List attempts by endpoint id
///
/// Note that by default this endpoint is limited to retrieving 90 days'
/// worth of data relative to now or, if an iterator is provided, 90
/// days before/after the time indicated by the iterator ID. If you
/// require data beyond those time ranges, you will need to explicitly
/// set the `before` or `after` parameter as appropriate.
pub async fn list_by_msg(
pub async fn list_by_endpoint(
&self,
app_id: String,
msg_id: String,
options: Option<MessageAttemptListOptions>,
endpoint_id: String,
options: Option<MessageAttemptListByEndpointOptions>,
) -> Result<ListResponseMessageAttemptOut> {
let MessageAttemptListOptions {
let MessageAttemptListByEndpointOptions {
limit,
iterator,
status,
status_code_class,
channel,
tag,
endpoint_id,
before,
after,
with_content,
with_msg,
event_types,
} = options.unwrap_or_default();

message_attempt_api::v1_period_message_attempt_period_list_by_msg(
message_attempt_api::v1_period_message_attempt_period_list_by_endpoint(
self.cfg,
message_attempt_api::V1PeriodMessageAttemptPeriodListByMsgParams {
message_attempt_api::V1PeriodMessageAttemptPeriodListByEndpointParams {
app_id,
msg_id,
endpoint_id,
limit,
iterator,
status,
status_code_class,
channel,
tag,
endpoint_id,
before,
after,
with_content,
with_msg,
event_types,
},
)
.await
}

/// List attempts by endpoint id
/// List attempts by message id
///
/// Note that by default this endpoint is limited to retrieving 90 days'
/// worth of data relative to now or, if an iterator is provided, 90
/// days before/after the time indicated by the iterator ID. If you
/// require data beyond those time ranges, you will need to explicitly
/// set the `before` or `after` parameter as appropriate.
pub async fn list_by_endpoint(
pub async fn list_by_msg(
&self,
app_id: String,
endpoint_id: String,
options: Option<MessageAttemptListByEndpointOptions>,
msg_id: String,
options: Option<MessageAttemptListOptions>,
) -> Result<ListResponseMessageAttemptOut> {
let MessageAttemptListByEndpointOptions {
let MessageAttemptListOptions {
limit,
iterator,
status,
status_code_class,
channel,
tag,
endpoint_id,
before,
after,
with_content,
with_msg,
event_types,
} = options.unwrap_or_default();

message_attempt_api::v1_period_message_attempt_period_list_by_endpoint(
message_attempt_api::v1_period_message_attempt_period_list_by_msg(
self.cfg,
message_attempt_api::V1PeriodMessageAttemptPeriodListByEndpointParams {
message_attempt_api::V1PeriodMessageAttemptPeriodListByMsgParams {
app_id,
endpoint_id,
msg_id,
limit,
iterator,
status,
status_code_class,
channel,
tag,
endpoint_id,
before,
after,
with_content,
with_msg,
event_types,
},
)
Expand All @@ -203,20 +238,18 @@ impl<'a> MessageAttempt<'a> {
&self,
app_id: String,
endpoint_id: String,
options: Option<MessageAttemptListOptions>,
options: Option<MessageAttemptListAttemptedMessagesOptions>,
) -> Result<ListResponseEndpointMessageOut> {
let MessageAttemptListOptions {
iterator,
let MessageAttemptListAttemptedMessagesOptions {
limit,
event_types,
before,
after,
iterator,
channel,
tag,
status,
status_code_class: _,
before,
after,
with_content,
endpoint_id: _,
event_types,
} = options.unwrap_or_default();

message_attempt_api::v1_period_message_attempt_period_list_attempted_messages(
Expand Down Expand Up @@ -260,6 +293,7 @@ impl<'a> MessageAttempt<'a> {
.await
}

#[deprecated = "Use `list_by_msg` instead, setting the `endpoint_id` in `options`."]
pub async fn list_attempts_for_endpoint(
&self,
app_id: String,
Expand Down Expand Up @@ -317,20 +351,6 @@ impl<'a> MessageAttempt<'a> {
.await
}

/// Resend a message to the specified endpoint.
pub async fn resend(&self, app_id: String, msg_id: String, endpoint_id: String) -> Result<()> {
message_attempt_api::v1_period_message_attempt_period_resend(
self.cfg,
message_attempt_api::V1PeriodMessageAttemptPeriodResendParams {
app_id,
msg_id,
endpoint_id,
idempotency_key: None,
},
)
.await
}

/// Deletes the given attempt's response body. Useful when an endpoint
/// accidentally returned sensitive content.
pub async fn expunge_content(
Expand All @@ -349,4 +369,18 @@ impl<'a> MessageAttempt<'a> {
)
.await
}

/// Resend a message to the specified endpoint.
pub async fn resend(&self, app_id: String, msg_id: String, endpoint_id: String) -> Result<()> {
message_attempt_api::v1_period_message_attempt_period_resend(
self.cfg,
message_attempt_api::V1PeriodMessageAttemptPeriodResendParams {
app_id,
msg_id,
endpoint_id,
idempotency_key: None,
},
)
.await
}
}
3 changes: 2 additions & 1 deletion rust/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ pub use self::{
integration::{Integration, IntegrationListOptions},
message::{Message, MessageListOptions},
message_attempt::{
MessageAttempt, MessageAttemptListByEndpointOptions, MessageAttemptListOptions,
MessageAttempt, MessageAttemptListAttemptedMessagesOptions,
MessageAttemptListByEndpointOptions, MessageAttemptListOptions,
},
operational_webhook_endpoint::{
OperationalWebhookEndpoint, OperationalWebhookEndpointListOptions,
Expand Down

0 comments on commit 7b718fd

Please sign in to comment.