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