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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//! Broadcast campaigns.
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::{client::Sendry, error::Error, Page};
/// Campaigns resource handle.
#[derive(Debug, Clone)]
pub struct Campaigns {
client: Sendry,
}
impl Campaigns {
pub(crate) fn new(client: Sendry) -> Self {
Self { client }
}
/// Create a draft campaign.
pub async fn create(&self, params: CampaignParams) -> Result<Campaign, Error> {
self.client
.request(
self.client
.build(Method::POST, "/v1/campaigns", &[], Some(¶ms)),
)
.await
}
/// Retrieve a campaign.
pub async fn get(&self, id: &str) -> Result<Campaign, Error> {
self.client
.request(self.client.build::<()>(
Method::GET,
&format!("/v1/campaigns/{id}"),
&[],
None,
))
.await
}
/// List campaigns.
pub async fn list(&self) -> Result<Page<Campaign>, Error> {
self.client
.request(
self.client
.build::<()>(Method::GET, "/v1/campaigns", &[], None),
)
.await
}
/// Send a campaign immediately.
pub async fn send(&self, id: &str) -> Result<Campaign, Error> {
self.client
.request(self.client.build::<()>(
Method::POST,
&format!("/v1/campaigns/{id}/send"),
&[],
None,
))
.await
}
}
/// Parameters for creating a campaign.
#[derive(Debug, Clone, Serialize)]
pub struct CampaignParams {
/// Display name.
pub name: String,
/// Subject line.
pub subject: String,
/// Sender address.
pub from: String,
/// Audience to send to.
pub audience_id: String,
/// HTML body.
pub html: String,
/// Plain-text body.
pub text: String,
}
/// Campaign record returned by the API.
#[derive(Debug, Clone, Deserialize)]
pub struct Campaign {
/// Campaign id.
pub id: String,
/// Display name.
pub name: String,
/// `draft`, `sending`, `sent`, `paused`, `cancelled`.
pub status: String,
/// Count of emails sent so far.
pub sent_count: u32,
/// Total recipients.
pub total_recipients: u32,
/// Creation timestamp.
pub created_at: String,
}