harvest_api/request/
create_billable_rate.rs1use serde_json::json;
2use crate::model::*;
3use crate::HarvestClient;
4pub struct CreateBillableRateRequest<'a> {
8 pub(crate) client: &'a HarvestClient,
9 pub user_id: String,
10 pub amount: Option<f64>,
11 pub start_date: Option<String>,
12}
13impl<'a> CreateBillableRateRequest<'a> {
14 pub async fn send(self) -> anyhow::Result<BillableRate> {
15 let mut r = self
16 .client
17 .client
18 .post(&format!("/users/{user_id}/billable_rates", user_id = self.user_id));
19 if let Some(ref unwrapped) = self.amount {
20 r = r.push_json(json!({ "amount" : unwrapped }));
21 }
22 if let Some(ref unwrapped) = self.start_date {
23 r = r.push_json(json!({ "start_date" : unwrapped }));
24 }
25 r = self.client.authenticate(r);
26 let res = r.send().await.unwrap().error_for_status();
27 match res {
28 Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
29 Err(res) => {
30 let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
31 Err(anyhow::anyhow!("{:?}", text))
32 }
33 }
34 }
35 pub fn amount(mut self, amount: f64) -> Self {
36 self.amount = Some(amount);
37 self
38 }
39 pub fn start_date(mut self, start_date: &str) -> Self {
40 self.start_date = Some(start_date.to_owned());
41 self
42 }
43}