mailgun_sdk/endpoints/
get_bounces.rs

1//! Request and response module for fetching bounces for a domain.
2//!
3//! ### Example
4//!
5//! ```no_run
6//! # use mailgun_sdk::{
7//! #     Client,
8//! #     ParamList,
9//! #     get_bounces::{GetBouncesParam, GetBouncesParamList},
10//! # };
11//! # let client = Client::new("", "");
12//! let request = GetBouncesParamList::default()
13//!     .add(GetBouncesParam::Limit(1));
14//!
15//! let bounces = client.get_bounces(request).unwrap();
16//! ```
17//!
18//! [API Documentation](https://documentation.mailgun.com/en/latest/api-suppressions.html#bounces)
19
20use crate::{Paging, Param, ParamError, ParamList};
21
22//- Request
23
24/// A parameter for fetching bounces for a domain.
25#[derive(Debug)]
26pub enum GetBouncesParam {
27    /// Maximum number of records to return (default: 100, max: 10000).
28    Limit(usize),
29}
30
31impl Param for GetBouncesParam {
32    fn try_as_tuple(&self) -> Result<(String, String), ParamError> {
33        Ok(match self {
34            Self::Limit(v) => ("limit".to_string(), v.to_string()),
35        })
36    }
37}
38
39/// List of parameters for fetching bounces for a domain.
40#[derive(Debug)]
41pub struct GetBouncesParamList {
42    pub values: Vec<GetBouncesParam>,
43}
44
45impl Default for GetBouncesParamList {
46    fn default() -> Self {
47        Self {
48            values: vec![],
49        }
50    }
51}
52
53impl ParamList for GetBouncesParamList {
54    type ParamType = GetBouncesParam;
55
56    fn add(mut self, param: Self::ParamType) -> Self {
57        self.values.push(param);
58
59        self
60    }
61}
62
63//- Response
64
65/// Response returned by get bounces endpoint.
66#[derive(Debug, Deserialize, Serialize)]
67pub struct GetBouncesResponse {
68    pub items: Vec<BounceItem>,
69    pub paging: Paging,
70}
71
72/// A single item found in [`GetBouncesResponse`](struct.GetBouncesResponse.html).
73#[derive(Debug, Deserialize, Serialize)]
74pub struct BounceItem {
75    pub address: String,
76    pub code: String,
77    pub error: String,
78    pub created_at: String,
79}