steel-rs 0.1.3

Steel API client
Documentation
use crate::client::{MultipartRequestBuilder, RawRequestBuilder, RequestBuilder, Steel};
use crate::types::*;

pub struct Files<'a> {
    client: &'a Steel,
}

impl<'a> Files<'a> {
    pub fn new(client: &'a Steel) -> Self {
        Self { client }
    }

    /// List global files
    pub fn list(&self) -> RequestBuilder<'_, (), (), FileList> {
        let path = "/v1/files".to_string();
        self.client
            .call(reqwest::Method::GET, path, None::<()>, None::<()>)
    }

    /// Upload a global file
    pub fn upload(
        &self,
        body: FileUploadParams,
    ) -> MultipartRequestBuilder<
        '_,
        impl Fn() -> Result<reqwest::multipart::Form, reqwest::Error>,
        (),
        File,
    > {
        let path = "/v1/files".to_string();
        self.client
            .multipart_call(reqwest::Method::POST, path, None::<()>, move || {
                body.to_form()
            })
    }

    /// Download a global file
    pub fn download(&self, path: &str) -> RawRequestBuilder<'_, (), ()> {
        let path = format!("/v1/files/{}", crate::client::encode_path(path));
        self.client
            .raw_call(reqwest::Method::GET, path, None::<()>, None::<()>)
    }

    /// Delete a global file
    pub fn delete(&self, path: &str) -> RequestBuilder<'_, (), (), serde_json::Value> {
        let path = format!("/v1/files/{}", crate::client::encode_path(path));
        self.client
            .call(reqwest::Method::DELETE, path, None::<()>, None::<()>)
    }
}