harvest_api/request/
update_company.rs1use serde_json::json;
2use crate::model::*;
3use crate::HarvestClient;
4pub struct UpdateCompanyRequest<'a> {
8 pub(crate) client: &'a HarvestClient,
9 pub wants_timestamp_timers: Option<bool>,
10 pub weekly_capacity: Option<i64>,
11}
12impl<'a> UpdateCompanyRequest<'a> {
13 pub async fn send(self) -> anyhow::Result<Company> {
14 let mut r = self.client.client.patch("/company");
15 if let Some(ref unwrapped) = self.wants_timestamp_timers {
16 r = r.push_json(json!({ "wants_timestamp_timers" : unwrapped }));
17 }
18 if let Some(ref unwrapped) = self.weekly_capacity {
19 r = r.push_json(json!({ "weekly_capacity" : unwrapped }));
20 }
21 r = self.client.authenticate(r);
22 let res = r.send().await.unwrap().error_for_status();
23 match res {
24 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
25 Err(res) => {
26 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
27 Err(anyhow::anyhow!("{:?}", text))
28 }
29 }
30 }
31 pub fn wants_timestamp_timers(mut self, wants_timestamp_timers: bool) -> Self {
32 self.wants_timestamp_timers = Some(wants_timestamp_timers);
33 self
34 }
35 pub fn weekly_capacity(mut self, weekly_capacity: i64) -> Self {
36 self.weekly_capacity = Some(weekly_capacity);
37 self
38 }
39}