opensearch-client 0.3.1

Strongly typed OpenSearch Client
Documentation
/*
 * opensearch-client
 *
 * Rust Client for OpenSearch
 *
 * The version of the OpenAPI document: 3.1.0
 * Contact: alberto.paro@gmail.com
 * Generated by Paro OpenAPI Generator
 */
use bon::bon;

use reqwest;
use std::sync::Arc;
use serde::{Deserialize, Serialize, de::Error as OtherError};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration};
use crate::apis::ContentType;
use crate::*;


#[async_trait]
pub trait DanglingIndicesApi: Send + Sync {


    /// DELETE /_dangling/{index_uuid}///
    /// Deletes the specified dangling index.
    async fn delete_dangling_index(&self, params: DeleteDanglingIndexParams) -> Result<crate::common::AcknowledgedResponseBase, Error>;

    /// POST /_dangling/{index_uuid}///
    /// Imports the specified dangling index.
    async fn import_dangling_index(&self, params: ImportDanglingIndexParams) -> Result<crate::common::AcknowledgedResponseBase, Error>;

    /// GET /_dangling///
    /// Returns all dangling indexes.
    async fn list_dangling_indices(&self, params: ListDanglingIndicesParams) -> Result<crate::dangling_indices::ListDanglingIndicesResponse, Error>;
}

pub struct DanglingIndicesApiClient {
    configuration: Arc<crate::Configuration>
}

impl DanglingIndicesApiClient {
    pub fn new(configuration: Arc<crate::Configuration>) -> Self {
        Self { configuration }
    }
}


/// Struct for passing parameters to the method [`delete_dangling_index`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct DeleteDanglingIndexParams {
      /// A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and
  /// `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
    pub cluster_manager_timeout: Option<String>,
      /// A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and
  /// `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
    pub master_timeout: Option<String>,
      /// A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and
  /// `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
    pub timeout: Option<String>,
      /// No description available
    pub accept_data_loss: bool,
      /// No description available
    pub error_trace: Option<bool>,
      /// No description available
    pub filter_path: Option<common::FilterPath>,
      /// No description available
    pub human: Option<bool>,
      /// No description available
    pub index_uuid: String,
      /// No description available
    pub pretty: Option<bool>,
      /// No description available
    pub source: Option<String>,
}
/// Struct for passing parameters to the method [`import_dangling_index`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct ImportDanglingIndexParams {
      /// A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and
  /// `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
    pub cluster_manager_timeout: Option<String>,
      /// A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and
  /// `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
    pub master_timeout: Option<String>,
      /// A duration. Units can be `nanos`, `micros`, `ms` (milliseconds), `s` (seconds), `m` (minutes), `h` (hours) and
  /// `d` (days). Also accepts "0" without a unit and "-1" to indicate an unspecified value.
    pub timeout: Option<String>,
      /// No description available
    pub accept_data_loss: bool,
      /// No description available
    pub error_trace: Option<bool>,
      /// No description available
    pub filter_path: Option<common::FilterPath>,
      /// No description available
    pub human: Option<bool>,
      /// No description available
    pub index_uuid: String,
      /// No description available
    pub pretty: Option<bool>,
      /// No description available
    pub source: Option<String>,
}
/// Struct for passing parameters to the method [`list_dangling_indices`]
#[derive(Clone, Debug)]
#[cfg_attr(feature = "bon", derive(::bon::Builder))]
pub struct ListDanglingIndicesParams {
      /// No description available
    pub error_trace: Option<bool>,
      /// No description available
    pub filter_path: Option<common::FilterPath>,
      /// No description available
    pub human: Option<bool>,
      /// No description available
    pub pretty: Option<bool>,
      /// No description available
    pub source: Option<String>,
}

