harvest_api/request/
update_user_assigned_teammates.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 UpdateUserAssignedTeammatesRequest<'a> {
8    pub(crate) client: &'a HarvestClient,
9    pub user_id: String,
10    pub teammate_ids: Option<serde_json::Value>,
11}
12impl<'a> UpdateUserAssignedTeammatesRequest<'a> {
13    pub async fn send(self) -> anyhow::Result<TeammatesPatchResponse> {
14        let mut r = self
15            .client
16            .client
17            .patch(&format!("/users/{user_id}/teammates", user_id = self.user_id));
18        if let Some(ref unwrapped) = self.teammate_ids {
19            r = r.push_json(json!({ "teammate_ids" : unwrapped }));
20        }
21        r = self.client.authenticate(r);
22        let res = r.send().await.unwrap().error_for_status();
23        match res {
24            Ok(res) => res.json().await.map_err(|e| anyhow::anyhow!("{:?}", e)),
25            Err(res) => {
26                let text = res.text().await.map_err(|e| anyhow::anyhow!("{:?}", e))?;
27                Err(anyhow::anyhow!("{:?}", text))
28            }
29        }
30    }
31    pub fn teammate_ids(mut self, teammate_ids: serde_json::Value) -> Self {
32        self.teammate_ids = Some(teammate_ids);
33        self
34    }
35}