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::cloudflare_images_list_images_v2`]
    ///
    ///[`Client::cloudflare_images_list_images_v2`]: crate::Client::cloudflare_images_list_images_v2
    #[derive(Debug, Clone)]
    pub struct CloudflareImagesListImagesV2<'a> {
        client: &'a crate::Client,
        account_id: Result<types::ImagesAccountIdentifier, String>,
        continuation_token: Result<types::ImagesImagesListContinuationToken, String>,
        creator: Result<Option<::std::string::String>, String>,
        meta_field_operator: Result<::std::string::String, String>,
        per_page: Result<f64, String>,
        sort_order: Result<types::CloudflareImagesListImagesV2SortOrder, String>,
    }
    impl<'a> CloudflareImagesListImagesV2<'a> {
        pub fn new(client: &'a crate::Client) -> Self {
            Self {
                client: client,
                account_id: Err("account_id was not initialized".to_string()),
                continuation_token: Err("continuation_token was not initialized".to_string()),
                creator: Ok(None),
                meta_field_operator: Err("meta_field_operator was not initialized".to_string()),
                per_page: Err("per_page was not initialized".to_string()),
                sort_order: Err("sort_order was not initialized".to_string()),
            }
        }

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

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

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

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

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

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

        ///Sends a `GET` request to `/accounts/{account_id}/images/v2`
        pub async fn send(
            self,
        ) -> Result<
            ResponseValue<::serde_json::Map<::std::string::String, ::serde_json::Value>>,
            Error<()>,
        > {
            let Self {
                client,
                account_id,
                continuation_token,
                creator,
                meta_field_operator,
                per_page,
                sort_order,
            } = self;
            let account_id = account_id.map_err(Error::InvalidRequest)?;
            let continuation_token = continuation_token.map_err(Error::InvalidRequest)?;
            let creator = creator.map_err(Error::InvalidRequest)?;
            let meta_field_operator = meta_field_operator.map_err(Error::InvalidRequest)?;
            let per_page = per_page.map_err(Error::InvalidRequest)?;
            let sort_order = sort_order.map_err(Error::InvalidRequest)?;
            let url = format!(
                "{}/accounts/{}/images/v2",
                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(
                    "continuation_token",
                    &continuation_token,
                ))
                .query(&progenitor_client::QueryParam::new("creator", &creator))
                .query(&progenitor_client::QueryParam::new(
                    "meta.<field>[<operator>]",
                    &meta_field_operator,
                ))
                .query(&progenitor_client::QueryParam::new("per_page", &per_page))
                .query(&progenitor_client::QueryParam::new(
                    "sort_order",
                    &sort_order,
                ))
                .headers(header_map)
                .build()?;
            let info = OperationInfo {
                operation_id: "cloudflare_images_list_images_v2",
            };
            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)),
            }
        }
    }