use crate::AuthProvider;
use derive_getters::Getters;
use reqwest::Client as ReqwestClient;
use std::sync::Arc;
use tracing::instrument;
#[derive(Getters)]
pub struct ArcGISClient {
http: ReqwestClient,
auth: Arc<dyn AuthProvider>,
}
impl ArcGISClient {
#[instrument(skip(auth))]
pub fn new(auth: impl AuthProvider + 'static) -> Self {
tracing::debug!("Creating new ArcGIS client");
Self {
http: ReqwestClient::new(),
auth: Arc::new(auth),
}
}
#[instrument(skip(self))]
pub async fn get_token_if_required(&self) -> crate::Result<Option<String>> {
if self.auth.requires_token_param() {
tracing::debug!("Auth provider requires token, retrieving");
Ok(Some(self.auth.get_token().await?))
} else {
tracing::debug!("Auth provider does not require token");
Ok(None)
}
}
}