harvest_api/request/
list_projects.rs

1use serde_json::json;
2use crate::model::*;
3use crate::HarvestClient;
4/**Create this with the associated client method.
5
6That method takes required values as arguments. Set optional values using builder methods on this struct.*/
7pub struct ListProjectsRequest<'a> {
8    pub(crate) client: &'a HarvestClient,
9    pub is_active: Option<bool>,
10    pub client_id: Option<i64>,
11    pub updated_since: Option<String>,
12    pub page: Option<i64>,
13    pub per_page: Option<i64>,
14}
15impl<'a> ListProjectsRequest<'a> {
16    pub async fn send(self) -> anyhow::Result<Projects> {
17        let mut r = self.client.client.get("/projects");
18        if let Some(ref unwrapped) = self.is_active {
19            r = r.push_query("is_active", &unwrapped.to_string());
20        }
21        if let Some(ref unwrapped) = self.client_id {
22            r = r.push_query("client_id", &unwrapped.to_string());
23        }
24        if let Some(ref unwrapped) = self.updated_since {
25            r = r.push_query("updated_since", &unwrapped.to_string());
26        }
27        if let Some(ref unwrapped) = self.page {
28            r = r.push_query("page", &unwrapped.to_string());
29        }
30        if let Some(ref unwrapped) = self.per_page {
31            r = r.push_query("per_page", &unwrapped.to_string());
32        }
33        r = self.client.authenticate(r);
34        let res = r.send().await.unwrap().error_for_status();
35        match res {
36            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
37            Err(res) => {
38                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
39                Err(anyhow::anyhow!("{:?}", text))
40            }
41        }
42    }
43    pub fn is_active(mut self, is_active: bool) -> Self {
44        self.is_active = Some(is_active);
45        self
46    }
47    pub fn client_id(mut self, client_id: i64) -> Self {
48        self.client_id = Some(client_id);
49        self
50    }
51    pub fn updated_since(mut self, updated_since: &str) -> Self {
52        self.updated_since = Some(updated_since.to_owned());
53        self
54    }
55    pub fn page(mut self, page: i64) -> Self {
56        self.page = Some(page);
57        self
58    }
59    pub fn per_page(mut self, per_page: i64) -> Self {
60        self.per_page = Some(per_page);
61        self
62    }
63}