pub struct WakaClient { /* private fields */ }Expand description
Async HTTP client for the WakaTime API v1.
All requests are authenticated via HTTP Basic auth using the supplied API key. The client performs automatic retry with exponential back-off on transient errors (network failures and HTTP 5xx responses).
§Example
use waka_api::WakaClient;
let client = WakaClient::new("waka_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
let me = client.me().await?;
println!("Logged in as {}", me.username);Implementations§
Source§impl WakaClient
impl WakaClient
Sourcepub fn new(api_key: &str) -> Self
pub fn new(api_key: &str) -> Self
Creates a new client pointing at the production WakaTime API.
§Panics
Panics if the default base URL cannot be parsed (compile-time constant — this is unreachable in practice).
Sourcepub fn with_base_url(api_key: &str, base_url: &str) -> Result<Self, ApiError>
pub fn with_base_url(api_key: &str, base_url: &str) -> Result<Self, ApiError>
Creates a new client pointing at a custom base URL.
Primarily used in tests to target a wiremock mock server.
§Errors
Returns an error if base_url is not a valid URL.
Sourcepub async fn me(&self) -> Result<User, ApiError>
pub async fn me(&self) -> Result<User, ApiError>
Returns the profile of the currently authenticated user.
Calls GET /users/current.
§Errors
Returns ApiError::Unauthorized if the API key is invalid.
Returns ApiError::NetworkError on connection or timeout failures.
Sourcepub async fn summaries(
&self,
params: SummaryParams,
) -> Result<SummaryResponse, ApiError>
pub async fn summaries( &self, params: SummaryParams, ) -> Result<SummaryResponse, ApiError>
Returns coding summaries for the date range described by params.
Calls GET /users/current/summaries.
§Errors
Returns ApiError::Unauthorized if the API key is invalid.
Returns ApiError::NetworkError on connection or timeout failures.
Returns ApiError::ParseError if the response cannot be deserialized.
Sourcepub async fn projects(&self) -> Result<ProjectsResponse, ApiError>
pub async fn projects(&self) -> Result<ProjectsResponse, ApiError>
Returns all projects the authenticated user has logged time against.
Calls GET /users/current/projects.
§Errors
Returns ApiError::Unauthorized if the API key is invalid.
Returns ApiError::NetworkError on connection or timeout failures.
Returns ApiError::ParseError if the response cannot be deserialized.
Sourcepub async fn stats(&self, range: StatsRange) -> Result<StatsResponse, ApiError>
pub async fn stats(&self, range: StatsRange) -> Result<StatsResponse, ApiError>
Returns aggregated coding stats for the given predefined range.
Calls GET /users/current/stats/{range}.
§Errors
Returns ApiError::Unauthorized if the API key is invalid.
Returns ApiError::NetworkError on connection or timeout failures.
Returns ApiError::ParseError if the response cannot be deserialized.
Sourcepub async fn goals(&self) -> Result<GoalsResponse, ApiError>
pub async fn goals(&self) -> Result<GoalsResponse, ApiError>
Returns all coding goals for the authenticated user.
Calls GET /users/current/goals.
§Errors
Returns ApiError::Unauthorized if the API key is invalid.
Returns ApiError::NetworkError on connection or timeout failures.
Returns ApiError::ParseError if the response cannot be deserialized.
Sourcepub async fn leaderboard(
&self,
page: u32,
) -> Result<LeaderboardResponse, ApiError>
pub async fn leaderboard( &self, page: u32, ) -> Result<LeaderboardResponse, ApiError>
Returns the public WakaTime leaderboard for the given page.
Page numbers are 1-based. Calls GET /users/current/leaderboards.
§Errors
Returns ApiError::Unauthorized if the API key is invalid.
Returns ApiError::NetworkError on connection or timeout failures.
Returns ApiError::ParseError if the response cannot be deserialized.
Trait Implementations§
Source§impl Clone for WakaClient
impl Clone for WakaClient
Source§fn clone(&self) -> WakaClient
fn clone(&self) -> WakaClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more