postmark/api/bounce/
delivery_stats.rs1use crate::Endpoint;
2use serde::{Deserialize, Serialize};
3use std::borrow::Cow;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
6pub struct DeliveryStatsRequest {}
7
8impl Endpoint for DeliveryStatsRequest {
9 type Request = ();
10 type Response = DeliveryStatsResponse;
11
12 fn endpoint(&self) -> Cow<'static, str> {
13 "/deliverystats".into()
14 }
15
16 fn body(&self) -> &Self::Request {
17 &()
18 }
19
20 fn method(&self) -> http::Method {
21 http::Method::GET
22 }
23}
24
25#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
26#[serde(rename_all = "PascalCase")]
27
28pub struct DeliveryStatsResponse {
29 #[serde(rename = "InactiveMails")]
30 pub inactive_mails: i64,
32 pub bounces: Vec<Bounce>,
34}
35
36#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
37#[serde(rename_all = "PascalCase")]
38pub struct Bounce {
39 pub name: String,
40 pub count: i64,
41 pub type_field: Option<String>,
42}
43
44#[cfg(test)]
45mod tests {
46 use httptest::matchers::request;
47 use httptest::{responders::*, Expectation, Server};
48 use serde_json::json;
49
50 use super::DeliveryStatsRequest;
51 use crate::reqwest::PostmarkClient;
52 use crate::Query;
53
54 #[tokio::test]
55 pub async fn send_get_deliverystats() {
56 let server = Server::run();
57
58 server.expect(
59 Expectation::matching(request::method_path("GET", "/deliverystats")).respond_with(
60 json_encoded(json!({
61 "InactiveMails": 192,
62 "Bounces": [
63 {
64 "Name": "All",
65 "Count": 253
66 },
67 {
68 "Type": "HardBounce",
69 "Name": "Hard bounce",
70 "Count": 195
71 },
72 {
73 "Type": "Transient",
74 "Name": "Message delayed",
75 "Count": 10
76 },
77 {
78 "Type": "AutoResponder",
79 "Name": "Auto responder",
80 "Count": 14
81 },
82 {
83 "Type": "SpamNotification",
84 "Name": "Spam notification",
85 "Count": 3
86 },
87 {
88 "Type": "SoftBounce",
89 "Name": "Soft bounce",
90 "Count": 30
91 },
92 {
93 "Type": "SpamComplaint",
94 "Name": "Spam complaint",
95 "Count": 1
96 }
97 ]
98 })),
99 ),
100 );
101
102 let client = PostmarkClient::builder()
103 .base_url(server.url("/").to_string())
104 .build();
105
106 let req = DeliveryStatsRequest::default();
107
108 let resp = req
109 .execute(&client)
110 .await
111 .expect("Should get a response and be able to json decode it");
112
113 assert_eq!(resp.inactive_mails, 192);
114 }
115}