#![doc = "Generated implementation of authenticated SDK resource facades."]
use reqwest_middleware::ClientWithMiddleware;
use spiral_contract::call::CallError;
use uuid::Uuid;
use crate::api::locations::LocationsClient;
use crate::api::locations::objects::*;
use crate::auth::TokenSource;
use crate::http::HttpClient;
#[derive(Clone, Debug)]
pub struct AuthenticatedClient {
http: HttpClient,
client: LocationsClient,
}
impl AuthenticatedClient {
pub fn new(base: &str) -> Result<Self, CallError<LocationsError>> {
Self::from_http(HttpClient::connect(base).map_err(CallError::transport)?)
}
pub(crate) fn from_http(http: HttpClient) -> Result<Self, CallError<LocationsError>> {
let client =
LocationsClient::from_transport(http.base_url().as_str(), http.middleware_client())?;
Ok(Self { http, client })
}
pub fn with_client(mut self, client: impl Into<ClientWithMiddleware>) -> Self {
self.http = self.http.with_client(client);
self.client = self.client.with_transport(self.http.middleware_client());
self
}
pub fn with_token_source(mut self, provider: TokenSource) -> Self {
self.http = self.http.with_token_source(provider);
self
}
pub async fn create_location(
&self,
request: CreateLocationRequest,
) -> Result<CreateLocationResponse, CallError<LocationsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client.create_location_http(auth_header, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn create_version(
&self,
location_id: Uuid,
request: CreateVersionRequest,
) -> Result<VersionResponse, CallError<LocationsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.create_version_http(auth_header, location_id, request),
)
.await
.map_err(CallError::transport)?
}
pub async fn read_version(
&self,
location_id: Uuid,
version_id: Uuid,
) -> Result<VersionResponse, CallError<LocationsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.read_version_http(auth_header, location_id, version_id),
)
.await
.map_err(CallError::transport)?
}
pub async fn storage_binding(
&self,
location_id: Uuid,
version_id: Uuid,
) -> Result<StorageBinding, CallError<LocationsError>> {
let auth_header = self
.http
.auth_header()
.await
.map_err(CallError::transport)?;
tokio::time::timeout(
std::time::Duration::from_secs(60),
self.client
.storage_binding_http(auth_header, location_id, version_id),
)
.await
.map_err(CallError::transport)?
}
}