use serde_json::json;
use crate::model::*;
use crate::HarvestClient;
pub struct UpdateEstimateItemCategoryRequest<'a> {
pub(crate) client: &'a HarvestClient,
pub estimate_item_category_id: String,
pub name: Option<String>,
}
impl<'a> UpdateEstimateItemCategoryRequest<'a> {
pub async fn send(self) -> anyhow::Result<EstimateItemCategory> {
let mut r = self
.client
.client
.patch(
&format!(
"/estimate_item_categories/{estimate_item_category_id}",
estimate_item_category_id = self.estimate_item_category_id
),
);
if let Some(ref unwrapped) = self.name {
r = r.push_json(json!({ "name" : unwrapped }));
}
r = self.client.authenticate(r);
let res = r.send().await.unwrap().error_for_status();
match res {
Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
Err(res) => {
let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
Err(anyhow::anyhow!("{:?}", text))
}
}
}
pub fn name(mut self, name: &str) -> Self {
self.name = Some(name.to_owned());
self
}
}