use sfr_types as st;
pub use st::FilesRemoteAddResponse;
use crate::{Client, Request};
use serde::Serialize;
#[derive(Serialize, Debug)]
pub struct FilesRemoteAdd(st::FilesRemoteAddRequest);
const API_CODE: &str = "files.remote.add";
impl FilesRemoteAdd {
async fn request_inner(&self, client: &Client) -> Result<FilesRemoteAddResponse, st::Error> {
#[allow(clippy::missing_docs_in_private_items)] const URL: &str = "https://slack.com/api/files.remote.add";
tracing::debug!("form = {self:?}");
let response = client
.client()
.post(URL)
.bearer_auth(client.token())
.form(&self)
.send()
.await
.map_err(|e| st::Error::failed_to_request_by_http(API_CODE, e))?;
tracing::debug!("response = {response:?}");
let body: serde_json::Value = response
.json()
.await
.map_err(|e| st::Error::failed_to_read_json(API_CODE, e))?;
tracing::debug!("body = {body:?}");
body.try_into()
}
}
impl From<st::FilesRemoteAddRequest> for FilesRemoteAdd {
fn from(inner: st::FilesRemoteAddRequest) -> Self {
Self(inner)
}
}
impl Request for FilesRemoteAdd {
type Response = FilesRemoteAddResponse;
async fn request(self, client: &Client) -> Result<Self::Response, st::Error> {
self.request_inner(client).await
}
}