Skip to content

Commit

Permalink
Use client builder bearer auth for email
Browse files Browse the repository at this point in the history
  • Loading branch information
rgardner committed Mar 10, 2020
1 parent 9db1096 commit 74fbef7
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions app/pocket_cleaner/src/email.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::fmt;

use actix_web::{
client::Client,
client::{Client, ClientBuilder},
http::{header::ContentType, uri::Uri, PathAndQuery},
};
use serde::Serialize;
Expand Down Expand Up @@ -38,18 +38,16 @@ impl SendGridAPIClient {
}

pub async fn send(&self, mail: &Mail) -> Result<()> {
let client = Client::default();
let req = SendMailRequest {
sendgrid_api_key: self.sendgrid_api_key.clone(),
mail: mail.clone(),
};
let client = ClientBuilder::new()
.bearer_auth(&self.sendgrid_api_key)
.finish();
let req = SendMailRequest { mail: mail.clone() };
send_send_mail_request(&client, &req).await?;
Ok(())
}
}

struct SendMailRequest {
sendgrid_api_key: String,
mail: Mail,
}

Expand Down Expand Up @@ -124,7 +122,6 @@ async fn send_send_mail_request(client: &Client, req: &SendMailRequest) -> Resul
let mut resp = client
.post(url)
.content_type("application/json")
.bearer_auth(&req.sendgrid_api_key)
.send_json(&body)
.await
.map_err(|e| PocketCleanerError::Unknown(e.to_string()))?;
Expand Down

0 comments on commit 74fbef7

Please sign in to comment.