asana/request/
create_batch_request.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 CreateBatchRequestRequest {
12 pub data: BatchRequest,
13 pub opt_fields: Option<Vec<String>>,
14 pub opt_pretty: Option<bool>,
15}
16impl CreateBatchRequestRequest {}
17impl FluentRequest<'_, CreateBatchRequestRequest> {
18 pub fn opt_fields(
19 mut self,
20 opt_fields: impl IntoIterator<Item = impl AsRef<str>>,
21 ) -> Self {
22 self
23 .params
24 .opt_fields = Some(
25 opt_fields.into_iter().map(|s| s.as_ref().to_owned()).collect(),
26 );
27 self
28 }
29 pub fn opt_pretty(mut self, opt_pretty: bool) -> Self {
30 self.params.opt_pretty = Some(opt_pretty);
31 self
32 }
33}
34impl<'a> ::std::future::IntoFuture for FluentRequest<'a, CreateBatchRequestRequest> {
35 type Output = httpclient::InMemoryResult<CreateBatchRequestResponse>;
36 type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
37 fn into_future(self) -> Self::IntoFuture {
38 Box::pin(async move {
39 let url = "/batch";
40 let mut r = self.client.client.post(url);
41 r = r.json(json!({ "data" : self.params.data }));
42 if let Some(ref unwrapped) = self.params.opt_fields {
43 for item in unwrapped {
44 r = r.query("opt_fields[]", &item.to_string());
45 }
46 }
47 if let Some(ref unwrapped) = self.params.opt_pretty {
48 r = r.query("opt_pretty", &unwrapped.to_string());
49 }
50 r = self.client.authenticate(r);
51 let res = r.await?;
52 res.json().map_err(Into::into)
53 })
54 }
55}