#![allow(unused_imports)]
use crate::Result;
#[cfg(not(target_arch = "wasm32"))]
use ::olai_http::CloudClient as Transport;
#[cfg(target_arch = "wasm32")]
use ::olai_http_wasm::WasmClient as Transport;
use unitycatalog_common::models::external_locations::v1::*;
use url::Url;
#[derive(Clone)]
pub struct ExternalLocationServiceClient {
pub(crate) client: Transport,
pub(crate) base_url: Url,
}
impl ExternalLocationServiceClient {
pub fn new(client: Transport, mut base_url: Url) -> Self {
if !base_url.path().ends_with('/') {
base_url.set_path(&format!("{}/", base_url.path()));
}
Self { client, base_url }
}
pub async fn list_external_locations(
&self,
request: &ListExternalLocationsRequest,
) -> Result<ListExternalLocationsResponse> {
let mut url = self.base_url.join("external-locations")?;
if let Some(ref value) = request.max_results {
url.query_pairs_mut()
.append_pair("max_results", &value.to_string());
}
if let Some(ref value) = request.page_token {
url.query_pairs_mut()
.append_pair("page_token", &value.to_string());
}
if let Some(ref value) = request.include_browse {
url.query_pairs_mut()
.append_pair("include_browse", &value.to_string());
}
let response = self.client.get(url).send().await?;
if !response.status().is_success() {
return Err(crate::error::parse_error_response(response).await);
}
let result = response.bytes().await?;
Ok(serde_json::from_slice(&result)?)
}
pub async fn create_external_location(
&self,
request: &CreateExternalLocationRequest,
) -> Result<ExternalLocation> {
let url = self.base_url.join("external-locations")?;
let response = self.client.post(url).json(request).send().await?;
if !response.status().is_success() {
return Err(crate::error::parse_error_response(response).await);
}
let result = response.bytes().await?;
Ok(serde_json::from_slice(&result)?)
}
pub async fn get_external_location(
&self,
request: &GetExternalLocationRequest,
) -> Result<ExternalLocation> {
let formatted_path = format!("external-locations/{}", request.name);
let url = self.base_url.join(&formatted_path)?;
let response = self.client.get(url).send().await?;
if !response.status().is_success() {
return Err(crate::error::parse_error_response(response).await);
}
let result = response.bytes().await?;
Ok(serde_json::from_slice(&result)?)
}
pub async fn update_external_location(
&self,
request: &UpdateExternalLocationRequest,
) -> Result<ExternalLocation> {
let formatted_path = format!("external-locations/{}", request.name);
let url = self.base_url.join(&formatted_path)?;
let response = self.client.patch(url).json(request).send().await?;
if !response.status().is_success() {
return Err(crate::error::parse_error_response(response).await);
}
let result = response.bytes().await?;
Ok(serde_json::from_slice(&result)?)
}
pub async fn delete_external_location(
&self,
request: &DeleteExternalLocationRequest,
) -> Result<()> {
let formatted_path = format!("external-locations/{}", request.name);
let mut url = self.base_url.join(&formatted_path)?;
if let Some(ref value) = request.force {
url.query_pairs_mut()
.append_pair("force", &value.to_string());
}
let response = self.client.delete(url).send().await?;
if !response.status().is_success() {
return Err(crate::error::parse_error_response(response).await);
}
Ok(())
}
}