hevy 0.1.0

An async Rust client library for the Hevy public API (https://api.hevyapp.com/docs/)
Documentation
use crate::client::HevyClient;
use crate::error::Result;
use crate::models::{CreateWorkoutRequest, PaginatedWorkoutEvents, Workout, WorkoutCount, WorkoutsPage};

impl HevyClient {
    /// Gets a paginated list of workouts, ordered from oldest to newest.
    ///
    /// `page` must be 1 or greater (defaults to `1`). `page_size` is capped at 10
    /// by the API (defaults to `5`).
    pub async fn list_workouts(
        &self,
        page: Option<u32>,
        page_size: Option<u32>,
    ) -> Result<WorkoutsPage> {
        self.get(
            "/v1/workouts",
            &[
                ("page", page.map(|p| p.to_string())),
                ("pageSize", page_size.map(|p| p.to_string())),
            ],
        )
        .await
    }

    /// Gets a single workout's complete details by its id.
    pub async fn get_workout(&self, workout_id: &str) -> Result<Workout> {
        self.get(&format!("/v1/workouts/{workout_id}"), &[]).await
    }

    /// Creates a new workout.
    pub async fn create_workout(&self, request: &CreateWorkoutRequest) -> Result<Workout> {
        self.post("/v1/workouts", request).await
    }

    /// Updates an existing workout.
    pub async fn update_workout(
        &self,
        workout_id: &str,
        request: &CreateWorkoutRequest,
    ) -> Result<Workout> {
        self.put(&format!("/v1/workouts/{workout_id}"), request)
            .await
    }

    /// Gets the total number of workouts on the account.
    pub async fn workout_count(&self) -> Result<u64> {
        let response: WorkoutCount = self.get("/v1/workouts/count", &[]).await?;
        Ok(response.workout_count)
    }

    /// Retrieves a paginated list of workout events (updates or deletes) since a
    /// given date, ordered from newest to oldest.
    ///
    /// This allows clients to keep a local cache of workouts up to date without
    /// re-fetching the entire list. `since` should be an ISO 8601 timestamp
    /// (defaults to the Unix epoch).
    pub async fn workout_events(
        &self,
        page: Option<u32>,
        page_size: Option<u32>,
        since: Option<&str>,
    ) -> Result<PaginatedWorkoutEvents> {
        self.get(
            "/v1/workouts/events",
            &[
                ("page", page.map(|p| p.to_string())),
                ("pageSize", page_size.map(|p| p.to_string())),
                ("since", since.map(|s| s.to_string())),
            ],
        )
        .await
    }
}