olai-uc-client 0.0.4

Async Rust client for the Unity Catalog REST API.
Documentation
// @generated — do not edit by hand.
#![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::recipients::v1::*;
use url::Url;
/// HTTP client for service operations
#[derive(Clone)]
pub struct RecipientServiceClient {
    pub(crate) client: Transport,
    pub(crate) base_url: Url,
}
impl RecipientServiceClient {
    /// Create a new client instance
    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 }
    }
    /// List recipients.
    pub async fn list_recipients(
        &self,
        request: &ListRecipientsRequest,
    ) -> Result<ListRecipientsResponse> {
        let mut url = self.base_url.join("recipients")?;
        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());
        }
        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)?)
    }
    /// Create a new recipient.
    pub async fn create_recipient(&self, request: &CreateRecipientRequest) -> Result<Recipient> {
        let url = self.base_url.join("recipients")?;
        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)?)
    }
    /// Get a recipient by name.
    pub async fn get_recipient(&self, request: &GetRecipientRequest) -> Result<Recipient> {
        let formatted_path = format!("recipients/{}", 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)?)
    }
    /// Update a recipient.
    pub async fn update_recipient(&self, request: &UpdateRecipientRequest) -> Result<Recipient> {
        let formatted_path = format!("recipients/{}", 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)?)
    }
    /// Delete a recipient.
    pub async fn delete_recipient(&self, request: &DeleteRecipientRequest) -> Result<()> {
        let formatted_path = format!("recipients/{}", request.name);
        let url = self.base_url.join(&formatted_path)?;
        let response = self.client.delete(url).send().await?;
        if !response.status().is_success() {
            return Err(crate::error::parse_error_response(response).await);
        }
        Ok(())
    }
}