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 with a JSON body.
Sourcepub async fn post_bytes(
&self,
url: &str,
body: &[u8],
content_type: &str,
) -> Result<Response>
pub async fn post_bytes( &self, url: &str, body: &[u8], content_type: &str, ) -> Result<Response>
Sends an authenticated POST request with a raw byte body and returns
the raw response — for Drive’s multipart-upload endpoint, whose
multipart/related body crate::drive::files_api::FilesApi::upload
hand-assembles (Drive’s upload endpoint rejects the
multipart/form-data reqwest::multipart::Form would produce).
body is cloned per send attempt (send_authorized’s build
closure is Fn, not FnOnce — it may run twice, once on a 401
retry — and reqwest::RequestBuilder::body takes ownership).
Sourcepub async fn patch_bytes(
&self,
url: &str,
body: &[u8],
content_type: &str,
) -> Result<Response>
pub async fn patch_bytes( &self, url: &str, body: &[u8], content_type: &str, ) -> Result<Response>
Sends an authenticated PATCH request with a raw byte body and
returns the raw response —
crate::drive::files_api::FilesApi::edit_content’s simple
media-only content replacement (uploadType=media, no multipart
envelope needed since there’s no accompanying metadata change).
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).
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for DriveClient
impl !RefUnwindSafe for DriveClient
impl !UnwindSafe for DriveClient
impl Send for DriveClient
impl Sync for DriveClient
impl Unpin for DriveClient
impl UnsafeUnpin for DriveClient
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