mailgun_sdk/endpoints/
get_unsubscribes.rs

1//! Request and response module for fetching unsubscribes for a domain.
2//!
3//! ### Example
4//!
5//! ```no_run
6//! # use mailgun_sdk::{
7//! #     Client,
8//! #     ParamList,
9//! #     get_unsubscribes::{GetUnsubscribesParam, GetUnsubscribesParamList},
10//! # };
11//! # let client = Client::new("", "");
12//! let request = GetUnsubscribesParamList::default()
13//!     .add(GetUnsubscribesParam::Limit(1));
14//!
15//! let unsubscribes = client.get_unsubscribes(request).unwrap();
16//! ```
17//!
18//! [API Documentation](https://documentation.mailgun.com/en/latest/api-suppressions.html#unsubscribes)
19
20use crate::{Paging, Param, ParamError, ParamList};
21
22//- Request
23
24/// A parameter for fetching unsubscribes for a domain.
25#[derive(Debug)]
26pub enum GetUnsubscribesParam {
27    /// Maximum number of records to return (default: 100, max: 10000).
28    Limit(usize),
29}
30
31impl Param for GetUnsubscribesParam {
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 unsubscribes for a domain.
40#[derive(Debug)]
41pub struct GetUnsubscribesParamList {
42    pub values: Vec<GetUnsubscribesParam>,
43}
44
45impl Default for GetUnsubscribesParamList {
46    fn default() -> Self {
47        Self {
48            values: vec![],
49        }
50    }
51}
52
53impl ParamList for GetUnsubscribesParamList {
54    type ParamType = GetUnsubscribesParam;
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 unsubscribes endpoint.
66#[derive(Debug, Deserialize, Serialize)]
67pub struct GetUnsubscribesResponse {
68    pub items: Vec<UnsubscribeItem>,
69    pub paging: Paging,
70}
71
72/// A single item found in [`GetUnsubscribesResponse`](struct.GetUnsubscribesResponse.html).
73#[derive(Debug, Deserialize, Serialize)]
74pub struct UnsubscribeItem {
75    pub address: String,
76    pub tag: String,
77    pub created_at: String,
78}