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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
}
}