Skip to main content

postmark/api/bounce/
get_bounce.rs

1use std::borrow::Cow;
2
3use crate::Endpoint;
4use crate::api::bounce::{BounceId, BounceInfo};
5use crate::api::endpoint_with_path_segment;
6use serde::Serialize;
7use typed_builder::TypedBuilder;
8
9#[derive(Debug, Clone, PartialEq, Serialize, TypedBuilder)]
10#[serde(rename_all = "PascalCase")]
11pub struct GetBounceRequest {
12    #[builder(setter(into))]
13    #[serde(skip)]
14    pub bounce_id: BounceId,
15}
16
17impl Endpoint for GetBounceRequest {
18    type Request = GetBounceRequest;
19    type Response = BounceInfo;
20
21    fn endpoint(&self) -> Cow<'static, str> {
22        endpoint_with_path_segment("/bounces", &self.bounce_id.to_string())
23    }
24
25    fn body(&self) -> &Self::Request {
26        self
27    }
28
29    fn method(&self) -> http::Method {
30        http::Method::GET
31    }
32}
33
34#[cfg(test)]
35mod tests {
36    use httptest::matchers::request;
37    use httptest::{Expectation, Server, responders::*};
38    use serde_json::json;
39
40    use crate::Query;
41    use crate::reqwest::PostmarkClient;
42
43    use super::*;
44
45    #[tokio::test]
46    pub async fn get_bounce() {
47        let server = Server::run();
48
49        server.expect(
50            Expectation::matching(request::method_path("GET", "/bounces/42")).respond_with(
51                json_encoded(json!({
52                    "ID": 42,
53                    "Type": "HardBounce",
54                    "TypeCode": 1,
55                    "Name": "Hard bounce",
56                    "Tag": "Invitation",
57                    "MessageID": "0aa96361",
58                    "Description": "The server was unable to deliver your message",
59                    "Details": "relay=none, delay=0.16",
60                    "Email": "zaphod@example.com",
61                    "BouncedAt": "2019-06-18T07:27:19.0000000-04:00",
62                    "DumpAvailable": true,
63                    "Inactive": true,
64                    "CanActivate": true,
65                    "Content": null,
66                    "Subject": null
67                })),
68            ),
69        );
70
71        let client = PostmarkClient::builder()
72            .base_url(server.url("/").to_string())
73            .build();
74
75        let req = GetBounceRequest::builder().bounce_id(42).build();
76        let resp = req.execute(&client).await.expect("json decode");
77        assert_eq!(resp.id, 42);
78    }
79}