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