use crate::{
config::Config,
error::OpenAIError,
types::admin::roles::{
PublicCreateOrganizationRoleBody, PublicRoleListResource, PublicUpdateOrganizationRoleBody,
Role, RoleDeletedResource,
},
Client, RequestOptions,
};
pub struct Roles<'c, C: Config> {
client: &'c Client<C>,
pub(crate) request_options: RequestOptions,
}
impl<'c, C: Config> Roles<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self {
client,
request_options: RequestOptions::new(),
}
}
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<PublicRoleListResource, OpenAIError> {
self.client
.get("/organization/roles", &self.request_options)
.await
}
#[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn create(
&self,
request: PublicCreateOrganizationRoleBody,
) -> Result<Role, OpenAIError> {
self.client
.post("/organization/roles", request, &self.request_options)
.await
}
#[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn update(
&self,
role_id: &str,
request: PublicUpdateOrganizationRoleBody,
) -> Result<Role, OpenAIError> {
self.client
.post(
format!("/organization/roles/{role_id}").as_str(),
request,
&self.request_options,
)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, role_id: &str) -> Result<RoleDeletedResource, OpenAIError> {
self.client
.delete(
format!("/organization/roles/{role_id}").as_str(),
&self.request_options,
)
.await
}
}