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 FeatureFlagsApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListFeatureFlagsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListOrganizationFeatureFlagsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListUserFeatureFlagsParams {
#[serde(skip_serializing_if = "Option::is_none")]
pub before: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub after: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub limit: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub order: Option<PaginationOrder>,
}
impl<'a> FeatureFlagsApi<'a> {
pub async fn list_feature_flags(
&self,
params: ListFeatureFlagsParams,
) -> Result<FlagList, Error> {
self.list_feature_flags_with_options(params, None).await
}
pub async fn list_feature_flags_with_options(
&self,
params: ListFeatureFlagsParams,
options: Option<&crate::RequestOptions>,
) -> Result<FlagList, Error> {
let path = "/feature-flags".to_string();
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
pub fn list_feature_flags_auto_paging(
&self,
params: ListFeatureFlagsParams,
) -> impl futures_util::Stream<Item = Result<Flag, Error>> + '_ {
crate::pagination::auto_paginate_pages(move |after| {
let mut params = params.clone();
params.after = after;
async move {
let page = self.list_feature_flags(params).await?;
Ok((page.data, page.list_metadata.after))
}
})
}
pub async fn get_feature_flag(&self, slug: &str) -> Result<Flag, Error> {
self.get_feature_flag_with_options(slug, None).await
}
pub async fn get_feature_flag_with_options(
&self,
slug: &str,
options: Option<&crate::RequestOptions>,
) -> Result<Flag, Error> {
let slug = crate::client::path_segment(slug);
let path = format!("/feature-flags/{slug}");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
pub async fn disable_feature_flag(&self, slug: &str) -> Result<FeatureFlag, Error> {
self.disable_feature_flag_with_options(slug, None).await
}
pub async fn disable_feature_flag_with_options(
&self,
slug: &str,
options: Option<&crate::RequestOptions>,
) -> Result<FeatureFlag, Error> {
let slug = crate::client::path_segment(slug);
let path = format!("/feature-flags/{slug}/disable");
let method = http::Method::PUT;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
pub async fn enable_feature_flag(&self, slug: &str) -> Result<FeatureFlag, Error> {
self.enable_feature_flag_with_options(slug, None).await
}
pub async fn enable_feature_flag_with_options(
&self,
slug: &str,
options: Option<&crate::RequestOptions>,
) -> Result<FeatureFlag, Error> {
let slug = crate::client::path_segment(slug);
let path = format!("/feature-flags/{slug}/enable");
let method = http::Method::PUT;
self.client
.request_with_query_opts(method, &path, &(), options)
.await
}
pub async fn add_flag_target(&self, resource_id: &str, slug: &str) -> Result<(), Error> {
self.add_flag_target_with_options(resource_id, slug, None)
.await
}
pub async fn add_flag_target_with_options(
&self,
resource_id: &str,
slug: &str,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
let resource_id = crate::client::path_segment(resource_id);
let slug = crate::client::path_segment(slug);
let path = format!("/feature-flags/{slug}/targets/{resource_id}");
let method = http::Method::POST;
self.client
.request_with_query_opts_empty(method, &path, &(), options)
.await
}
pub async fn remove_flag_target(&self, resource_id: &str, slug: &str) -> Result<(), Error> {
self.remove_flag_target_with_options(resource_id, slug, None)
.await
}
pub async fn remove_flag_target_with_options(
&self,
resource_id: &str,
slug: &str,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
let resource_id = crate::client::path_segment(resource_id);
let slug = crate::client::path_segment(slug);
let path = format!("/feature-flags/{slug}/targets/{resource_id}");
let method = http::Method::DELETE;
self.client
.request_with_query_opts_empty(method, &path, &(), options)
.await
}
pub async fn list_organization_feature_flags(
&self,
organization_id: &str,
params: ListOrganizationFeatureFlagsParams,
) -> Result<FlagList, Error> {
self.list_organization_feature_flags_with_options(organization_id, params, None)
.await
}
pub async fn list_organization_feature_flags_with_options(
&self,
organization_id: &str,
params: ListOrganizationFeatureFlagsParams,
options: Option<&crate::RequestOptions>,
) -> Result<FlagList, Error> {
let organization_id = crate::client::path_segment(organization_id);
let path = format!("/organizations/{organization_id}/feature-flags");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
pub fn list_organization_feature_flags_auto_paging(
&self,
organization_id: impl Into<String>,
params: ListOrganizationFeatureFlagsParams,
) -> impl futures_util::Stream<Item = Result<Flag, Error>> + '_ {
let organization_id: String = organization_id.into();
crate::pagination::auto_paginate_pages(move |after| {
let organization_id = organization_id.clone();
let mut params = params.clone();
params.after = after;
async move {
let page = self
.list_organization_feature_flags(&organization_id, params)
.await?;
Ok((page.data, page.list_metadata.after))
}
})
}
pub async fn list_user_feature_flags(
&self,
user_id: &str,
params: ListUserFeatureFlagsParams,
) -> Result<FlagList, Error> {
self.list_user_feature_flags_with_options(user_id, params, None)
.await
}
pub async fn list_user_feature_flags_with_options(
&self,
user_id: &str,
params: ListUserFeatureFlagsParams,
options: Option<&crate::RequestOptions>,
) -> Result<FlagList, Error> {
let user_id = crate::client::path_segment(user_id);
let path = format!("/user_management/users/{user_id}/feature-flags");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
pub fn list_user_feature_flags_auto_paging(
&self,
user_id: impl Into<String>,
params: ListUserFeatureFlagsParams,
) -> impl futures_util::Stream<Item = Result<Flag, Error>> + '_ {
let user_id: String = user_id.into();
crate::pagination::auto_paginate_pages(move |after| {
let user_id = user_id.clone();
let mut params = params.clone();
params.after = after;
async move {
let page = self.list_user_feature_flags(&user_id, params).await?;
Ok((page.data, page.list_metadata.after))
}
})
}
}