pub struct FitbitResponseCache<C: FitbitClientTrait> { /* private fields */ }
Expand description
A cache for Fitbit API responses.
This cache stores responses from the Fitbit API to reduce the number of API calls made. It caches responses by date, so multiple requests for the same date will only result in a single API call.
Implementations§
Source§impl<C: FitbitClientTrait> FitbitResponseCache<C>
impl<C: FitbitClientTrait> FitbitResponseCache<C>
Sourcepub fn get_sleep_response(
&mut self,
date: NaiveDate,
) -> Result<&SleepResponseV1_2, FitbitError>
pub fn get_sleep_response( &mut self, date: NaiveDate, ) -> Result<&SleepResponseV1_2, FitbitError>
Gets a sleep response for the given date.
If the response is not in the cache, it will be fetched from the API and cached.
§Arguments
date
- The date for which to get sleep data
§Returns
A reference to the cached sleep response or an error if the request failed
§Example
let date = NaiveDate::from_ymd_opt(2023, 1, 1).unwrap();
let sleep_data = cache.get_sleep_response(date);
Sourcepub fn get_activity_summary_response(
&mut self,
date: NaiveDate,
) -> Result<&ActivitySummaryResponse, FitbitError>
pub fn get_activity_summary_response( &mut self, date: NaiveDate, ) -> Result<&ActivitySummaryResponse, FitbitError>
Gets an activity summary response for the given date.
If the response is not in the cache, it will be fetched from the API and cached.
§Arguments
date
- The date for which to get activity data
§Returns
A reference to the cached activity summary response or an error if the request failed
§Example
let date = NaiveDate::from_ymd_opt(2023, 1, 1).unwrap();
let activity_data = cache.get_activity_summary_response(date);
Sourcepub fn clear_cache(&mut self)
pub fn clear_cache(&mut self)
Clears all cached responses.
This can be useful if you want to force a refresh of all data.
Sourcepub fn remove_from_cache(&mut self, date: NaiveDate)
pub fn remove_from_cache(&mut self, date: NaiveDate)
Removes a specific date from the cache.
This can be useful if you want to force a refresh of data for a specific date.
§Arguments
date
- The date to remove from the cache