pub struct DriveClient { /* private fields */ }Expand description
HTTP client for the Drive v3 REST API.
Implementations§
Source§impl DriveClient
impl DriveClient
Sourcepub fn new(base_url: &str, credentials: &DriveCredentials) -> Result<Self>
pub fn new(base_url: &str, credentials: &DriveCredentials) -> 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: &DriveCredentials) -> Result<Self>
pub fn from_credentials(credentials: &DriveCredentials) -> Result<Self>
Creates a client from stored credentials against the real Drive API host.
Respects DRIVE_API_URL as an optional override: when set (and
non-empty) in the process environment it replaces
Self::DEFAULT_BASE_URL wholesale — mirrors Gmail’s GMAIL_API_URL
(PR #1466), used to exercise CLI output shapes without a real Google
Cloud project or 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 get_bytes(&self, url: &str) -> Result<Response>
pub async fn get_bytes(&self, url: &str) -> Result<Response>
Sends an authenticated GET request without forcing an Accept: application/json header, for endpoints that return raw bytes rather
than JSON (files.export, files.get?alt=media) — see
Self::get_json for the JSON counterpart. Retries exactly once on
HTTP 401, identically to get_json.
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 patch_json<T: Serialize + Sync + ?Sized>(
&self,
url: &str,
body: &T,
) -> Result<Response>
pub async fn patch_json<T: Serialize + Sync + ?Sized>( &self, url: &str, body: &T, ) -> Result<Response>
Sends an authenticated PATCH request with a JSON body and returns the
raw response. Drive’s files.update (rename/move) is the only PATCH
endpoint this client calls.
Sourcepub async fn response_to_error(response: Response) -> DriveError
pub async fn response_to_error(response: Response) -> DriveError
Consumes a non-success response into a DriveError.
Parses Drive’s {"error":{"message":...,"errors":[{"reason":...}]}}
envelope (the same shape every Google API error uses) into a human
message when present (falls back to the raw body otherwise). Drive
signals quota exhaustion as 403 userRateLimitExceeded, not
429 — unlike plain 429s, that shape now also drives a retry (see
[is_drive_quota_exceeded] via retry_if),
so this only sees the error once retries are exhausted (or the
reason didn’t match).