unitycatalog_client/codegen/catalogs/
client.rs1#![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::catalogs::v1::*;
9use url::Url;
10#[derive(Clone)]
12pub struct CatalogServiceClient {
13 pub(crate) client: Transport,
14 pub(crate) base_url: Url,
15}
16impl CatalogServiceClient {
17 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 pub async fn list_catalogs(
31 &self,
32 request: &ListCatalogsRequest,
33 ) -> Result<ListCatalogsResponse> {
34 let mut url = self.base_url.join("catalogs")?;
35 if let Some(ref value) = request.max_results {
36 url.query_pairs_mut()
37 .append_pair("max_results", &value.to_string());
38 }
39 if let Some(ref value) = request.page_token {
40 url.query_pairs_mut()
41 .append_pair("page_token", &value.to_string());
42 }
43 let response = self.client.get(url).send().await?;
44 if !response.status().is_success() {
45 return Err(crate::error::parse_error_response(response).await);
46 }
47 let result = response.bytes().await?;
48 Ok(serde_json::from_slice(&result)?)
49 }
50 pub async fn create_catalog(&self, request: &CreateCatalogRequest) -> Result<Catalog> {
55 let url = self.base_url.join("catalogs")?;
56 let response = self.client.post(url).json(request).send().await?;
57 if !response.status().is_success() {
58 return Err(crate::error::parse_error_response(response).await);
59 }
60 let result = response.bytes().await?;
61 Ok(serde_json::from_slice(&result)?)
62 }
63 pub async fn get_catalog(&self, request: &GetCatalogRequest) -> Result<Catalog> {
68 let formatted_path = format!("catalogs/{}", request.name);
69 let mut url = self.base_url.join(&formatted_path)?;
70 if let Some(ref value) = request.include_browse {
71 url.query_pairs_mut()
72 .append_pair("include_browse", &value.to_string());
73 }
74 let response = self.client.get(url).send().await?;
75 if !response.status().is_success() {
76 return Err(crate::error::parse_error_response(response).await);
77 }
78 let result = response.bytes().await?;
79 Ok(serde_json::from_slice(&result)?)
80 }
81 pub async fn update_catalog(&self, request: &UpdateCatalogRequest) -> Result<Catalog> {
86 let formatted_path = format!("catalogs/{}", request.name);
87 let url = self.base_url.join(&formatted_path)?;
88 let response = self.client.patch(url).json(request).send().await?;
89 if !response.status().is_success() {
90 return Err(crate::error::parse_error_response(response).await);
91 }
92 let result = response.bytes().await?;
93 Ok(serde_json::from_slice(&result)?)
94 }
95 pub async fn delete_catalog(&self, request: &DeleteCatalogRequest) -> Result<()> {
100 let formatted_path = format!("catalogs/{}", request.name);
101 let mut url = self.base_url.join(&formatted_path)?;
102 if let Some(ref value) = request.force {
103 url.query_pairs_mut()
104 .append_pair("force", &value.to_string());
105 }
106 let response = self.client.delete(url).send().await?;
107 if !response.status().is_success() {
108 return Err(crate::error::parse_error_response(response).await);
109 }
110 Ok(())
111 }
112}