hevy 0.1.0

An async Rust client library for the Hevy public API (https://api.hevyapp.com/docs/)
Documentation
//! A tour of the main `hevy` crate features.
//!
//! Set the `HEVY_API_KEY` environment variable (get one at
//! https://hevy.com/settings?developer, requires Hevy Pro) and run with:
//!
//! ```sh
//! HEVY_API_KEY=your-key cargo run --example basic_usage
//! ```

use hevy::{CreateWorkoutRequest, HevyClient, NewWorkout, WorkoutExerciseInput, WorkoutSetInput};

#[tokio::main]
async fn main() -> hevy::Result<()> {
    let api_key = std::env::var("HEVY_API_KEY").expect("set the HEVY_API_KEY environment variable");
    let client = HevyClient::new(api_key);

    // Who are we?
    let user = client.get_user_info().await?;
    println!("Logged in as {} ({})", user.name, user.url);

    // How many workouts do we have logged?
    let count = client.workout_count().await?;
    println!("You have logged {count} workouts");

    // Fetch the most recent page of workouts.
    let page = client.list_workouts(Some(1), Some(5)).await?;
    println!("Page {}/{}:", page.page, page.page_count);
    for workout in &page.workouts {
        println!("  - {} ({})", workout.title, workout.id);
    }

    // Look up the first exercise template available on the account so we have
    // a valid id to log a workout against.
    let templates = client.list_exercise_templates(Some(1), Some(1)).await?;
    let Some(template) = templates.exercise_templates.first() else {
        println!("No exercise templates available, skipping workout creation.");
        return Ok(());
    };

    // Log a new workout using that exercise.
    let workout = NewWorkout::new(
        "Hevy crate demo workout",
        "2024-08-14T12:00:00Z",
        "2024-08-14T12:30:00Z",
    )
    .with_exercise(
        WorkoutExerciseInput::new(&template.id)
            .with_set(WorkoutSetInput::warmup(40.0, 12))
            .with_set(WorkoutSetInput::normal(80.0, 10)),
    );

    let created = client
        .create_workout(&CreateWorkoutRequest::new(workout))
        .await?;
    println!("Created workout '{}' with id {}", created.title, created.id);

    Ok(())
}