benchling 5.0.0

Benchling client, generated from the OpenAPI spec.
Documentation
use serde_json::json;
use crate::model::*;
use crate::BenchlingClient;
/**Create this with the associated client method.

That method takes required values as arguments. Set optional values using builder methods on this struct.*/
pub struct ListMoleculesRequest<'a> {
    pub(crate) client: &'a BenchlingClient,
    pub page_size: Option<i64>,
    pub next_token: Option<String>,
    pub sort: Option<String>,
    pub modified_at: Option<String>,
    pub name: Option<String>,
    pub name_includes: Option<String>,
    pub folder_id: Option<String>,
    pub mentioned_in: Option<Vec<String>>,
    pub project_id: Option<String>,
    pub registry_id: Option<String>,
    pub schema_id: Option<String>,
    pub schema_fields: Option<SchemaFieldsQueryParam>,
    pub archive_reason: Option<String>,
    pub mentions: Option<Vec<String>>,
    pub ids: Option<String>,
    pub entity_registry_ids_any_of: Option<String>,
    pub names_any_of: Option<String>,
    pub author_ids_any_of: Option<String>,
    pub chemical_substructure_mol: Option<String>,
    pub chemical_substructure_smiles: Option<String>,
}
impl<'a> ListMoleculesRequest<'a> {
    pub async fn send(self) -> anyhow::Result<MoleculesPaginatedList> {
        let mut r = self.client.client.get("/molecules");
        if let Some(ref unwrapped) = self.page_size {
            r = r.push_query("pageSize", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.next_token {
            r = r.push_query("nextToken", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.sort {
            r = r.push_query("sort", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.modified_at {
            r = r.push_query("modifiedAt", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.name {
            r = r.push_query("name", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.name_includes {
            r = r.push_query("nameIncludes", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.folder_id {
            r = r.push_query("folderId", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.mentioned_in {
            for item in unwrapped {
                r = r.push_query("mentionedIn[]", &item.to_string());
            }
        }
        if let Some(ref unwrapped) = self.project_id {
            r = r.push_query("projectId", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.registry_id {
            r = r.push_query("registryId", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.schema_id {
            r = r.push_query("schemaId", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.schema_fields {
            r = r.push_query("schemaFields", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.archive_reason {
            r = r.push_query("archiveReason", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.mentions {
            for item in unwrapped {
                r = r.push_query("mentions[]", &item.to_string());
            }
        }
        if let Some(ref unwrapped) = self.ids {
            r = r.push_query("ids", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.entity_registry_ids_any_of {
            r = r.push_query("entityRegistryIds.anyOf", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.names_any_of {
            r = r.push_query("names.anyOf", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.author_ids_any_of {
            r = r.push_query("authorIds.anyOf", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.chemical_substructure_mol {
            r = r.push_query("chemicalSubstructure.mol", &unwrapped.to_string());
        }
        if let Some(ref unwrapped) = self.chemical_substructure_smiles {
            r = r.push_query("chemicalSubstructure.smiles", &unwrapped.to_string());
        }
        r = self.client.authenticate(r);
        let res = r.send().await.unwrap().error_for_status();
        match res {
            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
            Err(res) => {
                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
                Err(anyhow::anyhow!("{:?}", text))
            }
        }
    }
    pub fn page_size(mut self, page_size: i64) -> Self {
        self.page_size = Some(page_size);
        self
    }
    pub fn next_token(mut self, next_token: &str) -> Self {
        self.next_token = Some(next_token.to_owned());
        self
    }
    pub fn sort(mut self, sort: &str) -> Self {
        self.sort = Some(sort.to_owned());
        self
    }
    pub fn modified_at(mut self, modified_at: &str) -> Self {
        self.modified_at = Some(modified_at.to_owned());
        self
    }
    pub fn name(mut self, name: &str) -> Self {
        self.name = Some(name.to_owned());
        self
    }
    pub fn name_includes(mut self, name_includes: &str) -> Self {
        self.name_includes = Some(name_includes.to_owned());
        self
    }
    pub fn folder_id(mut self, folder_id: &str) -> Self {
        self.folder_id = Some(folder_id.to_owned());
        self
    }
    pub fn mentioned_in(
        mut self,
        mentioned_in: impl IntoIterator<Item = impl AsRef<str>>,
    ) -> Self {
        self
            .mentioned_in = Some(
            mentioned_in.into_iter().map(|s| s.as_ref().to_owned()).collect(),
        );
        self
    }
    pub fn project_id(mut self, project_id: &str) -> Self {
        self.project_id = Some(project_id.to_owned());
        self
    }
    pub fn registry_id(mut self, registry_id: &str) -> Self {
        self.registry_id = Some(registry_id.to_owned());
        self
    }
    pub fn schema_id(mut self, schema_id: &str) -> Self {
        self.schema_id = Some(schema_id.to_owned());
        self
    }
    pub fn schema_fields(mut self, schema_fields: SchemaFieldsQueryParam) -> Self {
        self.schema_fields = Some(schema_fields);
        self
    }
    pub fn archive_reason(mut self, archive_reason: &str) -> Self {
        self.archive_reason = Some(archive_reason.to_owned());
        self
    }
    pub fn mentions(
        mut self,
        mentions: impl IntoIterator<Item = impl AsRef<str>>,
    ) -> Self {
        self
            .mentions = Some(
            mentions.into_iter().map(|s| s.as_ref().to_owned()).collect(),
        );
        self
    }
    pub fn ids(mut self, ids: &str) -> Self {
        self.ids = Some(ids.to_owned());
        self
    }
    pub fn entity_registry_ids_any_of(
        mut self,
        entity_registry_ids_any_of: &str,
    ) -> Self {
        self.entity_registry_ids_any_of = Some(entity_registry_ids_any_of.to_owned());
        self
    }
    pub fn names_any_of(mut self, names_any_of: &str) -> Self {
        self.names_any_of = Some(names_any_of.to_owned());
        self
    }
    pub fn author_ids_any_of(mut self, author_ids_any_of: &str) -> Self {
        self.author_ids_any_of = Some(author_ids_any_of.to_owned());
        self
    }
    pub fn chemical_substructure_mol(mut self, chemical_substructure_mol: &str) -> Self {
        self.chemical_substructure_mol = Some(chemical_substructure_mol.to_owned());
        self
    }
    pub fn chemical_substructure_smiles(
        mut self,
        chemical_substructure_smiles: &str,
    ) -> Self {
        self
            .chemical_substructure_smiles = Some(
            chemical_substructure_smiles.to_owned(),
        );
        self
    }
}