sendgrid2/request/
get_categories.rs

1use serde_json::json;
2use crate::model::*;
3use crate::SendgridClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct GetCategoriesRequest<'a> {
8    pub(crate) client: &'a SendgridClient,
9    pub limit: Option<i64>,
10    pub category: Option<String>,
11    pub offset: Option<i64>,
12    pub on_behalf_of: Option<String>,
13}
14impl<'a> GetCategoriesRequest<'a> {
15    pub async fn send(self) -> anyhow::Result<Vec<serde_json::Value>> {
16        let mut r = self.client.client.get("/v3/categories");
17        if let Some(ref unwrapped) = self.limit {
18            r = r.push_query("limit", &unwrapped.to_string());
19        }
20        if let Some(ref unwrapped) = self.category {
21            r = r.push_query("category", &unwrapped.to_string());
22        }
23        if let Some(ref unwrapped) = self.offset {
24            r = r.push_query("offset", &unwrapped.to_string());
25        }
26        if let Some(ref unwrapped) = self.on_behalf_of {
27            r = r.header("on-behalf-of", &unwrapped.to_string());
28        }
29        r = self.client.authenticate(r);
30        let res = r.send().await.unwrap().error_for_status();
31        match res {
32            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
33            Err(res) => {
34                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
35                Err(anyhow::anyhow!("{:?}", text))
36            }
37        }
38    }
39    pub fn limit(mut self, limit: i64) -> Self {
40        self.limit = Some(limit);
41        self
42    }
43    pub fn category(mut self, category: &str) -> Self {
44        self.category = Some(category.to_owned());
45        self
46    }
47    pub fn offset(mut self, offset: i64) -> Self {
48        self.offset = Some(offset);
49        self
50    }
51    pub fn on_behalf_of(mut self, on_behalf_of: &str) -> Self {
52        self.on_behalf_of = Some(on_behalf_of.to_owned());
53        self
54    }
55}