1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
use std::sync::Arc;
use serde::Serialize;
use serde_json::Value;
use crate::client::Inner;
use crate::error::Result;
use crate::params;
/// The `suppressions` resource (the org-wide do-not-send list). Reached through
/// [`Mailtea::suppressions`](crate::Mailtea::suppressions).
///
/// Suppressions are team-scoped — there is no `publication_id`.
#[derive(Clone, Debug)]
pub struct Suppressions {
inner: Arc<Inner>,
}
impl Suppressions {
pub(crate) fn new(inner: Arc<Inner>) -> Self {
Self { inner }
}
/// `GET /v1/suppressions` — list entries, cursor-paginated. Optional
/// filters: `reason`, `q` (email search), `created_after`,
/// `created_before`, `limit`, `starting_after`.
pub async fn list(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"GET",
&format!("/v1/suppressions{}", params::query(params)?),
None,
)
.await
}
/// `POST /v1/suppressions` — add addresses. Takes `emails` (up to 1000) and
/// an optional `reason`. Returns `{"added": ...}`.
pub async fn add(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call("POST", "/v1/suppressions", crate::params::to_body(params)?)
.await
}
/// `DELETE /v1/suppressions` — remove addresses. Takes `emails`. Returns
/// `{"removed": ...}`.
pub async fn remove(&self, params: impl Serialize) -> Result<Value> {
self.inner
.call(
"DELETE",
"/v1/suppressions",
crate::params::to_body(params)?,
)
.await
}
/// `GET /v1/suppressions/export` — the whole list as CSV.
///
/// Returns the raw `text/csv` body (`email,reason,source,created_at` with a
/// header row), not JSON.
pub async fn export(&self) -> Result<String> {
self.inner
.call_text("GET", "/v1/suppressions/export", None)
.await
}
}