Skip to main content

unitycatalog_client/codegen/recipients/
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::recipients::v1::*;
9use url::Url;
10/// HTTP client for service operations
11#[derive(Clone)]
12pub struct RecipientServiceClient {
13    pub(crate) client: Transport,
14    pub(crate) base_url: Url,
15}
16impl RecipientServiceClient {
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 recipients.
25    pub async fn list_recipients(
26        &self,
27        request: &ListRecipientsRequest,
28    ) -> Result<ListRecipientsResponse> {
29        let mut url = self.base_url.join("recipients")?;
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        let response = self.client.get(url).send().await?;
39        if !response.status().is_success() {
40            return Err(crate::error::parse_error_response(response).await);
41        }
42        let result = response.bytes().await?;
43        Ok(serde_json::from_slice(&result)?)
44    }
45    /// Create a new recipient.
46    pub async fn create_recipient(&self, request: &CreateRecipientRequest) -> Result<Recipient> {
47        let url = self.base_url.join("recipients")?;
48        let response = self.client.post(url).json(request).send().await?;
49        if !response.status().is_success() {
50            return Err(crate::error::parse_error_response(response).await);
51        }
52        let result = response.bytes().await?;
53        Ok(serde_json::from_slice(&result)?)
54    }
55    /// Get a recipient by name.
56    pub async fn get_recipient(&self, request: &GetRecipientRequest) -> Result<Recipient> {
57        let formatted_path = format!("recipients/{}", request.name);
58        let url = self.base_url.join(&formatted_path)?;
59        let response = self.client.get(url).send().await?;
60        if !response.status().is_success() {
61            return Err(crate::error::parse_error_response(response).await);
62        }
63        let result = response.bytes().await?;
64        Ok(serde_json::from_slice(&result)?)
65    }
66    /// Update a recipient.
67    pub async fn update_recipient(&self, request: &UpdateRecipientRequest) -> Result<Recipient> {
68        let formatted_path = format!("recipients/{}", request.name);
69        let url = self.base_url.join(&formatted_path)?;
70        let response = self.client.patch(url).json(request).send().await?;
71        if !response.status().is_success() {
72            return Err(crate::error::parse_error_response(response).await);
73        }
74        let result = response.bytes().await?;
75        Ok(serde_json::from_slice(&result)?)
76    }
77    /// Delete a recipient.
78    pub async fn delete_recipient(&self, request: &DeleteRecipientRequest) -> Result<()> {
79        let formatted_path = format!("recipients/{}", request.name);
80        let url = self.base_url.join(&formatted_path)?;
81        let response = self.client.delete(url).send().await?;
82        if !response.status().is_success() {
83            return Err(crate::error::parse_error_response(response).await);
84        }
85        Ok(())
86    }
87}