benchling/request/
get_plate.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 GetPlateRequest<'a> {
8    pub(crate) client: &'a BenchlingClient,
9    pub plate_id: String,
10    pub returning: Option<String>,
11}
12impl<'a> GetPlateRequest<'a> {
13    pub async fn send(self) -> anyhow::Result<Plate> {
14        let mut r = self
15            .client
16            .client
17            .get(&format!("/plates/{plate_id}", plate_id = self.plate_id));
18        if let Some(ref unwrapped) = self.returning {
19            r = r.push_query("returning", &unwrapped.to_string());
20        }
21        r = self.client.authenticate(r);
22        let res = r.send().await.unwrap().error_for_status();
23        match res {
24            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
25            Err(res) => {
26                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
27                Err(anyhow::anyhow!("{:?}", text))
28            }
29        }
30    }
31    pub fn returning(mut self, returning: &str) -> Self {
32        self.returning = Some(returning.to_owned());
33        self
34    }
35}