sendgrid2/request/
get_user_username.rs1use serde_json::json;
2use crate::model::*;
3use crate::SendgridClient;
4pub struct GetUserUsernameRequest<'a> {
8 pub(crate) client: &'a SendgridClient,
9 pub on_behalf_of: Option<String>,
10}
11impl<'a> GetUserUsernameRequest<'a> {
12 pub async fn send(self) -> anyhow::Result<serde_json::Value> {
13 let mut r = self.client.client.get("/v3/user/username");
14 if let Some(ref unwrapped) = self.on_behalf_of {
15 r = r.header("on-behalf-of", &unwrapped.to_string());
16 }
17 r = self.client.authenticate(r);
18 let res = r.send().await.unwrap().error_for_status();
19 match res {
20 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
21 Err(res) => {
22 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
23 Err(anyhow::anyhow!("{:?}", text))
24 }
25 }
26 }
27 pub fn on_behalf_of(mut self, on_behalf_of: &str) -> Self {
28 self.on_behalf_of = Some(on_behalf_of.to_owned());
29 self
30 }
31}