From e3932c89ab52a4cf0366b6172c03eb6430d23a1b Mon Sep 17 00:00:00 2001 From: Jeremiah Russell Date: Wed, 1 Oct 2025 09:59:28 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(gmail):=20add=20gmail=20client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - implement client for gmail api - implement auth for gmail api --- src/client.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/client.rs diff --git a/src/client.rs b/src/client.rs new file mode 100644 index 0000000..23a9626 --- /dev/null +++ b/src/client.rs @@ -0,0 +1,29 @@ +use google_gmail1::{ + common::Client, + hyper_rustls::{self, HttpsConnector}, + hyper_util::{self, client::legacy::connect::HttpConnector}, + yup_oauth2::{self, ApplicationSecret, authenticator::Authenticator}, +}; + +/// Get auth for gmail +pub async fn get_auth(secret: ApplicationSecret) -> Authenticator> { + yup_oauth2::InstalledFlowAuthenticator::builder( + secret, + yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect, + ) + .build() + .await + .unwrap() +} + +/// Get client for gmail +pub fn get_client() -> Client> { + hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new()).build( + hyper_rustls::HttpsConnectorBuilder::new() + .with_native_roots() + .unwrap() + .https_or_http() + .enable_http1() + .build(), + ) +}