asana/request/
instantiate_project.rs

1use serde_json::json;
2use crate::model::*;
3use crate::FluentRequest;
4use serde::{Serialize, Deserialize};
5use httpclient::InMemoryResponseExt;
6use crate::AsanaClient;
7/**You should use this struct via [`AsanaClient::instantiate_project`].
8
9On request success, this will return a [`InstantiateProjectResponse`].*/
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct InstantiateProjectRequest {
12    pub data: ProjectTemplateInstantiateProjectRequest,
13    pub opt_fields: Option<Vec<String>>,
14    pub opt_pretty: Option<bool>,
15    pub project_template_gid: String,
16}
17impl InstantiateProjectRequest {}
18impl FluentRequest<'_, InstantiateProjectRequest> {
19    pub fn opt_fields(
20        mut self,
21        opt_fields: impl IntoIterator<Item = impl AsRef<str>>,
22    ) -> Self {
23        self
24            .params
25            .opt_fields = Some(
26            opt_fields.into_iter().map(|s| s.as_ref().to_owned()).collect(),
27        );
28        self
29    }
30    pub fn opt_pretty(mut self, opt_pretty: bool) -> Self {
31        self.params.opt_pretty = Some(opt_pretty);
32        self
33    }
34}
35impl<'a> ::std::future::IntoFuture for FluentRequest<'a, InstantiateProjectRequest> {
36    type Output = httpclient::InMemoryResult<InstantiateProjectResponse>;
37    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
38    fn into_future(self) -> Self::IntoFuture {
39        Box::pin(async move {
40            let url = &format!(
41                "/project_templates/{project_template_gid}/instantiateProject",
42                project_template_gid = self.params.project_template_gid
43            );
44            let mut r = self.client.client.post(url);
45            r = r.json(json!({ "data" : self.params.data }));
46            if let Some(ref unwrapped) = self.params.opt_fields {
47                for item in unwrapped {
48                    r = r.query("opt_fields[]", &item.to_string());
49                }
50            }
51            if let Some(ref unwrapped) = self.params.opt_pretty {
52                r = r.query("opt_pretty", &unwrapped.to_string());
53            }
54            r = self.client.authenticate(r);
55            let res = r.await?;
56            res.json().map_err(Into::into)
57        })
58    }
59}