foundation_deployment_cloudflare 0.1.2

Cloudflare API v4 client — DNS records, zones, certificates
//! Auto-generated API module for cloudflare ips.
//!
//! Generated by `cargo run --bin ewe_platform gen_api`.
//! DO NOT EDIT MANUALLY.
//!
//! Feature flag: `cloudflare_ips `

#![cfg(feature = "cloudflare_ips")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(clippy::missing_errors_doc, clippy::doc_markdown, clippy::useless_format)]
#![allow(unused_imports)]

use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use foundation_netio::shared::client::http_client::HttpClient;
use serde::{Deserialize, Serialize};
use foundation_macros::JsonHash;

use super::shared::ApiResponse;

// =============================================================================
// TYPE DECLARATIONS
// =============================================================================

/// `CloudflareIpsCloudflareIpDetailsResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct CloudflareIpsCloudflareIpDetailsResponse {
    /// `result` property.
    pub result: Option<serde_json::Value>,
}

/// `PublicIpApiResponseCommon` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct PublicIpApiResponseCommon {
    /// errors property.
    pub errors: Vec<std::collections::HashMap<String, serde_json::Value>>,
    /// messages property.
    pub messages: Vec<std::collections::HashMap<String, serde_json::Value>>,
    /// success property.
    pub success: bool,
}

/// `PublicIpApiResponseSingle` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct PublicIpApiResponseSingle {
}

/// `PublicIpMessages` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct PublicIpMessages {
    #[serde(flatten)]
    pub data: std::collections::HashMap<String, serde_json::Value>,
}

// =============================================================================
// ARGS TYPES (per-endpoint)
// =============================================================================

/// Arguments for [`cloudflare-ips-cloudflare-ip-details_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct CloudflareIpsCloudflareIpDetailsArgs {
    /// Query parameter: `networks`.
    pub networks: Option<String>,
}

// =============================================================================
// CLIENT FUNCTIONS (per-endpoint)
// =============================================================================

// -----------------------------------------------------------------------------
// GET /ips
// -----------------------------------------------------------------------------

/// GET /ips.
///
/// Takes a `DynNetClient` and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Example
///
/// ```ignore
/// let response = cloudflare_ips_cloudflare_ip_details_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn cloudflare_ips_cloudflare_ip_details_request<F>(
    client: DynNetClient,
    args: &CloudflareIpsCloudflareIpDetailsArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<CloudflareIpsCloudflareIpDetailsResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/ips",
    );
    let endpoint_url = format!("{}{}", base_url, path);

    let mut builder = PreparedRequestBuilder::get(&endpoint_url)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    builder = builder.query("networks", args.networks.as_deref());

    if let Some(f) = builder_mod {
        f(&mut builder);
    }

    let response = client.send_async(builder.build()).await
        .map_err(|e| super::shared::ApiError::RequestSendFailed(e.to_string()))?;

    let status: usize = response.get_status().into();
    let headers = response.get_headers_ref().clone();
    if status < 200 || status >= 300 {
        let error_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
        let body = (!error_bytes.is_empty())
            .then(|| String::from_utf8_lossy(&error_bytes).into_owned());
        return Err(super::shared::ApiError::HttpStatus { code: status as u16, headers, body });
    }
    let body_bytes = foundation_netio::shared::client::body_reader::collect_bytes_from_send_safe(response.take_body());
    let parsed: CloudflareIpsCloudflareIpDetailsResponse = serde_json::from_slice(&body_bytes).map_err(|e: serde_json::Error| super::shared::ApiError::ParseFailed(e.to_string()))?;
    Ok(ApiResponse { status: status as u16, headers, body: parsed })
}