pub struct GmailClient { /* private fields */ }Expand description
HTTP client for the Gmail v1 REST API.
Implementations§
Source§impl GmailClient
impl GmailClient
Sourcepub fn new(base_url: &str, credentials: &GmailCredentials) -> Result<Self>
pub fn new(base_url: &str, credentials: &GmailCredentials) -> Result<Self>
Builds a client against base_url with already-loaded credentials.
For production use, construct via Self::from_credentials; tests
pass a wiremock URL directly.
Sourcepub fn from_credentials(credentials: &GmailCredentials) -> Result<Self>
pub fn from_credentials(credentials: &GmailCredentials) -> Result<Self>
Creates a client from stored credentials against the real Gmail API host.
Respects GMAIL_API_URL as an optional override: when set (and
non-empty) in the process environment it replaces
Self::DEFAULT_BASE_URL wholesale. Added per PR #1466 review —
without it, exercising the CLI’s output shapes required a real
Google Cloud project, and there was no way to route through a forced
egress proxy.
Sourcepub async fn get_json(&self, url: &str) -> Result<Response>
pub async fn get_json(&self, url: &str) -> Result<Response>
Sends an authenticated GET request and returns the raw response.
Retries exactly once on HTTP 401 by forcing a session refresh — see
Self::send_authorized for why both a proactive and a reactive
refresh path exist.
Sourcepub async fn post_json<T: Serialize + Sync + ?Sized>(
&self,
url: &str,
body: &T,
) -> Result<Response>
pub async fn post_json<T: Serialize + Sync + ?Sized>( &self, url: &str, body: &T, ) -> Result<Response>
Sends an authenticated POST request with a JSON body and returns the raw response.
Sourcepub async fn response_to_error(response: Response) -> GmailError
pub async fn response_to_error(response: Response) -> GmailError
Consumes a non-success response into a GmailError.
Parses Gmail’s {"error":{"message":...,"errors":[{"reason":...}]}}
envelope into a human message when present (falls back to the raw
body otherwise). Gmail signals quota exhaustion as 403
rateLimitExceeded/userRateLimitExceeded, not 429 — unlike plain
429s, that shape now also drives a retry (see [is_gmail_quota_exceeded]
via retry_if), so this only sees the
error once retries are exhausted (or the reason didn’t match).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for GmailClient
impl !RefUnwindSafe for GmailClient
impl !UnwindSafe for GmailClient
impl Send for GmailClient
impl Sync for GmailClient
impl Unpin for GmailClient
impl UnsafeUnpin for GmailClient
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more