postmark/api/webhooks/
delete_webhook.rs1use std::borrow::Cow;
2
3use crate::Endpoint;
4use crate::api::endpoint_with_path_segment;
5use crate::api::webhooks::WebhookId;
6use serde::{Deserialize, Serialize};
7use typed_builder::TypedBuilder;
8
9#[derive(Debug, Clone, PartialEq, Serialize, TypedBuilder)]
10#[serde(rename_all = "PascalCase")]
11pub struct DeleteWebhookRequest {
12 #[builder(setter(into))]
13 #[serde(skip)]
14 pub webhook_id: WebhookId,
15}
16
17#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
18#[serde(rename_all = "PascalCase")]
19pub struct DeleteWebhookResponse {
20 pub error_code: i64,
21 pub message: String,
22}
23
24impl Endpoint for DeleteWebhookRequest {
25 type Request = DeleteWebhookRequest;
26 type Response = DeleteWebhookResponse;
27
28 fn endpoint(&self) -> Cow<'static, str> {
29 endpoint_with_path_segment("/webhooks", &self.webhook_id.to_string())
30 }
31
32 fn body(&self) -> &Self::Request {
33 self
34 }
35
36 fn method(&self) -> http::Method {
37 http::Method::DELETE
38 }
39}
40
41#[cfg(test)]
42mod tests {
43 use httptest::matchers::request;
44 use httptest::{Expectation, Server, responders::*};
45 use serde_json::json;
46
47 use crate::Query;
48 use crate::reqwest::PostmarkClient;
49
50 use super::*;
51
52 #[tokio::test]
53 pub async fn delete_webhook() {
54 let server = Server::run();
55
56 server.expect(
57 Expectation::matching(request::method_path("DELETE", "/webhooks/1234")).respond_with(
58 json_encoded(json!({
59 "ErrorCode": 0,
60 "Message": "Webhook 1234 removed."
61 })),
62 ),
63 );
64
65 let client = PostmarkClient::builder()
66 .base_url(server.url("/").to_string())
67 .build();
68
69 let req = DeleteWebhookRequest::builder().webhook_id(1234).build();
70
71 let resp = req
72 .execute(&client)
73 .await
74 .expect("Should get a response and be able to json decode it");
75
76 assert_eq!(resp.error_code, 0);
77 assert_eq!(resp.message, "Webhook 1234 removed.");
78 }
79}