use crate::internal::path_escape;
use crate::runtime::{self, Error};
pub struct ZipDownloadsManager {
session: std::sync::Arc<runtime::Client>,
}
impl ZipDownloadsManager {
pub(crate) fn new(session: std::sync::Arc<runtime::Client>) -> Self {
Self { session }
}
pub async fn create(
&self,
body: crate::models::schemas::ZipDownloadRequest,
) -> Result<crate::models::schemas::ZipDownload, Error> {
let mut url = self.session.base_url("api");
url.push_str("/zip_downloads");
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_content(&self, zip_download_id: String) -> Result<runtime::Stream, Error> {
let mut url = self.session.base_url("download");
url.push_str("/zip_downloads");
url.push('/');
let seg = path_escape(&zip_download_id);
url.push_str(&seg);
url.push_str("/content");
let req = self.session.new_request("GET", &url);
let resp = self.session.fetch(req).await?;
Ok(runtime::response_stream(&resp))
}
pub async fn get_status(
&self,
zip_download_id: String,
) -> Result<crate::models::schemas::ZipDownloadStatus, Error> {
let mut url = self.session.base_url("api");
url.push_str("/zip_downloads");
url.push('/');
let seg = path_escape(&zip_download_id);
url.push_str(&seg);
url.push_str("/status");
let req = self.session.new_request("GET", &url);
let resp = self.session.fetch(req).await?;
let data = runtime::response_bytes(&resp)?;
Ok(serde_json::from_slice(&data)?)
}
}