rippling_base_api/
groups.rs

1use anyhow::Result;
2
3use crate::Client;
4#[derive(Clone, Debug)]
5pub struct Groups {
6    pub client: Client,
7}
8
9impl Groups {
10    #[doc(hidden)]
11    pub fn new(client: Client) -> Self {
12        Self { client }
13    }
14
15    #[doc = "GET Groups\n\nPlease note, the Groups endpoint requires an OAuth application (i.e. approved 3rd party partners), as the end point is intended for mapping third-party application “Groups” within Rippling organizations.\n\nLists the current third-party groups for an organization.\n\n```rust,no_run\nasync fn example_groups_get() -> anyhow::Result<()> {\n    let client = rippling_base_api::Client::new_from_env();\n    let result: Vec<rippling_base_api::types::Group> = client.groups().get().await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
16    #[tracing::instrument]
17    pub async fn get<'a>(&'a self) -> Result<Vec<crate::types::Group>, crate::types::error::Error> {
18        let mut req = self.client.client.request(
19            http::Method::GET,
20            &format!("{}/{}", self.client.base_url, "platform/api/groups"),
21        );
22        req = req.bearer_auth(&self.client.token);
23        let resp = req.send().await?;
24        let status = resp.status();
25        if status.is_success() {
26            let text = resp.text().await.unwrap_or_default();
27            serde_json::from_str(&text).map_err(|err| {
28                crate::types::error::Error::from_serde_error(
29                    format_serde_error::SerdeError::new(text.to_string(), err),
30                    status,
31                )
32            })
33        } else {
34            let text = resp.text().await.unwrap_or_default();
35            return Err(crate::types::error::Error::Server {
36                body: text.to_string(),
37                status,
38            });
39        }
40    }
41
42    #[doc = "POST Groups\n\nCreates a generic group, that can be associated within the third-party \
43             application.\n\n```rust,no_run\nasync fn example_groups_post() -> anyhow::Result<()> \
44             {\n    let client = rippling_base_api::Client::new_from_env();\n    let result: \
45             rippling_base_api::types::Group = client\n        .groups()\n        \
46             .post(&rippling_base_api::types::PostGroupsRequestBody {\n            name: \
47             Some(\"some-string\".to_string()),\n            spoke_id: \
48             Some(\"some-string\".to_string()),\n            users: \
49             Some(vec![\"some-string\".to_string()]),\n        })\n        .await?;\n    \
50             println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
51    #[tracing::instrument]
52    pub async fn post<'a>(
53        &'a self,
54        body: &crate::types::PostGroupsRequestBody,
55    ) -> Result<crate::types::Group, crate::types::error::Error> {
56        let mut req = self.client.client.request(
57            http::Method::POST,
58            &format!("{}/{}", self.client.base_url, "platform/api/groups"),
59        );
60        req = req.bearer_auth(&self.client.token);
61        req = req.json(body);
62        let resp = req.send().await?;
63        let status = resp.status();
64        if status.is_success() {
65            let text = resp.text().await.unwrap_or_default();
66            serde_json::from_str(&text).map_err(|err| {
67                crate::types::error::Error::from_serde_error(
68                    format_serde_error::SerdeError::new(text.to_string(), err),
69                    status,
70                )
71            })
72        } else {
73            let text = resp.text().await.unwrap_or_default();
74            return Err(crate::types::error::Error::Server {
75                body: text.to_string(),
76                status,
77            });
78        }
79    }
80
81    #[doc = "GET Group\n\nPlease note, the Groups endpoint requires an OAuth application (i.e. approved 3rd party partners), as the end point is intended for mapping third-party application “Groups” within Rippling organizations.\n\n**Parameters:**\n\n- `group_id: i64`: Unique identifier for the group within Rippling. (required)\n\n```rust,no_run\nasync fn example_groups_get_id() -> anyhow::Result<()> {\n    let client = rippling_base_api::Client::new_from_env();\n    let result: rippling_base_api::types::Group = client\n        .groups()\n        .get_id(\n            4 as i64,\n            &rippling_base_api::types::GroupUpdatePayload {\n                name: Some(\"some-string\".to_string()),\n                spoke_id: Some(\"some-string\".to_string()),\n                users: Some(vec![serde_json::Value::String(\"some-string\".to_string())]),\n                version: Some(\"some-string\".to_string()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
82    #[tracing::instrument]
83    pub async fn get_id<'a>(
84        &'a self,
85        group_id: i64,
86        body: &crate::types::GroupUpdatePayload,
87    ) -> Result<crate::types::Group, crate::types::error::Error> {
88        let mut req = self.client.client.request(
89            http::Method::GET,
90            &format!(
91                "{}/{}",
92                self.client.base_url,
93                "platform/api/groups/{groupId}".replace("{groupId}", &format!("{}", group_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            let text = resp.text().await.unwrap_or_default();
102            serde_json::from_str(&text).map_err(|err| {
103                crate::types::error::Error::from_serde_error(
104                    format_serde_error::SerdeError::new(text.to_string(), err),
105                    status,
106                )
107            })
108        } else {
109            let text = resp.text().await.unwrap_or_default();
110            return Err(crate::types::error::Error::Server {
111                body: text.to_string(),
112                status,
113            });
114        }
115    }
116
117    #[doc = "PUT Group\n\nPlease note, the Groups endpoint requires an OAuth application (i.e. approved 3rd party partners), as the end point is intended for mapping third-party application “Groups” within Rippling organizations.\n\nUsing the PUT method, all of the group fields will be updated, even if the corresponding parameter is missing. If the PATCH method is used, and a param is missing, its value won’t be changed.\n\n**Parameters:**\n\n- `group_id: i64`: Unique identifier for the group within Rippling. (required)\n\n```rust,no_run\nasync fn example_groups_put_id() -> anyhow::Result<()> {\n    let client = rippling_base_api::Client::new_from_env();\n    let result: rippling_base_api::types::Group = client\n        .groups()\n        .put_id(\n            4 as i64,\n            &rippling_base_api::types::GroupUpdatePayload {\n                name: Some(\"some-string\".to_string()),\n                spoke_id: Some(\"some-string\".to_string()),\n                users: Some(vec![serde_json::Value::String(\"some-string\".to_string())]),\n                version: Some(\"some-string\".to_string()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
118    #[tracing::instrument]
119    pub async fn put_id<'a>(
120        &'a self,
121        group_id: i64,
122        body: &crate::types::GroupUpdatePayload,
123    ) -> Result<crate::types::Group, crate::types::error::Error> {
124        let mut req = self.client.client.request(
125            http::Method::PUT,
126            &format!(
127                "{}/{}",
128                self.client.base_url,
129                "platform/api/groups/{groupId}".replace("{groupId}", &format!("{}", group_id))
130            ),
131        );
132        req = req.bearer_auth(&self.client.token);
133        req = req.json(body);
134        let resp = req.send().await?;
135        let status = resp.status();
136        if status.is_success() {
137            let text = resp.text().await.unwrap_or_default();
138            serde_json::from_str(&text).map_err(|err| {
139                crate::types::error::Error::from_serde_error(
140                    format_serde_error::SerdeError::new(text.to_string(), err),
141                    status,
142                )
143            })
144        } else {
145            let text = resp.text().await.unwrap_or_default();
146            return Err(crate::types::error::Error::Server {
147                body: text.to_string(),
148                status,
149            });
150        }
151    }
152
153    #[doc = "DELETE Group\n\nPlease note, the Groups endpoint requires an OAuth application (i.e. approved 3rd party partners), as the end point is intended for mapping third-party application “Groups” within Rippling organizations.\n\nDeletes the specified group.\n\n**Parameters:**\n\n- `group_id: i64`: Unique identifier for the group within Rippling. (required)\n\n```rust,no_run\nasync fn example_groups_delete_id() -> anyhow::Result<()> {\n    let client = rippling_base_api::Client::new_from_env();\n    client.groups().delete_id(4 as i64).await?;\n    Ok(())\n}\n```"]
154    #[tracing::instrument]
155    pub async fn delete_id<'a>(&'a self, group_id: i64) -> Result<(), crate::types::error::Error> {
156        let mut req = self.client.client.request(
157            http::Method::DELETE,
158            &format!(
159                "{}/{}",
160                self.client.base_url,
161                "platform/api/groups/{groupId}".replace("{groupId}", &format!("{}", group_id))
162            ),
163        );
164        req = req.bearer_auth(&self.client.token);
165        let resp = req.send().await?;
166        let status = resp.status();
167        if status.is_success() {
168            Ok(())
169        } else {
170            let text = resp.text().await.unwrap_or_default();
171            return Err(crate::types::error::Error::Server {
172                body: text.to_string(),
173                status,
174            });
175        }
176    }
177
178    #[doc = "PATCH Group\n\nPlease note, the Groups endpoint requires an OAuth application (i.e. approved 3rd party partners), as the end point is intended for mapping third-party application “Groups” within Rippling organizations.\n\nUsing the PUT method, all of the group fields will be updated, even if the corresponding parameter is missing. If the PATCH method is used, and a param is missing, its value won’t be changed.\n\n**Parameters:**\n\n- `group_id: i64`: Unique identifier for the group within Rippling. (required)\n\n```rust,no_run\nasync fn example_groups_patch_id() -> anyhow::Result<()> {\n    let client = rippling_base_api::Client::new_from_env();\n    let result: rippling_base_api::types::Group = client\n        .groups()\n        .patch_id(\n            4 as i64,\n            &rippling_base_api::types::GroupUpdatePayload {\n                name: Some(\"some-string\".to_string()),\n                spoke_id: Some(\"some-string\".to_string()),\n                users: Some(vec![serde_json::Value::String(\"some-string\".to_string())]),\n                version: Some(\"some-string\".to_string()),\n            },\n        )\n        .await?;\n    println!(\"{:?}\", result);\n    Ok(())\n}\n```"]
179    #[tracing::instrument]
180    pub async fn patch_id<'a>(
181        &'a self,
182        group_id: i64,
183        body: &crate::types::GroupUpdatePayload,
184    ) -> Result<crate::types::Group, crate::types::error::Error> {
185        let mut req = self.client.client.request(
186            http::Method::PATCH,
187            &format!(
188                "{}/{}",
189                self.client.base_url,
190                "platform/api/groups/{groupId}".replace("{groupId}", &format!("{}", group_id))
191            ),
192        );
193        req = req.bearer_auth(&self.client.token);
194        req = req.json(body);
195        let resp = req.send().await?;
196        let status = resp.status();
197        if status.is_success() {
198            let text = resp.text().await.unwrap_or_default();
199            serde_json::from_str(&text).map_err(|err| {
200                crate::types::error::Error::from_serde_error(
201                    format_serde_error::SerdeError::new(text.to_string(), err),
202                    status,
203                )
204            })
205        } else {
206            let text = resp.text().await.unwrap_or_default();
207            return Err(crate::types::error::Error::Server {
208                body: text.to_string(),
209                status,
210            });
211        }
212    }
213}