front_api/
teams.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Teams {
6    pub client: Client,
7}
8
9impl Teams {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "List teams\n\nList the teams in the company.\n\n```rust,no_run\nasync fn \
16             example_teams_list() -> anyhow::Result<()> {\n    let client = \
17             front_api::Client::new_from_env();\n    let result: \
18             front_api::types::ListTeamsResponse = client.teams().list().await?;\n    \
19             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
20    #[tracing::instrument]
21    pub async fn list<'a>(
22        &'a self,
23    ) -> Result<crate::types::ListTeamsResponse, crate::types::error::Error> {
24        let mut req = self.client.client.request(
25            http::Method::GET,
26            &format!("{}/{}", self.client.base_url, "teams"),
27        );
28        req = req.bearer_auth(&self.client.token);
29        let resp = req.send().await?;
30        let status = resp.status();
31        if status.is_success() {
32            let text = resp.text().await.unwrap_or_default();
33            serde_json::from_str(&text).map_err(|err| {
34                crate::types::error::Error::from_serde_error(
35                    format_serde_error::SerdeError::new(text.to_string(), err),
36                    status,
37                )
38            })
39        } else {
40            Err(crate::types::error::Error::UnexpectedResponse(resp))
41        }
42    }
43
44    #[doc = "Get team\n\nFetch a team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The Team ID (required)\n\n```rust,no_run\nasync fn example_teams_get() -> anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    let result: front_api::types::TeamResponse = client.teams().get(\"some-string\").await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
45    #[tracing::instrument]
46    pub async fn get<'a>(
47        &'a self,
48        team_id: &'a str,
49    ) -> Result<crate::types::TeamResponse, crate::types::error::Error> {
50        let mut req = self.client.client.request(
51            http::Method::GET,
52            &format!(
53                "{}/{}",
54                self.client.base_url,
55                "teams/{team_id}".replace("{team_id}", team_id)
56            ),
57        );
58        req = req.bearer_auth(&self.client.token);
59        let resp = req.send().await?;
60        let status = resp.status();
61        if status.is_success() {
62            let text = resp.text().await.unwrap_or_default();
63            serde_json::from_str(&text).map_err(|err| {
64                crate::types::error::Error::from_serde_error(
65                    format_serde_error::SerdeError::new(text.to_string(), err),
66                    status,
67                )
68            })
69        } else {
70            Err(crate::types::error::Error::UnexpectedResponse(resp))
71        }
72    }
73
74    #[doc = "Add teammates to team\n\nAdd one or more teammates to a team.\n\n**Parameters:**\n\n- \
75             `team_id: &'astr`: The Team ID (required)\n\n```rust,no_run\nasync fn \
76             example_teams_add_teammates_to() -> anyhow::Result<()> {\n    let client = \
77             front_api::Client::new_from_env();\n    client\n        .teams()\n        \
78             .add_teammates_to(\n            \"some-string\",\n            \
79             &front_api::types::TeammateIds {\n                teammate_ids: \
80             vec![\"some-string\".to_string()],\n            },\n        )\n        .await?;\n    \
81             Ok(())\n}\n```"]
82    #[tracing::instrument]
83    pub async fn add_teammates_to<'a>(
84        &'a self,
85        team_id: &'a str,
86        body: &crate::types::TeammateIds,
87    ) -> Result<(), crate::types::error::Error> {
88        let mut req = self.client.client.request(
89            http::Method::POST,
90            &format!(
91                "{}/{}",
92                self.client.base_url,
93                "teams/{team_id}/teammates".replace("{team_id}", team_id)
94            ),
95        );
96        req = req.bearer_auth(&self.client.token);
97        req = req.json(body);
98        let resp = req.send().await?;
99        let status = resp.status();
100        if status.is_success() {
101            Ok(())
102        } else {
103            Err(crate::types::error::Error::UnexpectedResponse(resp))
104        }
105    }
106
107    #[doc = "Remove teammates from team\n\nRemove one or more teammates from a \
108             team.\n\n**Parameters:**\n\n- `team_id: &'astr`: The Team ID \
109             (required)\n\n```rust,no_run\nasync fn example_teams_remove_teammates_from() -> \
110             anyhow::Result<()> {\n    let client = front_api::Client::new_from_env();\n    \
111             client\n        .teams()\n        .remove_teammates_from(\n            \
112             \"some-string\",\n            &front_api::types::TeammateIds {\n                \
113             teammate_ids: vec![\"some-string\".to_string()],\n            },\n        )\n        \
114             .await?;\n    Ok(())\n}\n```"]
115    #[tracing::instrument]
116    pub async fn remove_teammates_from<'a>(
117        &'a self,
118        team_id: &'a str,
119        body: &crate::types::TeammateIds,
120    ) -> Result<(), crate::types::error::Error> {
121        let mut req = self.client.client.request(
122            http::Method::DELETE,
123            &format!(
124                "{}/{}",
125                self.client.base_url,
126                "teams/{team_id}/teammates".replace("{team_id}", team_id)
127            ),
128        );
129        req = req.bearer_auth(&self.client.token);
130        req = req.json(body);
131        let resp = req.send().await?;
132        let status = resp.status();
133        if status.is_success() {
134            Ok(())
135        } else {
136            Err(crate::types::error::Error::UnexpectedResponse(resp))
137        }
138    }
139}