Skip to main content

unitycatalog_client/codegen/external_locations/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4#[cfg(not(target_arch = "wasm32"))]
5use ::olai_http::CloudClient as Transport;
6#[cfg(target_arch = "wasm32")]
7use ::olai_http_wasm::WasmClient as Transport;
8use unitycatalog_common::models::external_locations::v1::*;
9use url::Url;
10/// HTTP client for service operations
11#[derive(Clone)]
12pub struct ExternalLocationServiceClient {
13    pub(crate) client: Transport,
14    pub(crate) base_url: Url,
15}
16impl ExternalLocationServiceClient {
17    /// Create a new client instance
18    pub fn new(client: Transport, mut base_url: Url) -> Self {
19        if !base_url.path().ends_with('/') {
20            base_url.set_path(&format!("{}/", base_url.path()));
21        }
22        Self { client, base_url }
23    }
24    /// List external locations
25    pub async fn list_external_locations(
26        &self,
27        request: &ListExternalLocationsRequest,
28    ) -> Result<ListExternalLocationsResponse> {
29        let mut url = self.base_url.join("external-locations")?;
30        if let Some(ref value) = request.max_results {
31            url.query_pairs_mut()
32                .append_pair("max_results", &value.to_string());
33        }
34        if let Some(ref value) = request.page_token {
35            url.query_pairs_mut()
36                .append_pair("page_token", &value.to_string());
37        }
38        if let Some(ref value) = request.include_browse {
39            url.query_pairs_mut()
40                .append_pair("include_browse", &value.to_string());
41        }
42        let response = self.client.get(url).send().await?;
43        if !response.status().is_success() {
44            return Err(crate::error::parse_error_response(response).await);
45        }
46        let result = response.bytes().await?;
47        Ok(serde_json::from_slice(&result)?)
48    }
49    /// Create a new external location
50    pub async fn create_external_location(
51        &self,
52        request: &CreateExternalLocationRequest,
53    ) -> Result<ExternalLocation> {
54        let url = self.base_url.join("external-locations")?;
55        let response = self.client.post(url).json(request).send().await?;
56        if !response.status().is_success() {
57            return Err(crate::error::parse_error_response(response).await);
58        }
59        let result = response.bytes().await?;
60        Ok(serde_json::from_slice(&result)?)
61    }
62    /// Get an external location
63    pub async fn get_external_location(
64        &self,
65        request: &GetExternalLocationRequest,
66    ) -> Result<ExternalLocation> {
67        let formatted_path = format!("external-locations/{}", request.name);
68        let url = self.base_url.join(&formatted_path)?;
69        let response = self.client.get(url).send().await?;
70        if !response.status().is_success() {
71            return Err(crate::error::parse_error_response(response).await);
72        }
73        let result = response.bytes().await?;
74        Ok(serde_json::from_slice(&result)?)
75    }
76    /// Update an external location
77    pub async fn update_external_location(
78        &self,
79        request: &UpdateExternalLocationRequest,
80    ) -> Result<ExternalLocation> {
81        let formatted_path = format!("external-locations/{}", request.name);
82        let url = self.base_url.join(&formatted_path)?;
83        let response = self.client.patch(url).json(request).send().await?;
84        if !response.status().is_success() {
85            return Err(crate::error::parse_error_response(response).await);
86        }
87        let result = response.bytes().await?;
88        Ok(serde_json::from_slice(&result)?)
89    }
90    /// Delete an external location
91    pub async fn delete_external_location(
92        &self,
93        request: &DeleteExternalLocationRequest,
94    ) -> Result<()> {
95        let formatted_path = format!("external-locations/{}", request.name);
96        let mut url = self.base_url.join(&formatted_path)?;
97        if let Some(ref value) = request.force {
98            url.query_pairs_mut()
99                .append_pair("force", &value.to_string());
100        }
101        let response = self.client.delete(url).send().await?;
102        if !response.status().is_success() {
103            return Err(crate::error::parse_error_response(response).await);
104        }
105        Ok(())
106    }
107}