// verify that fitbit oauth access token is working
// and subscription is setup
verify that fitbit oauth access token is working
and subscription is setup
verify that fitbit oauth access token is working and subscription is setup
async fn validate_fitbit(&self) -> Result<FitbitState> {
        let resp = match reqwest::Client::new()
            .get("https://api.fitbit.com/1/user/-/body/apiSubscriptions.json")
            .bearer_auth(&self.fitbit_access_token)
            .send()
            .await
            .context("fitbit validate get subscriptions list")?
        {
            resp if resp.status() == http::StatusCode::UNAUTHORIZED
                || resp.status() == http::StatusCode::FORBIDDEN =>
            {
                return Ok(FitbitState::NoAuth);
            }
            resp if !resp.status().is_success() => resp
                .error_for_status()
                .context("fitbit validate subscription")?,
            resp => resp,
        };
        // find subscription
        let body: serde_json::Value = resp
            .json()
            .await
            .context("fitbit validate get subscriptions list to json")?;
        let sub = body["apiSubscriptions"].as_array().and_then(|subs| {
            subs.iter()
                .find(|sub| sub["subscriptionId"].as_str() == Some(&self.uid))
        });
        match sub {
            Some(_) => Ok(FitbitState::Ok),
            None => Ok(FitbitState::AuthNoSub),
        }
    }
async fn validate_fitbit ( & self ) -> Result < FitbitState > { let resp = match reqwest :: Client :: new ( ) . get ( " " ) . bearer_auth ( & self . fitbit_access_token ) . send ( ) . await . context ( " " ) ? { resp if resp . status ( ) == http :: StatusCode :: UNAUTHORIZED || resp . status ( ) == http :: StatusCode :: FORBIDDEN => { return Ok ( FitbitState :: NoAuth ) ; } resp if ! resp . status ( ) . is_success ( ) => resp . error_for_status ( ) . context ( " " ) ? , resp => resp , } ; // find subscription let body : serde_json :: Value = resp . json ( ) . await . context ( " " ) ? ; let sub = body [ " " ] . as_array ( ) . and_then ( | subs | { subs . iter ( ) . find ( | sub | sub [ " " ] . as_str ( ) == Some ( & self . uid ) ) } ) ; match sub { Some ( _ ) => Ok ( FitbitState :: Ok ) , None => Ok ( FitbitState :: AuthNoSub ) , } }
verify that fitbit oauth access token is working
and subscription is setup
verify that fitbit oauth access token is working and subscription is setup
&self