use crate::{
config::Config,
error::OpenAIError,
types::admin::users::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
Client, RequestOptions, UserRoles,
};
pub struct Users<'c, C: Config> {
client: &'c Client<C>,
pub(crate) request_options: RequestOptions,
}
impl<'c, C: Config> Users<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self {
client,
request_options: RequestOptions::new(),
}
}
pub fn roles(&self, user_id: &str) -> UserRoles<'_, C> {
UserRoles::new(self.client, user_id)
}
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<UserListResponse, OpenAIError> {
self.client
.get("/organization/users", &self.request_options)
.await
}
#[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn modify(
&self,
user_id: &str,
request: UserRoleUpdateRequest,
) -> Result<User, OpenAIError> {
self.client
.post(
format!("/organization/users/{user_id}").as_str(),
request,
&self.request_options,
)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
self.client
.get(
format!("/organization/users/{user_id}").as_str(),
&self.request_options,
)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
self.client
.delete(
format!("/organization/users/{user_id}").as_str(),
&self.request_options,
)
.await
}
}