Skip to main content

unitycatalog_client/codegen/recipients/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::recipients::v1::*;
6use url::Url;
7/// HTTP client for service operations
8#[derive(Clone)]
9pub struct RecipientServiceClient {
10    pub(crate) client: CloudClient,
11    pub(crate) base_url: Url,
12}
13impl RecipientServiceClient {
14    /// Create a new client instance
15    pub fn new(client: CloudClient, mut base_url: Url) -> Self {
16        if !base_url.path().ends_with('/') {
17            base_url.set_path(&format!("{}/", base_url.path()));
18        }
19        Self { client, base_url }
20    }
21    /// List recipients.
22    pub async fn list_recipients(
23        &self,
24        request: &ListRecipientsRequest,
25    ) -> Result<ListRecipientsResponse> {
26        let mut url = self.base_url.join("recipients")?;
27        if let Some(ref value) = request.max_results {
28            url.query_pairs_mut()
29                .append_pair("max_results", &value.to_string());
30        }
31        if let Some(ref value) = request.page_token {
32            url.query_pairs_mut()
33                .append_pair("page_token", &value.to_string());
34        }
35        let response = self.client.get(url).send().await?;
36        if !response.status().is_success() {
37            return Err(crate::error::parse_error_response(response).await);
38        }
39        let result = response.bytes().await?;
40        Ok(serde_json::from_slice(&result)?)
41    }
42    /// Create a new recipient.
43    pub async fn create_recipient(&self, request: &CreateRecipientRequest) -> Result<Recipient> {
44        let url = self.base_url.join("recipients")?;
45        let response = self.client.post(url).json(request).send().await?;
46        if !response.status().is_success() {
47            return Err(crate::error::parse_error_response(response).await);
48        }
49        let result = response.bytes().await?;
50        Ok(serde_json::from_slice(&result)?)
51    }
52    /// Get a recipient by name.
53    pub async fn get_recipient(&self, request: &GetRecipientRequest) -> Result<Recipient> {
54        let formatted_path = format!("recipients/{}", request.name);
55        let url = self.base_url.join(&formatted_path)?;
56        let response = self.client.get(url).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    /// Update a recipient.
64    pub async fn update_recipient(&self, request: &UpdateRecipientRequest) -> Result<Recipient> {
65        let formatted_path = format!("recipients/{}", request.name);
66        let url = self.base_url.join(&formatted_path)?;
67        let response = self.client.patch(url).json(request).send().await?;
68        if !response.status().is_success() {
69            return Err(crate::error::parse_error_response(response).await);
70        }
71        let result = response.bytes().await?;
72        Ok(serde_json::from_slice(&result)?)
73    }
74    /// Delete a recipient.
75    pub async fn delete_recipient(&self, request: &DeleteRecipientRequest) -> Result<()> {
76        let formatted_path = format!("recipients/{}", request.name);
77        let url = self.base_url.join(&formatted_path)?;
78        let response = self.client.delete(url).send().await?;
79        if !response.status().is_success() {
80            return Err(crate::error::parse_error_response(response).await);
81        }
82        Ok(())
83    }
84}