use std::sync::Arc;
use reqwest::Method;
use super::types;
use crate::{
error::SdkError,
transport::{RequestSpec, Transport},
};
#[derive(Debug, Clone)]
pub struct ApiKeysClient {
transport: Arc<Transport>,
}
impl ApiKeysClient {
pub(crate) fn new(transport: Arc<Transport>) -> Self {
Self { transport }
}
pub async fn list(&self) -> Result<Vec<types::ApiKeyListItem>, SdkError> {
self.transport
.request_json::<(), Vec<types::ApiKeyListItem>>(RequestSpec {
method: Method::GET,
path: "/api-keys",
..Default::default()
})
.await
}
pub async fn create(
&self,
body: &types::CreateApiKeyRequest,
) -> Result<types::CreateApiKeyResponse, SdkError> {
self.transport
.request_json::<types::CreateApiKeyRequest, types::CreateApiKeyResponse>(RequestSpec {
method: Method::POST,
path: "/api-keys",
body: Some(body),
..Default::default()
})
.await
}
pub async fn update(
&self,
id: &str,
body: &types::UpdateApiKeyRequest,
) -> Result<(), SdkError> {
let path = format!("/api-keys/{id}");
self.transport
.request_json::<types::UpdateApiKeyRequest, ()>(RequestSpec {
method: Method::PATCH,
path: &path,
body: Some(body),
..Default::default()
})
.await
}
pub async fn revoke(&self, id: &str) -> Result<(), SdkError> {
let path = format!("/api-keys/{id}");
self.transport
.request_json::<(), ()>(RequestSpec {
method: Method::DELETE,
path: &path,
..Default::default()
})
.await
}
pub async fn restore(&self, id: &str) -> Result<(), SdkError> {
let path = format!("/api-keys/{id}/restore");
self.transport
.request_json::<(), ()>(RequestSpec {
method: Method::POST,
path: &path,
..Default::default()
})
.await
}
pub async fn purge(&self, id: &str) -> Result<(), SdkError> {
let path = format!("/api-keys/{id}/purge");
self.transport
.request_json::<(), ()>(RequestSpec {
method: Method::DELETE,
path: &path,
..Default::default()
})
.await
}
}