workos 1.0.0

Official Rust SDK for the WorkOS API
Documentation
// Code generated by oagen. DO NOT EDIT.

use crate::client::Client;
#[allow(unused_imports)]
use crate::enums::*;
use crate::error::Error;
#[allow(unused_imports)]
use crate::models::*;
use serde::Serialize;

pub struct UserManagementOrganizationMembershipGroupsApi<'a> {
    pub(crate) client: &'a Client,
}

#[derive(Debug, Clone, Default, Serialize)]
pub struct ListOrganizationMembershipGroupsParams {
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `before="obj_123"` to fetch a new batch of objects before `"obj_123"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub before: Option<String>,
    /// An object ID that defines your place in the list. When the ID is not present, you are at the end of the list. For example, if you make a list request and receive 100 objects, ending with `"obj_123"`, your subsequent call can include `after="obj_123"` to fetch a new batch of objects after `"obj_123"`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub after: Option<String>,
    /// Upper limit on the number of objects to return, between `1` and `100`.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub limit: Option<i64>,
    /// Order the results by the creation time. Supported values are `"asc"` (ascending), `"desc"` (descending), and `"normal"` (descending with reversed cursor semantics where `before` fetches older records and `after` fetches newer records). Defaults to descending.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub order: Option<PaginationOrder>,
}

impl<'a> UserManagementOrganizationMembershipGroupsApi<'a> {
    /// List groups
    ///
    /// Get a list of groups that an organization membership belongs to.
    pub async fn list_organization_membership_groups(
        &self,
        om_id: &str,
        params: ListOrganizationMembershipGroupsParams,
    ) -> Result<GroupList, Error> {
        self.list_organization_membership_groups_with_options(om_id, params, None)
            .await
    }

    /// Variant of [`Self::list_organization_membership_groups`] that accepts per-request [`crate::RequestOptions`].
    pub async fn list_organization_membership_groups_with_options(
        &self,
        om_id: &str,
        params: ListOrganizationMembershipGroupsParams,
        options: Option<&crate::RequestOptions>,
    ) -> Result<GroupList, Error> {
        let om_id = crate::client::path_segment(om_id);
        let path = format!("/user_management/organization_memberships/{om_id}/groups");
        let method = http::Method::GET;
        self.client
            .request_with_query_opts(method, &path, &params, options)
            .await
    }

    /// Returns an async [`futures_util::Stream`] that yields every `Group`
    /// across all pages, advancing the `after` cursor under the hood.
    ///
    /// ```ignore
    /// use futures_util::TryStreamExt;
    /// let all: Vec<Group> = self
    ///     .list_organization_membership_groups_auto_paging(om_id, params)
    ///     .try_collect()
    ///     .await?;
    /// ```
    pub fn list_organization_membership_groups_auto_paging(
        &self,
        om_id: impl Into<String>,
        params: ListOrganizationMembershipGroupsParams,
    ) -> impl futures_util::Stream<Item = Result<Group, Error>> + '_ {
        let om_id: String = om_id.into();
        crate::pagination::auto_paginate_pages(move |after| {
            let om_id = om_id.clone();
            let mut params = params.clone();
            params.after = after;
            async move {
                let page = self
                    .list_organization_membership_groups(&om_id, params)
                    .await?;
                Ok((page.data, page.list_metadata.after))
            }
        })
    }
}