sure_client_rs/client/usage.rs
1use crate::error::ApiResult;
2use crate::models::usage::UsageResponse;
3use reqwest::Method;
4
5use super::SureClient;
6
7impl SureClient {
8 /// Get API usage information
9 ///
10 /// Returns usage statistics for API key authentication or a message for OAuth authentication.
11 ///
12 /// # Returns
13 /// Usage response containing either API key usage information or OAuth authentication message.
14 ///
15 /// # Errors
16 /// Returns `ApiError::Unauthorized` if the API key is invalid.
17 /// Returns `ApiError::Network` if the request fails due to network issues.
18 ///
19 /// # Example
20 /// ```no_run
21 /// use sure_client_rs::{SureClient, BearerToken};
22 /// use sure_client_rs::models::usage::UsageResponse;
23 ///
24 /// # async fn example(client: SureClient) -> Result<(), Box<dyn std::error::Error>> {
25 /// let response = client.get_usage().await?;
26 ///
27 /// match response {
28 /// UsageResponse::ApiKey(usage) => {
29 /// println!("API Key: {}", usage.api_key.name);
30 /// println!("Current count: {}", usage.rate_limit.current_count);
31 /// if let Some(remaining) = usage.rate_limit.remaining {
32 /// println!("Remaining requests: {}", remaining);
33 /// }
34 /// }
35 /// UsageResponse::OAuth(info) => {
36 /// println!("OAuth: {}", info.message);
37 /// }
38 /// }
39 /// # Ok(())
40 /// # }
41 /// ```
42 ///
43 pub async fn get_usage(&self) -> ApiResult<UsageResponse> {
44 self.execute_request(Method::GET, "/api/v1/usage", None, None)
45 .await
46 }
47}