Struct FitbitResponseCache

Source
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>

Source

pub fn new(fitbit_client: C) -> Self

Creates a new cache with the given Fitbit client.

§Arguments
  • fitbit_client - The Fitbit client to use for making API calls
§Example
use fitbit_rs::{FitbitClient, FitbitResponseCache};

let client = FitbitClient::new("your_access_token".to_string());
let cache = FitbitResponseCache::new(client);
Source

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);
Source

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);
Source

pub fn clear_cache(&mut self)

Clears all cached responses.

This can be useful if you want to force a refresh of all data.

Source

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
Source

pub fn client(&self) -> &C

Gets a reference to the underlying Fitbit client.

§Returns

A reference to the Fitbit client

Auto Trait Implementations§

§

impl<C> Freeze for FitbitResponseCache<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for FitbitResponseCache<C>
where C: RefUnwindSafe,

§

impl<C> Send for FitbitResponseCache<C>
where C: Send,

§

impl<C> Sync for FitbitResponseCache<C>
where C: Sync,

§

impl<C> Unpin for FitbitResponseCache<C>
where C: Unpin,

§

impl<C> UnwindSafe for FitbitResponseCache<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.