foundation_deployment_digitalocean 0.1.3

DigitalOcean API v2 client — droplet provisioning and SSH keys
//! Auto-generated API module for digitalocean keys.
//!
//! Generated by `cargo run --bin ewe_platform gen_api`.
//! DO NOT EDIT MANUALLY.
//!
//! Feature flag: `digitalocean_keys `

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

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

use super::shared::ApiResponse;

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

/// `Meta` type.
///
/// Same shape as `super::shared::MetaObject`.
pub type Meta = super::shared::MetaObject;

/// `PageLinks` type.
///
/// Same shape as `super::shared::PagesObject`.
pub type PageLinks = super::shared::PagesObject;

/// `Pagination` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct Pagination {
    /// `links` property.
    pub links: Option<PageLinks>,
}

/// `SshKeyFingerprint` type.
pub type SshKeyFingerprint = String;

/// `SshKeyId` type.
pub type SshKeyId = i64;

/// `SshKeyName` type.
pub type SshKeyName = String;

/// `SshKeys` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SshKeys {
    /// `fingerprint` property.
    pub fingerprint: Option<String>,
    /// `id` property.
    pub id: Option<i64>,
    /// `name` property.
    pub name: String,
    /// `public_key` property.
    pub public_key: String,
}

/// `SshKeysAllResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SshKeysAllResponse {
    /// `links` property.
    pub links: Option<PageLinks>,
    /// `meta` property.
    pub meta: serde_json::Value,
    /// `ssh_keys` property.
    pub ssh_keys: Option<Vec<SshKeys>>,
}

/// `SshKeysNewResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct SshKeysNewResponse {
    /// `ssh_key` property.
    pub ssh_key: Option<SshKeys>,
}

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

/// Arguments for [`sshKeys_list_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct SshKeysListArgs {
    /// Query parameter: `per_page`.
    pub per_page: Option<String>,
    /// Query parameter: `page`.
    pub page: Option<String>,
}

/// Arguments for [`sshKeys_create_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct SshKeysCreateArgs {
    /// Request body.
    pub body: SshKeys,
}

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

// -----------------------------------------------------------------------------
// GET /v2/account/keys
// -----------------------------------------------------------------------------

/// GET /v2/account/keys.
///
/// Takes a client and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request: a `DynNetClient`, or an `ApiClient` carrying the `BodyLimits` the response is read under
/// * `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 = ssh_keys_list_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn ssh_keys_list_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &SshKeysListArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<SshKeysAllResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/v2/account/keys",);
    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("per_page", args.per_page.as_deref());
    builder = builder.query("page", args.page.as_deref());

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

    super::shared::send_json(client.into(), builder.build()).await
}

// -----------------------------------------------------------------------------
// POST /v2/account/keys
// -----------------------------------------------------------------------------

/// POST /v2/account/keys.
///
/// Takes a client and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request: a `DynNetClient`, or an `ApiClient` carrying the `BodyLimits` the response is read under
/// * `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 = ssh_keys_create_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn ssh_keys_create_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &SshKeysCreateArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<ApiResponse<SshKeysNewResponse>, super::shared::ApiError>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/v2/account/keys",);
    let endpoint_url = format!("{}{}", base_url, path);

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

    builder = builder
        .body_json(&args.body)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

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

    super::shared::send_json(client.into(), builder.build()).await
}