harvest_api/request/
create_project.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 CreateProjectRequest<'a> {
8    pub(crate) client: &'a HarvestClient,
9    pub client_id: Option<i64>,
10    pub name: Option<String>,
11    pub code: Option<String>,
12    pub is_active: Option<bool>,
13    pub is_billable: Option<bool>,
14    pub is_fixed_fee: Option<bool>,
15    pub bill_by: Option<String>,
16    pub hourly_rate: Option<f64>,
17    pub budget: Option<f64>,
18    pub budget_by: Option<String>,
19    pub budget_is_monthly: Option<bool>,
20    pub notify_when_over_budget: Option<bool>,
21    pub over_budget_notification_percentage: Option<f64>,
22    pub show_budget_to_all: Option<bool>,
23    pub cost_budget: Option<f64>,
24    pub cost_budget_include_expenses: Option<bool>,
25    pub fee: Option<f64>,
26    pub notes: Option<String>,
27    pub starts_on: Option<String>,
28    pub ends_on: Option<String>,
29}
30impl<'a> CreateProjectRequest<'a> {
31    pub async fn send(self) -> anyhow::Result<Project> {
32        let mut r = self.client.client.post("/projects");
33        if let Some(ref unwrapped) = self.client_id {
34            r = r.push_json(json!({ "client_id" : unwrapped }));
35        }
36        if let Some(ref unwrapped) = self.name {
37            r = r.push_json(json!({ "name" : unwrapped }));
38        }
39        if let Some(ref unwrapped) = self.code {
40            r = r.push_json(json!({ "code" : unwrapped }));
41        }
42        if let Some(ref unwrapped) = self.is_active {
43            r = r.push_json(json!({ "is_active" : unwrapped }));
44        }
45        if let Some(ref unwrapped) = self.is_billable {
46            r = r.push_json(json!({ "is_billable" : unwrapped }));
47        }
48        if let Some(ref unwrapped) = self.is_fixed_fee {
49            r = r.push_json(json!({ "is_fixed_fee" : unwrapped }));
50        }
51        if let Some(ref unwrapped) = self.bill_by {
52            r = r.push_json(json!({ "bill_by" : unwrapped }));
53        }
54        if let Some(ref unwrapped) = self.hourly_rate {
55            r = r.push_json(json!({ "hourly_rate" : unwrapped }));
56        }
57        if let Some(ref unwrapped) = self.budget {
58            r = r.push_json(json!({ "budget" : unwrapped }));
59        }
60        if let Some(ref unwrapped) = self.budget_by {
61            r = r.push_json(json!({ "budget_by" : unwrapped }));
62        }
63        if let Some(ref unwrapped) = self.budget_is_monthly {
64            r = r.push_json(json!({ "budget_is_monthly" : unwrapped }));
65        }
66        if let Some(ref unwrapped) = self.notify_when_over_budget {
67            r = r.push_json(json!({ "notify_when_over_budget" : unwrapped }));
68        }
69        if let Some(ref unwrapped) = self.over_budget_notification_percentage {
70            r = r
71                .push_json(json!({ "over_budget_notification_percentage" : unwrapped }));
72        }
73        if let Some(ref unwrapped) = self.show_budget_to_all {
74            r = r.push_json(json!({ "show_budget_to_all" : unwrapped }));
75        }
76        if let Some(ref unwrapped) = self.cost_budget {
77            r = r.push_json(json!({ "cost_budget" : unwrapped }));
78        }
79        if let Some(ref unwrapped) = self.cost_budget_include_expenses {
80            r = r.push_json(json!({ "cost_budget_include_expenses" : unwrapped }));
81        }
82        if let Some(ref unwrapped) = self.fee {
83            r = r.push_json(json!({ "fee" : unwrapped }));
84        }
85        if let Some(ref unwrapped) = self.notes {
86            r = r.push_json(json!({ "notes" : unwrapped }));
87        }
88        if let Some(ref unwrapped) = self.starts_on {
89            r = r.push_json(json!({ "starts_on" : unwrapped }));
90        }
91        if let Some(ref unwrapped) = self.ends_on {
92            r = r.push_json(json!({ "ends_on" : unwrapped }));
93        }
94        r = self.client.authenticate(r);
95        let res = r.send().await.unwrap().error_for_status();
96        match res {
97            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
98            Err(res) => {
99                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
100                Err(anyhow::anyhow!("{:?}", text))
101            }
102        }
103    }
104    pub fn client_id(mut self, client_id: i64) -> Self {
105        self.client_id = Some(client_id);
106        self
107    }
108    pub fn name(mut self, name: &str) -> Self {
109        self.name = Some(name.to_owned());
110        self
111    }
112    pub fn code(mut self, code: &str) -> Self {
113        self.code = Some(code.to_owned());
114        self
115    }
116    pub fn is_active(mut self, is_active: bool) -> Self {
117        self.is_active = Some(is_active);
118        self
119    }
120    pub fn is_billable(mut self, is_billable: bool) -> Self {
121        self.is_billable = Some(is_billable);
122        self
123    }
124    pub fn is_fixed_fee(mut self, is_fixed_fee: bool) -> Self {
125        self.is_fixed_fee = Some(is_fixed_fee);
126        self
127    }
128    pub fn bill_by(mut self, bill_by: &str) -> Self {
129        self.bill_by = Some(bill_by.to_owned());
130        self
131    }
132    pub fn hourly_rate(mut self, hourly_rate: f64) -> Self {
133        self.hourly_rate = Some(hourly_rate);
134        self
135    }
136    pub fn budget(mut self, budget: f64) -> Self {
137        self.budget = Some(budget);
138        self
139    }
140    pub fn budget_by(mut self, budget_by: &str) -> Self {
141        self.budget_by = Some(budget_by.to_owned());
142        self
143    }
144    pub fn budget_is_monthly(mut self, budget_is_monthly: bool) -> Self {
145        self.budget_is_monthly = Some(budget_is_monthly);
146        self
147    }
148    pub fn notify_when_over_budget(mut self, notify_when_over_budget: bool) -> Self {
149        self.notify_when_over_budget = Some(notify_when_over_budget);
150        self
151    }
152    pub fn over_budget_notification_percentage(
153        mut self,
154        over_budget_notification_percentage: f64,
155    ) -> Self {
156        self
157            .over_budget_notification_percentage = Some(
158            over_budget_notification_percentage,
159        );
160        self
161    }
162    pub fn show_budget_to_all(mut self, show_budget_to_all: bool) -> Self {
163        self.show_budget_to_all = Some(show_budget_to_all);
164        self
165    }
166    pub fn cost_budget(mut self, cost_budget: f64) -> Self {
167        self.cost_budget = Some(cost_budget);
168        self
169    }
170    pub fn cost_budget_include_expenses(
171        mut self,
172        cost_budget_include_expenses: bool,
173    ) -> Self {
174        self.cost_budget_include_expenses = Some(cost_budget_include_expenses);
175        self
176    }
177    pub fn fee(mut self, fee: f64) -> Self {
178        self.fee = Some(fee);
179        self
180    }
181    pub fn notes(mut self, notes: &str) -> Self {
182        self.notes = Some(notes.to_owned());
183        self
184    }
185    pub fn starts_on(mut self, starts_on: &str) -> Self {
186        self.starts_on = Some(starts_on.to_owned());
187        self
188    }
189    pub fn ends_on(mut self, ends_on: &str) -> Self {
190        self.ends_on = Some(ends_on.to_owned());
191        self
192    }
193}