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 ApiKeysApi<'a> {
pub(crate) client: &'a Client,
}
#[derive(Debug, Clone, Default, Serialize)]
pub struct ListOrganizationApiKeysParams {
#[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, Serialize)]
pub struct CreateOrganizationApiKeyParams {
#[serde(skip)]
pub body: CreateOrganizationApiKey,
}
impl CreateOrganizationApiKeyParams {
#[allow(deprecated)]
pub fn new(body: CreateOrganizationApiKey) -> Self {
Self { body }
}
}
#[derive(Debug, Clone, Serialize)]
pub struct CreateValidationParams {
#[serde(skip)]
pub body: ValidateApiKey,
}
impl CreateValidationParams {
#[allow(deprecated)]
pub fn new(body: ValidateApiKey) -> Self {
Self { body }
}
}
impl<'a> ApiKeysApi<'a> {
pub async fn list_organization_api_keys(
&self,
organization_id: &str,
params: ListOrganizationApiKeysParams,
) -> Result<OrganizationApiKeyList, Error> {
self.list_organization_api_keys_with_options(organization_id, params, None)
.await
}
pub async fn list_organization_api_keys_with_options(
&self,
organization_id: &str,
params: ListOrganizationApiKeysParams,
options: Option<&crate::RequestOptions>,
) -> Result<OrganizationApiKeyList, Error> {
let organization_id = crate::client::path_segment(organization_id);
let path = format!("/organizations/{organization_id}/api_keys");
let method = http::Method::GET;
self.client
.request_with_query_opts(method, &path, ¶ms, options)
.await
}
pub fn list_organization_api_keys_auto_paging(
&self,
organization_id: impl Into<String>,
params: ListOrganizationApiKeysParams,
) -> impl futures_util::Stream<Item = Result<OrganizationApiKey, 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_api_keys(&organization_id, params)
.await?;
Ok((page.data, page.list_metadata.after))
}
})
}
pub async fn create_organization_api_key(
&self,
organization_id: &str,
params: CreateOrganizationApiKeyParams,
) -> Result<OrganizationApiKeyWithValue, Error> {
self.create_organization_api_key_with_options(organization_id, params, None)
.await
}
pub async fn create_organization_api_key_with_options(
&self,
organization_id: &str,
params: CreateOrganizationApiKeyParams,
options: Option<&crate::RequestOptions>,
) -> Result<OrganizationApiKeyWithValue, Error> {
let organization_id = crate::client::path_segment(organization_id);
let path = format!("/organizations/{organization_id}/api_keys");
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
pub async fn create_validation(
&self,
params: CreateValidationParams,
) -> Result<ApiKeyValidationResponse, Error> {
self.create_validation_with_options(params, None).await
}
pub async fn create_validation_with_options(
&self,
params: CreateValidationParams,
options: Option<&crate::RequestOptions>,
) -> Result<ApiKeyValidationResponse, Error> {
let path = "/api_keys/validations".to_string();
let method = http::Method::POST;
self.client
.request_with_body_opts(method, &path, ¶ms, Some(¶ms.body), options)
.await
}
pub async fn delete_api_key(&self, id: &str) -> Result<(), Error> {
self.delete_api_key_with_options(id, None).await
}
pub async fn delete_api_key_with_options(
&self,
id: &str,
options: Option<&crate::RequestOptions>,
) -> Result<(), Error> {
let id = crate::client::path_segment(id);
let path = format!("/api_keys/{id}");
let method = http::Method::DELETE;
self.client
.request_with_query_opts_empty(method, &path, &(), options)
.await
}
}