async_openai_wasm/
users.rs1use serde::Serialize;
2
3use crate::{
4 config::Config,
5 error::OpenAIError,
6 types::{User, UserDeleteResponse, UserListResponse, UserRoleUpdateRequest},
7 Client,
8};
9
10pub struct Users<'c, C: Config> {
12 client: &'c Client<C>,
13}
14
15impl<'c, C: Config> Users<'c, C> {
16 pub fn new(client: &'c Client<C>) -> Self {
17 Self { client }
18 }
19
20 pub async fn list<Q>(&self, query: &Q) -> Result<UserListResponse, OpenAIError>
22 where
23 Q: Serialize + ?Sized,
24 {
25 self.client
26 .get_with_query("/organization/users", query)
27 .await
28 }
29
30 pub async fn modify(
32 &self,
33 user_id: &str,
34 request: UserRoleUpdateRequest,
35 ) -> Result<User, OpenAIError> {
36 self.client
37 .post(format!("/organization/users/{user_id}").as_str(), request)
38 .await
39 }
40
41 pub async fn retrieve(&self, user_id: &str) -> Result<User, OpenAIError> {
43 self.client
44 .get(format!("/organization/users/{user_id}").as_str())
45 .await
46 }
47
48 pub async fn delete(&self, user_id: &str) -> Result<UserDeleteResponse, OpenAIError> {
50 self.client
51 .delete(format!("/organizations/users/{user_id}").as_str())
52 .await
53 }
54}