#[async_trait]
impl DanglingIndicesApi for DanglingIndicesApiClient {
///
      /// Deletes the specified dangling index.
    async fn delete_dangling_index(&self, params: DeleteDanglingIndexParams) -> Result<crate::common::AcknowledgedResponseBase, Error> {
        let DeleteDanglingIndexParams {
            cluster_manager_timeout,
            master_timeout,
            timeout,
            accept_data_loss,
            error_trace,
            filter_path,
            human,
            index_uuid,
            pretty,
            source,
        } = params;
    
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}_dangling/{index_uuid}", local_var_configuration.base_path, index_uuid=index_uuid);
        let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());


    if let Some(ref local_var_str) = pretty {
        local_var_req_builder = local_var_req_builder.query(&[("pretty", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = filter_path {
        local_var_req_builder = local_var_req_builder.query(&[("filter_path", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = error_trace {
        local_var_req_builder = local_var_req_builder.query(&[("error_trace", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = cluster_manager_timeout {
        local_var_req_builder = local_var_req_builder.query(&[("cluster_manager_timeout", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = timeout {
        local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
    }
        local_var_req_builder = local_var_req_builder.query(&[("accept_data_loss", &accept_data_loss.to_string())]);
    if let Some(ref local_var_str) = master_timeout {
        local_var_req_builder = local_var_req_builder.query(&[("master_timeout", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = human {
        local_var_req_builder = local_var_req_builder.query(&[("human", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = source {
        local_var_req_builder = local_var_req_builder.query(&[("source", &local_var_str.to_string())]);
    }







        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            
            serde_json::from_str(&local_var_content).map_err(Error::from)
            
            
        } else {
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
            };
            Err(Error::ApiError(local_var_error))
        }
    }///
      /// Imports the specified dangling index.
    async fn import_dangling_index(&self, params: ImportDanglingIndexParams) -> Result<crate::common::AcknowledgedResponseBase, Error> {
        let ImportDanglingIndexParams {
            cluster_manager_timeout,
            master_timeout,
            timeout,
            accept_data_loss,
            error_trace,
            filter_path,
            human,
            index_uuid,
            pretty,
            source,
        } = params;
    
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}_dangling/{index_uuid}", local_var_configuration.base_path, index_uuid=index_uuid);
        let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());


    if let Some(ref local_var_str) = error_trace {
        local_var_req_builder = local_var_req_builder.query(&[("error_trace", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = cluster_manager_timeout {
        local_var_req_builder = local_var_req_builder.query(&[("cluster_manager_timeout", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = pretty {
        local_var_req_builder = local_var_req_builder.query(&[("pretty", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = filter_path {
        local_var_req_builder = local_var_req_builder.query(&[("filter_path", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = human {
        local_var_req_builder = local_var_req_builder.query(&[("human", &local_var_str.to_string())]);
    }
        local_var_req_builder = local_var_req_builder.query(&[("accept_data_loss", &accept_data_loss.to_string())]);
    if let Some(ref local_var_str) = timeout {
        local_var_req_builder = local_var_req_builder.query(&[("timeout", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = source {
        local_var_req_builder = local_var_req_builder.query(&[("source", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = master_timeout {
        local_var_req_builder = local_var_req_builder.query(&[("master_timeout", &local_var_str.to_string())]);
    }







        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            
            serde_json::from_str(&local_var_content).map_err(Error::from)
            
            
        } else {
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
            };
            Err(Error::ApiError(local_var_error))
        }
    }///
      /// Returns all dangling indexes.
    async fn list_dangling_indices(&self, params: ListDanglingIndicesParams) -> Result<crate::dangling_indices::ListDanglingIndicesResponse, Error> {
        let ListDanglingIndicesParams {
            error_trace,
            filter_path,
            human,
            pretty,
            source,
        } = params;
    
        let local_var_configuration = &self.configuration;

        let local_var_client = &local_var_configuration.client;

        let local_var_uri_str = format!("{}_dangling", local_var_configuration.base_path);
        let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());


    if let Some(ref local_var_str) = pretty {
        local_var_req_builder = local_var_req_builder.query(&[("pretty", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = source {
        local_var_req_builder = local_var_req_builder.query(&[("source", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = error_trace {
        local_var_req_builder = local_var_req_builder.query(&[("error_trace", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = filter_path {
        local_var_req_builder = local_var_req_builder.query(&[("filter_path", &local_var_str.to_string())]);
    }
    if let Some(ref local_var_str) = human {
        local_var_req_builder = local_var_req_builder.query(&[("human", &local_var_str.to_string())]);
    }







        let local_var_req = local_var_req_builder.build()?;
        let local_var_resp = local_var_client.execute(local_var_req).await?;

        let local_var_status = local_var_resp.status();
        let local_var_content = local_var_resp.text().await?;

        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
            
            serde_json::from_str(&local_var_content).map_err(Error::from)
            
            
        } else {
            let local_var_error = ResponseContent {
                status: local_var_status,
                content: local_var_content,
            };
            Err(Error::ApiError(local_var_error))
        }
    }
}