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