pub struct ApiClient { /* private fields */ }Expand description
Asynchronous Asana API client handling retries, rate limiting, and caching.
Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn builder(token: AuthToken) -> ApiClientBuilder
pub fn builder(token: AuthToken) -> ApiClientBuilder
Create a builder for configuring the client.
Sourcepub fn new(token: AuthToken) -> Result<Self, ApiError>
pub fn new(token: AuthToken) -> Result<Self, ApiError>
Construct a client with default options.
§Errors
Returns an error if the cache directory cannot be created or if the HTTP client fails to initialize.
Sourcepub fn with_options(
token: AuthToken,
options: ApiClientOptions,
) -> Result<Self, ApiError>
pub fn with_options( token: AuthToken, options: ApiClientOptions, ) -> Result<Self, ApiError>
Construct a client with specific options.
§Errors
Returns an error if the cache directory cannot be created or if the HTTP client fails to initialize.
Sourcepub fn set_offline(&self, offline: bool)
pub fn set_offline(&self, offline: bool)
Update offline mode at runtime.
Sourcepub fn is_offline(&self) -> bool
pub fn is_offline(&self) -> bool
Determine if offline mode is active.
Sourcepub async fn rate_limit_info(&self) -> Option<RateLimitInfo>
pub async fn rate_limit_info(&self) -> Option<RateLimitInfo>
Retrieve the most recent rate-limit information captured from the API.
Sourcepub async fn get_json<T>(
&self,
path: &str,
query: &[(&str, &str)],
) -> Result<T, ApiError>where
T: DeserializeOwned,
pub async fn get_json<T>(
&self,
path: &str,
query: &[(&str, &str)],
) -> Result<T, ApiError>where
T: DeserializeOwned,
Retrieve JSON from an endpoint and deserialize into T.
§Errors
Returns an error if the network request fails, the response is invalid, or deserialization fails.
Sourcepub async fn get_current_user(&self) -> Result<Value, ApiError>
pub async fn get_current_user(&self) -> Result<Value, ApiError>
Retrieve the current authenticated user (/users/me).
§Errors
Returns an error if the network request fails, authentication is invalid, or the response cannot be parsed.
Sourcepub async fn post_json<T, R>(&self, path: &str, body: &T) -> Result<R, ApiError>
pub async fn post_json<T, R>(&self, path: &str, body: &T) -> Result<R, ApiError>
POST helper for JSON endpoints returning a structured payload.
§Errors
Returns an error if serialization fails, the network request fails, or the response cannot be deserialized.
Sourcepub async fn post_json_with_query<T, R>(
&self,
path: &str,
query_pairs: Vec<(String, String)>,
body: &T,
) -> Result<R, ApiError>
pub async fn post_json_with_query<T, R>( &self, path: &str, query_pairs: Vec<(String, String)>, body: &T, ) -> Result<R, ApiError>
POST helper accepting explicit query parameters.
§Errors
Returns an error if serialization fails, the network request fails, or the response cannot be deserialized.
Sourcepub async fn post_void<T>(&self, path: &str, body: &T) -> Result<(), ApiError>
pub async fn post_void<T>(&self, path: &str, body: &T) -> Result<(), ApiError>
POST helper for endpoints that do not return a payload.
§Errors
Returns an error if serialization fails or the network request fails.
Sourcepub async fn put_json<T, R>(&self, path: &str, body: &T) -> Result<R, ApiError>
pub async fn put_json<T, R>(&self, path: &str, body: &T) -> Result<R, ApiError>
PUT helper for JSON endpoints returning a structured payload.
§Errors
Returns an error if serialization fails, the network request fails, or the response cannot be deserialized.
Sourcepub async fn put_json_with_query<T, R>(
&self,
path: &str,
query_pairs: Vec<(String, String)>,
body: &T,
) -> Result<R, ApiError>
pub async fn put_json_with_query<T, R>( &self, path: &str, query_pairs: Vec<(String, String)>, body: &T, ) -> Result<R, ApiError>
PUT helper accepting explicit query parameters.
§Errors
Returns an error if serialization fails, the network request fails, or the response cannot be deserialized.
Sourcepub async fn delete(
&self,
path: &str,
query_pairs: Vec<(String, String)>,
) -> Result<(), ApiError>
pub async fn delete( &self, path: &str, query_pairs: Vec<(String, String)>, ) -> Result<(), ApiError>
Sourcepub async fn post_multipart<R>(
&self,
path: &str,
form: Form,
) -> Result<R, ApiError>where
R: DeserializeOwned,
pub async fn post_multipart<R>(
&self,
path: &str,
form: Form,
) -> Result<R, ApiError>where
R: DeserializeOwned,
POST multipart form data.
§Errors
Returns an error if the network request fails or the response cannot be deserialized.
Sourcepub async fn download_file(&self, url: &str) -> Result<Vec<u8>, ApiError>
pub async fn download_file(&self, url: &str) -> Result<Vec<u8>, ApiError>
Download file from URL.
§Errors
Returns an error if the network request fails or the download fails.