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).