box-open-sdk 0.4.1

Box API client for Rust (open source, community, punk rock) — typed models, async managers, and a reqwest runtime with retry, backoff, and token refresh.
Documentation
// Code generated by box-gantry. DO NOT EDIT.

use crate::internal::path_escape;
use crate::runtime::{self, Error};

/// Optional parameters for [`AiStudioManager::list_ai_agents`].
#[derive(Clone, Debug, Default)]
pub struct AiStudioListAiAgentsOptions {
    pub mode: Option<Vec<String>>,
    pub fields: Option<Vec<String>>,
    pub agent_state: Option<Vec<String>>,
    pub include_box_default: Option<bool>,
    pub marker: Option<String>,
    pub limit: Option<i64>,
}

/// Optional parameters for [`AiStudioManager::get_ai_agent`].
#[derive(Clone, Debug, Default)]
pub struct AiStudioGetAiAgentOptions {
    pub fields: Option<Vec<String>>,
}

/// Async paginator over [`AiStudioManager::list_ai_agents`], yielding one `crate::models::schemas::AiSingleAgentResponseFull`
/// per item across pages (FR-7.3).
pub struct AiStudioListAiAgentsPaginator {
    manager: AiStudioManager,
    options: AiStudioListAiAgentsOptions,
    buffer: std::vec::IntoIter<crate::models::schemas::AiSingleAgentResponseFull>,
    done: bool,
}

impl AiStudioListAiAgentsPaginator {
    /// The next item, advancing pages as needed; `None` at the end.
    /// An error is yielded once, then iteration stops.
    pub async fn next(
        &mut self,
    ) -> Option<Result<crate::models::schemas::AiSingleAgentResponseFull, Error>> {
        loop {
            if let Some(item) = self.buffer.next() {
                return Some(Ok(item));
            }
            if self.done {
                return None;
            }
            let page = match self
                .manager
                .list_ai_agents_page(Some(self.options.clone()))
                .await
            {
                Ok(page) => page,
                Err(err) => {
                    self.done = true;
                    return Some(Err(err));
                }
            };
            self.buffer = page.entries.into_iter();
            match page.next_marker.flatten() {
                Some(cursor) if !cursor.is_empty() => self.options.marker = Some(cursor),
                _ => self.done = true,
            }
        }
    }
}

/// Operations for the "ai_studio" API area.
pub struct AiStudioManager {
    session: std::sync::Arc<runtime::Client>,
}

impl AiStudioManager {
    pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
        Self { session }
    }

    async fn list_ai_agents_page(
        &self,
        opts: Option<AiStudioListAiAgentsOptions>,
    ) -> Result<crate::models::schemas::AiMultipleAgentResponse, Error> {
        let mut url = self.session.base_url("api");
        url.push_str("/ai_agents");
        let mut req = self.session.new_request("GET", &url);
        let opts = opts.unwrap_or_default();
        if let Some(value) = opts.mode {
            req = runtime::with_query(req, "mode", &value.join(","));
        }
        if let Some(value) = opts.fields {
            req = runtime::with_query(req, "fields", &value.join(","));
        }
        if let Some(value) = opts.agent_state {
            req = runtime::with_query(req, "agent_state", &value.join(","));
        }
        if let Some(value) = opts.include_box_default {
            req = runtime::with_query(req, "include_box_default", &value.to_string());
        }
        if let Some(value) = opts.marker {
            req = runtime::with_query(req, "marker", &value);
        }
        if let Some(value) = opts.limit {
            req = runtime::with_query(req, "limit", &value.to_string());
        }
        let resp = self.session.fetch(req).await?;
        let data = runtime::response_bytes(&resp)?;
        Ok(serde_json::from_slice(&data)?)
    }

    /// Iterate every `crate::models::schemas::AiSingleAgentResponseFull` across pages, threading the cursor.
    pub fn list_ai_agents(
        &self,
        opts: Option<AiStudioListAiAgentsOptions>,
    ) -> AiStudioListAiAgentsPaginator {
        AiStudioListAiAgentsPaginator {
            manager: AiStudioManager::new(self.session.clone()),
            options: opts.unwrap_or_default(),
            buffer: Vec::new().into_iter(),
            done: false,
        }
    }

    pub async fn create_ai_agents(
        &self,
        body: crate::models::schemas::CreateAiAgent,
    ) -> Result<crate::models::schemas::AiSingleAgentResponseFull, Error> {
        let mut url = self.session.base_url("api");
        url.push_str("/ai_agents");
        let mut req = self.session.new_request("POST", &url);
        let payload = serde_json::to_vec(&body)?;
        req = runtime::with_json_body(req, &payload);
        let resp = self.session.fetch(req).await?;
        let data = runtime::response_bytes(&resp)?;
        Ok(serde_json::from_slice(&data)?)
    }

    pub async fn get_ai_agent(
        &self,
        agent_id: String,
        opts: Option<AiStudioGetAiAgentOptions>,
    ) -> Result<crate::models::schemas::AiSingleAgentResponseFull, Error> {
        let mut url = self.session.base_url("api");
        url.push_str("/ai_agents");
        url.push('/');
        let seg = path_escape(&agent_id);
        url.push_str(&seg);
        let mut req = self.session.new_request("GET", &url);
        let opts = opts.unwrap_or_default();
        if let Some(value) = opts.fields {
            req = runtime::with_query(req, "fields", &value.join(","));
        }
        let resp = self.session.fetch(req).await?;
        let data = runtime::response_bytes(&resp)?;
        Ok(serde_json::from_slice(&data)?)
    }

    pub async fn update_ai_agent(
        &self,
        agent_id: String,
        body: crate::models::schemas::CreateAiAgent,
    ) -> Result<crate::models::schemas::AiSingleAgentResponseFull, Error> {
        let mut url = self.session.base_url("api");
        url.push_str("/ai_agents");
        url.push('/');
        let seg = path_escape(&agent_id);
        url.push_str(&seg);
        let mut req = self.session.new_request("PUT", &url);
        let payload = serde_json::to_vec(&body)?;
        req = runtime::with_json_body(req, &payload);
        let resp = self.session.fetch(req).await?;
        let data = runtime::response_bytes(&resp)?;
        Ok(serde_json::from_slice(&data)?)
    }

    pub async fn delete_ai_agent(&self, agent_id: String) -> Result<(), Error> {
        let mut url = self.session.base_url("api");
        url.push_str("/ai_agents");
        url.push('/');
        let seg = path_escape(&agent_id);
        url.push_str(&seg);
        let req = self.session.new_request("DELETE", &url);
        let _ = self.session.fetch(req).await?;
        Ok(())
    }
}