sendgrid2/request/
patch_marketing_singlesends_id.rs1use serde_json::json;
2use crate::model::*;
3use crate::SendgridClient;
4pub struct PatchMarketingSinglesendsIdRequest<'a> {
8 pub(crate) client: &'a SendgridClient,
9 pub id: String,
10 pub categories: Option<Vec<String>>,
11 pub email_config: Option<serde_json::Value>,
12 pub name: String,
13 pub send_at: Option<String>,
14 pub send_to: Option<serde_json::Value>,
15}
16impl<'a> PatchMarketingSinglesendsIdRequest<'a> {
17 pub async fn send(self) -> anyhow::Result<SinglesendResponse> {
18 let mut r = self
19 .client
20 .client
21 .patch(&format!("/v3/marketing/singlesends/{id}", id = self.id));
22 if let Some(ref unwrapped) = self.categories {
23 r = r.push_json(json!({ "categories" : unwrapped }));
24 }
25 if let Some(ref unwrapped) = self.email_config {
26 r = r.push_json(json!({ "email_config" : unwrapped }));
27 }
28 r = r.push_json(json!({ "name" : self.name }));
29 if let Some(ref unwrapped) = self.send_at {
30 r = r.push_json(json!({ "send_at" : unwrapped }));
31 }
32 if let Some(ref unwrapped) = self.send_to {
33 r = r.push_json(json!({ "send_to" : unwrapped }));
34 }
35 r = self.client.authenticate(r);
36 let res = r.send().await.unwrap().error_for_status();
37 match res {
38 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
39 Err(res) => {
40 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
41 Err(anyhow::anyhow!("{:?}", text))
42 }
43 }
44 }
45 pub fn categories(
46 mut self,
47 categories: impl IntoIterator<Item = impl AsRef<str>>,
48 ) -> Self {
49 self
50 .categories = Some(
51 categories.into_iter().map(|s| s.as_ref().to_owned()).collect(),
52 );
53 self
54 }
55 pub fn email_config(mut self, email_config: serde_json::Value) -> Self {
56 self.email_config = Some(email_config);
57 self
58 }
59 pub fn send_at(mut self, send_at: &str) -> Self {
60 self.send_at = Some(send_at.to_owned());
61 self
62 }
63 pub fn send_to(mut self, send_to: serde_json::Value) -> Self {
64 self.send_to = Some(send_to);
65 self
66 }
67}