Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub const OPERATION_IDS: &[&str] = &[
"message.index",
"message.show",
"message.events",
"processInboundMessage",
"message.source",
"message.html",
"message.text",
Expand Down Expand Up @@ -154,6 +155,12 @@ impl<'a> Messages<'a> {
.await
}

pub async fn process(&self, message_id: &str) -> Result<types::ProcessInboundMessageResponse> {
self.client
.post(&format!("/messages/{}/process", segment(message_id)), &())
.await
}

pub async fn events(
&self,
message_id: &str,
Expand Down
10 changes: 10 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub enum MessageStatus {
Pending,
#[serde(rename = "queued")]
Queued,
#[serde(rename = "quarantined")]
Quarantined,
#[serde(rename = "suppressed")]
Suppressed,
#[serde(rename = "processed")]
Expand Down Expand Up @@ -253,6 +255,8 @@ pub enum MessageEventType {
InboundQueued,
#[serde(rename = "inbound_spam_blocked")]
InboundSpamBlocked,
#[serde(rename = "inbound_released")]
InboundReleased,
#[serde(rename = "inbound_processed")]
InboundProcessed,
#[serde(rename = "inbound_retry")]
Expand Down Expand Up @@ -1001,6 +1005,12 @@ pub struct MessageEventsResponse {
pub prev_page_url: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct ProcessInboundMessageResponse {
pub data: serde_json::Value,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
#[serde(default)]
pub struct ProjectIndexResponse {
Expand Down
19 changes: 18 additions & 1 deletion tests/sdk_surface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,26 @@ async fn message_raw_body_endpoints_return_plain_text() {
);
}

#[tokio::test]
async fn process_quarantined_message_uses_typed_api_endpoint() {
let transport = MockTransport::new(vec![json_response(
serde_json::json!({"data": {"message_id": "message id", "status": "queued", "webhook_target_count": 1}}),
)]);
let api = Lettermint::api_with_transport("api-token", transport.clone()).unwrap();
assert_eq!(
api.messages().process("message id").await.unwrap().data["status"],
"queued"
);
assert_eq!(
transport.requests()[0].url,
"https://api.lettermint.co/v1/messages/message%20id/process"
);
}

#[test]
fn documented_operations_are_exposed() {
assert_eq!(lettermint::endpoints::OPERATION_IDS.len(), 49);
assert_eq!(lettermint::endpoints::OPERATION_IDS.len(), 50);
assert!(lettermint::endpoints::OPERATION_IDS.contains(&"processInboundMessage"));
assert!(lettermint::endpoints::OPERATION_IDS.contains(&"v1.sendMail"));
assert!(lettermint::endpoints::OPERATION_IDS.contains(&"webhook.showDelivery"));
}
Expand Down
Loading