Skip to main content

box_open_sdk/managers/
downloads.rs

1// Code generated by box-gantry. DO NOT EDIT.
2
3use crate::internal::path_escape;
4use crate::runtime::{self, Error};
5
6/// Optional parameters for [`DownloadsManager::get_file_content`].
7#[derive(Clone, Debug, Default)]
8pub struct DownloadsGetFileContentOptions {
9    pub range: Option<String>,
10    pub boxapi: Option<String>,
11    pub version: Option<String>,
12    pub access_token: Option<String>,
13}
14
15/// Operations for the "downloads" API area.
16pub struct DownloadsManager {
17    session: std::sync::Arc<runtime::Client>,
18}
19
20impl DownloadsManager {
21    pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
22        Self { session }
23    }
24
25    pub async fn get_file_content(
26        &self,
27        file_id: String,
28        opts: Option<DownloadsGetFileContentOptions>,
29    ) -> Result<runtime::Stream, Error> {
30        let mut url = self.session.base_url("api");
31        url.push_str("/files");
32        url.push('/');
33        let seg = path_escape(&file_id);
34        url.push_str(&seg);
35        url.push_str("/content");
36        let mut req = self.session.new_request("GET", &url);
37        let opts = opts.unwrap_or_default();
38        if let Some(value) = opts.range {
39            req = runtime::with_header(req, "range", &value);
40        }
41        if let Some(value) = opts.boxapi {
42            req = runtime::with_header(req, "boxapi", &value);
43        }
44        if let Some(value) = opts.version {
45            req = runtime::with_query(req, "version", &value);
46        }
47        if let Some(value) = opts.access_token {
48            req = runtime::with_query(req, "access_token", &value);
49        }
50        let resp = self.session.fetch(req).await?;
51        Ok(runtime::response_stream(&resp))
52    }
53}