tftio-asana-cli 3.1.0

An interface to the Asana API
Documentation
//! High level custom field operations built on the core API client.

use crate::api::api_get;
use crate::{
    api::{ApiClient, ApiError},
    models::CustomField,
};
use futures_util::{StreamExt, pin_mut};

/// List custom fields in a workspace.
///
/// # Errors
/// Returns [`ApiError`] if the API request fails or network errors occur.
pub async fn list_custom_fields(
    client: &ApiClient,
    workspace_gid: &str,
    limit: Option<usize>,
) -> Result<Vec<CustomField>, ApiError> {
    let endpoint = format!("/workspaces/{workspace_gid}/custom_fields");
    let stream = client.paginate_with_limit::<CustomField>(&endpoint, vec![], limit);
    pin_mut!(stream);

    let mut fields = Vec::new();
    while let Some(page) = stream.next().await {
        let mut page = page?;
        fields.append(&mut page);
    }

    Ok(fields)
}

/// Get a single custom field by GID.
///
/// # Errors
/// Returns [`ApiError`] if the API request fails or network errors occur.
pub async fn get_custom_field(
    client: &ApiClient,
    field_gid: &str,
) -> Result<CustomField, ApiError> {
    api_get(client, &format!("/custom_fields/{field_gid}")).await
}