box-open-sdk 0.2.0

Community, unofficial Box API client for Rust — 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 [`DownloadsManager::get_file_content`].
#[derive(Clone, Debug, Default)]
pub struct DownloadsGetFileContentOptions {
    pub range: Option<String>,
    pub boxapi: Option<String>,
    pub version: Option<String>,
    pub access_token: Option<String>,
}

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

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

    pub async fn get_file_content(
        &self,
        file_id: String,
        opts: Option<DownloadsGetFileContentOptions>,
    ) -> Result<runtime::Stream, Error> {
        let mut url = self.session.base_url("api");
        url.push_str("/files");
        url.push('/');
        let seg = path_escape(&file_id);
        url.push_str(&seg);
        url.push_str("/content");
        let mut req = self.session.new_request("GET", &url);
        let opts = opts.unwrap_or_default();
        if let Some(value) = opts.range {
            req = runtime::with_header(req, "range", &value);
        }
        if let Some(value) = opts.boxapi {
            req = runtime::with_header(req, "boxapi", &value);
        }
        if let Some(value) = opts.version {
            req = runtime::with_query(req, "version", &value);
        }
        if let Some(value) = opts.access_token {
            req = runtime::with_query(req, "access_token", &value);
        }
        let resp = self.session.fetch(req).await?;
        Ok(runtime::response_stream(&resp))
    }
}