cloudflare-api 0.1.0

Typed Rust client bindings for the Cloudflare API generated from OpenAPI definitions.
Documentation
use super::types;
use crate::{
    ByteStream, ClientHooks, ClientInfo, Error, OperationInfo, RequestBuilderExt,
    ResponseValue, encode_path,
};

    ///Builder for [`Client::workers_ai_search_model`]
    ///
    ///[`Client::workers_ai_search_model`]: crate::Client::workers_ai_search_model
    #[derive(Debug, Clone)]
    pub struct WorkersAiSearchModel<'a> {
        client: &'a crate::Client,
        account_id: Result<::std::string::String, String>,
        author: Result<::std::string::String, String>,
        hide_experimental: Result<bool, String>,
        page: Result<i64, String>,
        per_page: Result<i64, String>,
        search: Result<::std::string::String, String>,
        source: Result<f64, String>,
        task: Result<::std::string::String, String>,
    }
    impl<'a> WorkersAiSearchModel<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                author: Err("author was not initialized".to_string()),
                hide_experimental: Err("hide_experimental was not initialized".to_string()),
                page: Err("page was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                search: Err("search was not initialized".to_string()),
                source: Err("source was not initialized".to_string()),
                task: Err("task was not initialized".to_string()),
            }
        }

        pub fn account_id<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.account_id = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for account_id failed".to_string()
            });
            self
        }

        pub fn author<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.author = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for author failed".to_string()
            });
            self
        }

        pub fn hide_experimental<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<bool>,
        {
            self.hide_experimental = value
                .try_into()
                .map_err(|_| "conversion to `bool` for hide_experimental failed".to_string());
            self
        }

        pub fn page<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<i64>,
        {
            self.page = value
                .try_into()
                .map_err(|_| "conversion to `i64` for page failed".to_string());
            self
        }

        pub fn per_page<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<i64>,
        {
            self.per_page = value
                .try_into()
                .map_err(|_| "conversion to `i64` for per_page failed".to_string());
            self
        }

        pub fn search<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.search = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for search failed".to_string()
            });
            self
        }

        pub fn source<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<f64>,
        {
            self.source = value
                .try_into()
                .map_err(|_| "conversion to `f64` for source failed".to_string());
            self
        }

        pub fn task<V>(mut self, value: V) -> Self
        where
            V: std::convert::TryInto<::std::string::String>,
        {
            self.task = value.try_into().map_err(|_| {
                "conversion to `:: std :: string :: String` for task failed".to_string()
            });
            self
        }

        ///Sends a `GET` request to `/accounts/{account_id}/ai/models/search`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                author,
                hide_experimental,
                page,
                per_page,
                search,
                source,
                task,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let author = author.map_err(Error::InvalidRequest)?;
            let hide_experimental = hide_experimental.map_err(Error::InvalidRequest)?;
            let page = page.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let search = search.map_err(Error::InvalidRequest)?;
            let source = source.map_err(Error::InvalidRequest)?;
            let task = task.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/ai/models/search",
                client.baseurl,
                encode_path(&account_id.to_string()),
            );
            let mut header_map = ::reqwest::header::HeaderMap::with_capacity(1usize);
            header_map.append(
                ::reqwest::header::HeaderName::from_static("api-version"),
                ::reqwest::header::HeaderValue::from_static(crate::Client::api_version()),
            );
            #[allow(unused_mut)]
            let mut request = client
                .client
                .get(url)
                .header(
                    ::reqwest::header::ACCEPT,
                    ::reqwest::header::HeaderValue::from_static("application/json"),
                )
                .query(&progenitor_client::QueryParam::new("author", &author))
                .query(&progenitor_client::QueryParam::new(
                    "hide_experimental",
                    &hide_experimental,
                ))
                .query(&progenitor_client::QueryParam::new("page", &page))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new("search", &search))
                .query(&progenitor_client::QueryParam::new("source", &source))
                .query(&progenitor_client::QueryParam::new("task", &task))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "workers_ai_search_model",
            };
            client.pre(&mut request, &info).await?;
            let result = client.exec(request, &info).await;
            client.post(&result, &info).await?;
            let response = result?;
            match response.status().as_u16() {
                200u16 => ResponseValue::from_response(response).await,
                _ => Err(Error::UnexpectedResponse(response)),
            }
        }
    }