pub struct Client { /* private fields */ }Expand description
Main Cloudreve API client
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> Self
pub fn new(config: ClientConfig) -> Self
Create a new API client
Sourcepub fn set_on_credential_refreshed(&mut self, callback: OnCredentialRefreshed)
pub fn set_on_credential_refreshed(&mut self, callback: OnCredentialRefreshed)
Set a callback to be invoked when credentials are refreshed
The callback receives the new token information and can perform async operations such as persisting tokens to storage.
§Example
use cloudreve_sdk_api::{Client, ClientConfig};
use std::sync::Arc;
let mut client = Client::new(ClientConfig::new("https://cloudreve.example"));
client.set_on_credential_refreshed(Arc::new(|token| {
Box::pin(async move {
// Save token to storage
println!("New access token: {}", token.access_token);
})
}));Sourcepub fn clear_on_credential_refreshed(&mut self)
pub fn clear_on_credential_refreshed(&mut self)
Clear the credential refresh callback
Sourcepub fn set_on_credential_invalid(&mut self, callback: OnCredentialInvalid)
pub fn set_on_credential_invalid(&mut self, callback: OnCredentialInvalid)
Set a callback to be invoked when credentials are invalid or expired
This callback is triggered when the API returns error codes indicating authentication failure: 401 (LoginRequired), 40020 (CredentialInvalid), or 40089 (SessionExpired).
Sourcepub fn clear_on_credential_invalid(&mut self)
pub fn clear_on_credential_invalid(&mut self)
Clear the credential invalid callback
Sourcepub async fn set_tokens(&self, access_token: String, refresh_token: String)
pub async fn set_tokens(&self, access_token: String, refresh_token: String)
Set authentication tokens
Sourcepub async fn set_tokens_with_expiry(&self, token: &Token) -> ApiResult<()>
pub async fn set_tokens_with_expiry(&self, token: &Token) -> ApiResult<()>
Set tokens from a Token response with explicit expiration times.
Sourcepub async fn clear_tokens(&self)
pub async fn clear_tokens(&self)
Clear all authentication tokens
Sourcepub async fn set_purchase_ticket(&self, ticket: Option<String>)
pub async fn set_purchase_ticket(&self, ticket: Option<String>)
Set the purchase ticket for subsequent requests
Sourcepub async fn send<T, R>(
&self,
path: &str,
method: Method,
body: Option<&T>,
options: RequestOptions,
) -> ApiResult<R>
pub async fn send<T, R>( &self, path: &str, method: Method, body: Option<&T>, options: RequestOptions, ) -> ApiResult<R>
Send an API request with automatic token refresh
Sourcepub async fn get<R>(&self, path: &str, options: RequestOptions) -> ApiResult<R>where
R: DeserializeOwned + Default,
pub async fn get<R>(&self, path: &str, options: RequestOptions) -> ApiResult<R>where
R: DeserializeOwned + Default,
Send a GET request
Sourcepub async fn post<T, R>(
&self,
path: &str,
body: &T,
options: RequestOptions,
) -> ApiResult<R>
pub async fn post<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>
Send a POST request
Sourcepub async fn put<T, R>(
&self,
path: &str,
body: &T,
options: RequestOptions,
) -> ApiResult<R>
pub async fn put<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>
Send a PUT request
Sourcepub async fn delete<R>(
&self,
path: &str,
options: RequestOptions,
) -> ApiResult<R>where
R: DeserializeOwned + Default,
pub async fn delete<R>(
&self,
path: &str,
options: RequestOptions,
) -> ApiResult<R>where
R: DeserializeOwned + Default,
Send a DELETE request
Sourcepub async fn delete_with_body<T, R>(
&self,
path: &str,
body: &T,
options: RequestOptions,
) -> ApiResult<R>
pub async fn delete_with_body<T, R>( &self, path: &str, body: &T, options: RequestOptions, ) -> ApiResult<R>
Send a DELETE request with body