asana/request/
create_status_for_object.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::create_status_for_object`].
8
9On request success, this will return a [`CreateStatusForObjectResponse`].*/
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct CreateStatusForObjectRequest {
12    pub data: StatusUpdateRequest,
13    pub limit: Option<i64>,
14    pub offset: Option<String>,
15    pub opt_fields: Option<Vec<String>>,
16    pub opt_pretty: Option<bool>,
17}
18impl CreateStatusForObjectRequest {}
19impl FluentRequest<'_, CreateStatusForObjectRequest> {
20    pub fn limit(mut self, limit: i64) -> Self {
21        self.params.limit = Some(limit);
22        self
23    }
24    pub fn offset(mut self, offset: &str) -> Self {
25        self.params.offset = Some(offset.to_owned());
26        self
27    }
28    pub fn opt_fields(
29        mut self,
30        opt_fields: impl IntoIterator<Item = impl AsRef<str>>,
31    ) -> Self {
32        self
33            .params
34            .opt_fields = Some(
35            opt_fields.into_iter().map(|s| s.as_ref().to_owned()).collect(),
36        );
37        self
38    }
39    pub fn opt_pretty(mut self, opt_pretty: bool) -> Self {
40        self.params.opt_pretty = Some(opt_pretty);
41        self
42    }
43}
44impl<'a> ::std::future::IntoFuture for FluentRequest<'a, CreateStatusForObjectRequest> {
45    type Output = httpclient::InMemoryResult<CreateStatusForObjectResponse>;
46    type IntoFuture = ::futures::future::BoxFuture<'a, Self::Output>;
47    fn into_future(self) -> Self::IntoFuture {
48        Box::pin(async move {
49            let url = "/status_updates";
50            let mut r = self.client.client.post(url);
51            r = r.json(json!({ "data" : self.params.data }));
52            if let Some(ref unwrapped) = self.params.limit {
53                r = r.query("limit", &unwrapped.to_string());
54            }
55            if let Some(ref unwrapped) = self.params.offset {
56                r = r.query("offset", &unwrapped.to_string());
57            }
58            if let Some(ref unwrapped) = self.params.opt_fields {
59                for item in unwrapped {
60                    r = r.query("opt_fields[]", &item.to_string());
61                }
62            }
63            if let Some(ref unwrapped) = self.params.opt_pretty {
64                r = r.query("opt_pretty", &unwrapped.to_string());
65            }
66            r = self.client.authenticate(r);
67            let res = r.await?;
68            res.json().map_err(Into::into)
69        })
70    }
71}