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