benchling/request/
create_folder.rs

1use serde_json::json;
2use crate::model::*;
3use crate::BenchlingClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct CreateFolderRequest<'a> {
8    pub(crate) client: &'a BenchlingClient,
9    pub name: String,
10    pub parent_folder_id: String,
11}
12impl<'a> CreateFolderRequest<'a> {
13    pub async fn send(self) -> anyhow::Result<Folder> {
14        let mut r = self.client.client.post("/folders");
15        r = r.push_json(json!({ "name" : self.name }));
16        r = r.push_json(json!({ "parentFolderId" : self.parent_folder_id }));
17        r = self.client.authenticate(r);
18        let res = r.send().await.unwrap().error_for_status();
19        match res {
20            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
21            Err(res) => {
22                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
23                Err(anyhow::anyhow!("{:?}", text))
24            }
25        }
26    }
27}