asana/request/
create_project_for_workspace.rs1use serde_json::json;
2use crate::model::*;
3use crate::FluentRequest;
4use serde::{Serialize, Deserialize};
5use httpclient::InMemoryResponseExt;
6use crate::AsanaClient;
7#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct CreateProjectForWorkspaceRequest {
12 pub data: ProjectRequest,
13 pub opt_fields: Option<Vec<String>>,
14 pub opt_pretty: Option<bool>,
15 pub workspace_gid: String,
16}
17impl CreateProjectForWorkspaceRequest {}
18impl FluentRequest<'_, CreateProjectForWorkspaceRequest> {
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
36for FluentRequest<'a, CreateProjectForWorkspaceRequest> {
37 type Output = httpclient::InMemoryResult<CreateProjectForWorkspaceResponse>;
38 type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
39 fn into_future(self) -> Self::IntoFuture {
40 Box::pin(async move {
41 let url = &format!(
42 "/workspaces/{workspace_gid}/projects", workspace_gid = self.params
43 .workspace_gid
44 );
45 let mut r = self.client.client.post(url);
46 r = r.json(json!({ "data" : self.params.data }));
47 if let Some(ref unwrapped) = self.params.opt_fields {
48 for item in unwrapped {
49 r = r.query("opt_fields[]", &item.to_string());
50 }
51 }
52 if let Some(ref unwrapped) = self.params.opt_pretty {
53 r = r.query("opt_pretty", &unwrapped.to_string());
54 }
55 r = self.client.authenticate(r);
56 let res = r.await?;
57 res.json().map_err(Into::into)
58 })
59 }
60}