harvest_api/request/
update_task.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 UpdateTaskRequest<'a> {
8    pub(crate) client: &'a HarvestClient,
9    pub task_id: String,
10    pub name: Option<String>,
11    pub billable_by_default: Option<bool>,
12    pub default_hourly_rate: Option<f64>,
13    pub is_default: Option<bool>,
14    pub is_active: Option<bool>,
15}
16impl<'a> UpdateTaskRequest<'a> {
17    pub async fn send(self) -> anyhow::Result<Task> {
18        let mut r = self
19            .client
20            .client
21            .patch(&format!("/tasks/{task_id}", task_id = self.task_id));
22        if let Some(ref unwrapped) = self.name {
23            r = r.push_json(json!({ "name" : unwrapped }));
24        }
25        if let Some(ref unwrapped) = self.billable_by_default {
26            r = r.push_json(json!({ "billable_by_default" : unwrapped }));
27        }
28        if let Some(ref unwrapped) = self.default_hourly_rate {
29            r = r.push_json(json!({ "default_hourly_rate" : unwrapped }));
30        }
31        if let Some(ref unwrapped) = self.is_default {
32            r = r.push_json(json!({ "is_default" : unwrapped }));
33        }
34        if let Some(ref unwrapped) = self.is_active {
35            r = r.push_json(json!({ "is_active" : unwrapped }));
36        }
37        r = self.client.authenticate(r);
38        let res = r.send().await.unwrap().error_for_status();
39        match res {
40            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
41            Err(res) => {
42                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
43                Err(anyhow::anyhow!("{:?}", text))
44            }
45        }
46    }
47    pub fn name(mut self, name: &str) -> Self {
48        self.name = Some(name.to_owned());
49        self
50    }
51    pub fn billable_by_default(mut self, billable_by_default: bool) -> Self {
52        self.billable_by_default = Some(billable_by_default);
53        self
54    }
55    pub fn default_hourly_rate(mut self, default_hourly_rate: f64) -> Self {
56        self.default_hourly_rate = Some(default_hourly_rate);
57        self
58    }
59    pub fn is_default(mut self, is_default: bool) -> Self {
60        self.is_default = Some(is_default);
61        self
62    }
63    pub fn is_active(mut self, is_active: bool) -> Self {
64        self.is_active = Some(is_active);
65        self
66    }
67}