use crate::api::helpers::{fetch_from_strava_api, strava_v3};
use crate::models::{athlete, clubs};
use log::{info, trace};
pub fn get_athlete(
access_token: &str,
) -> Result<athlete::AthleteCollection, Box<dyn std::error::Error>> {
let url = strava_v3("athlete".to_string());
info!("Calling Strava Athlete API");
let response = fetch_from_strava_api(url, access_token)?;
trace!("Athlete API response: {:?}\n", response);
let athlete: athlete::AthleteCollection = response.json()?;
Ok(athlete)
}
pub fn get_athlete_stats(
access_token: &str,
athlete_id: &str,
) -> Result<athlete::AthleteStats, Box<dyn std::error::Error>> {
let path = format!("athletes/{}/stats", athlete_id);
let url = strava_v3(path);
let response = fetch_from_strava_api(url, access_token)?;
info!("Calling Athlete Stats API\n");
trace!("Athlete Stats API response: {:?}\n", response);
let athlete_stats: athlete::AthleteStats = response.json()?;
Ok(athlete_stats)
}
pub fn get_athlete_clubs(
access_token: &str,
) -> Result<clubs::ClubCollection, Box<dyn std::error::Error>> {
let url = strava_v3("athlete/clubs".to_string());
let response = fetch_from_strava_api(url, access_token)?;
let clubs: clubs::ClubCollection = response.json()?;
Ok(clubs)
}