async_openai/
groups.rs

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