async_openai_alt/
invites.rs

1use serde::Serialize;
2
3use crate::{
4    config::Config,
5    error::OpenAIError,
6    types::{Invite, InviteDeleteResponse, InviteListResponse, InviteRequest},
7    Client,
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    pub async fn list<Q>(&self, query: &Q) -> Result<InviteListResponse, OpenAIError>
22    where
23        Q: Serialize + ?Sized,
24    {
25        self.client
26            .get_with_query("/organization/invites", query)
27            .await
28    }
29
30    /// Retrieves an invite.
31    pub async fn retrieve(&self, invite_id: &str) -> Result<Invite, OpenAIError> {
32        self.client
33            .get(format!("/organization/invites/{invite_id}").as_str())
34            .await
35    }
36
37    /// Create an invite for a user to the organization. The invite must be accepted by the user before they have access to the organization.
38    pub async fn create(&self, request: InviteRequest) -> Result<Invite, OpenAIError> {
39        self.client.post("/organization/invites", request).await
40    }
41
42    /// Delete an invite. If the invite has already been accepted, it cannot be deleted.
43    pub async fn delete(&self, invite_id: &str) -> Result<InviteDeleteResponse, OpenAIError> {
44        self.client
45            .delete(format!("/organization/invites/{invite_id}").as_str())
46            .await
47    }
48}