async_openai/admin/
groups.rs

1use crate::{
2    config::Config,
3    error::OpenAIError,
4    types::admin::groups::{
5        CreateGroupBody, GroupDeletedResource, GroupListResource, GroupResourceWithSuccess,
6        GroupResponse,
7    },
8    Client, GroupRoles, GroupUsers, RequestOptions,
9};
10
11/// Manage reusable collections of users for organization-wide access control and maintain their membership.
12pub struct Groups<'c, C: Config> {
13    client: &'c Client<C>,
14    pub(crate) request_options: RequestOptions,
15}
16
17impl<'c, C: Config> Groups<'c, C> {
18    pub fn new(client: &'c Client<C>) -> Self {
19        Self {
20            client,
21            request_options: RequestOptions::new(),
22        }
23    }
24
25    /// To call [GroupUsers] group related APIs using this client.
26    pub fn users(&self, group_id: &str) -> GroupUsers<'_, C> {
27        GroupUsers::new(self.client, group_id)
28    }
29
30    /// To call [GroupRoles] group related APIs using this client.
31    pub fn roles(&self, group_id: &str) -> GroupRoles<'_, C> {
32        GroupRoles::new(self.client, group_id)
33    }
34
35    /// Lists all groups in the organization.
36    #[crate::byot(R = serde::de::DeserializeOwned)]
37    pub async fn list(&self) -> Result<GroupListResource, OpenAIError> {
38        self.client
39            .get("/organization/groups", &self.request_options)
40            .await
41    }
42
43    /// Creates a new group in the organization.
44    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
45    pub async fn create(&self, request: CreateGroupBody) -> Result<GroupResponse, OpenAIError> {
46        self.client
47            .post("/organization/groups", request, &self.request_options)
48            .await
49    }
50
51    /// Updates a group's information.
52    #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
53    pub async fn update(
54        &self,
55        group_id: &str,
56        request: crate::types::admin::groups::UpdateGroupBody,
57    ) -> Result<GroupResourceWithSuccess, OpenAIError> {
58        self.client
59            .post(
60                format!("/organization/groups/{group_id}").as_str(),
61                request,
62                &self.request_options,
63            )
64            .await
65    }
66
67    /// Deletes a group from the organization.
68    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
69    pub async fn delete(&self, group_id: &str) -> Result<GroupDeletedResource, OpenAIError> {
70        self.client
71            .delete(
72                format!("/organization/groups/{group_id}").as_str(),
73                &self.request_options,
74            )
75            .await
76    }
77}