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::{CreateRoutineRequest, Routine, RoutinesPage, UpdateRoutineRequest};
use crate::models::RoutineEnvelope;

impl HevyClient {
    /// Gets a paginated list of routines.
    ///
    /// `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_routines(
        &self,
        page: Option<u32>,
        page_size: Option<u32>,
    ) -> Result<RoutinesPage> {
        self.get(
            "/v1/routines",
            &[
                ("page", page.map(|p| p.to_string())),
                ("pageSize", page_size.map(|p| p.to_string())),
            ],
        )
        .await
    }

    /// Gets a routine by its id.
    pub async fn get_routine(&self, routine_id: &str) -> Result<Routine> {
        let envelope: RoutineEnvelope = self.get(&format!("/v1/routines/{routine_id}"), &[]).await?;
        Ok(envelope.routine)
    }

    /// Creates a new routine.
    pub async fn create_routine(&self, request: &CreateRoutineRequest) -> Result<Routine> {
        self.post("/v1/routines", request).await
    }

    /// Updates an existing routine.
    pub async fn update_routine(
        &self,
        routine_id: &str,
        request: &UpdateRoutineRequest,
    ) -> Result<Routine> {
        self.put(&format!("/v1/routines/{routine_id}"), request)
            .await
    }
}