async_openai_wasm/
invites.rs

1use serde::Serialize;
2
3use crate::{
4    Client,
5    config::Config,
6    error::OpenAIError,
7    types::{Invite, InviteDeleteResponse, InviteListResponse, InviteRequest},
8};
9
10/// Invite and manage invitations for an organization. Invited users are automatically added to the Default project.
11pub struct Invites<'c, C: Config> {
12    client: &'c Client<C>,
13}
14
15impl<'c, C: Config> Invites<'c, C> {
16    pub fn new(client: &'c Client<C>) -> Self {
17        Self { client }
18    }
19
20    /// Returns a list of invites in the organization.
21    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
22    pub async fn list<Q>(&self, query: &Q) -> Result<InviteListResponse, OpenAIError>
23    where
24        Q: Serialize + ?Sized,
25    {
26        self.client
27            .get_with_query("/organization/invites", &query)
28            .await
29    }
30
31    /// Retrieves an invite.
32    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
33    pub async fn retrieve(&self, invite_id: &str) -> Result<Invite, OpenAIError> {
34        self.client
35            .get(format!("/organization/invites/{invite_id}").as_str())
36            .await
37    }
38
39    /// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization.
40    #[crate::byot(T0 = serde::Serialize, R = serde::de::DeserializeOwned)]
41    pub async fn create(&self, request: InviteRequest) -> Result<Invite, OpenAIError> {
42        self.client.post("/organization/invites", request).await
43    }
44
45    /// Delete an invite. If the invite has already been accepted, it cannot be deleted.
46    #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
47    pub async fn delete(&self, invite_id: &str) -> Result<InviteDeleteResponse, OpenAIError> {
48        self.client
49            .delete(format!("/organization/invites/{invite_id}").as_str())
50            .await
51    }
52}