use crate::models::ApiKey;
use crate::models::CreateKeyRequest;
use crate::models::CreateKeyResponse;
use crate::models::DeleteApiRequest;
use crate::models::GetApiRequest;
use crate::models::GetApiResponse;
use crate::models::GetKeyRequest;
use crate::models::ListKeysRequest;
use crate::models::ListKeysResponse;
use crate::models::RevokeKeyRequest;
use crate::models::UpdateKeyRequest;
use crate::models::UpdateRemainingRequest;
use crate::models::UpdateRemainingResponse;
use crate::models::VerifyKeyRequest;
use crate::models::VerifyKeyResponse;
use crate::services::ApiService;
use crate::services::HttpService;
use crate::services::KeyService;
#[allow(unused_imports)]
use crate::models::HttpError;
#[derive(Debug, Clone)]
pub struct Client {
http: HttpService,
keys: KeyService,
apis: ApiService,
}
impl Client {
#[must_use]
pub fn new(key: &str) -> Self {
let http = HttpService::new(key);
let keys = KeyService;
let apis = ApiService;
Self { http, keys, apis }
}
#[must_use]
pub fn with_url(key: &str, url: &str) -> Self {
let http = HttpService::with_url(key, url);
let keys = KeyService;
let apis = ApiService;
Self { http, keys, apis }
}
pub fn set_key(&mut self, key: &str) {
self.http.set_key(key);
}
pub fn set_url(&mut self, url: &str) {
self.http.set_url(url);
}
pub async fn verify_key(&self, req: VerifyKeyRequest) -> Result<VerifyKeyResponse, HttpError> {
self.keys.verify_key(&self.http, req).await
}
pub async fn create_key(&self, req: CreateKeyRequest) -> Result<CreateKeyResponse, HttpError> {
self.keys.create_key(&self.http, req).await
}
pub async fn list_keys(&self, req: ListKeysRequest) -> Result<ListKeysResponse, HttpError> {
self.apis.list_keys(&self.http, req).await
}
pub async fn revoke_key(&self, req: RevokeKeyRequest) -> Result<(), HttpError> {
self.keys.revoke_key(&self.http, req).await
}
pub async fn get_api(&self, req: GetApiRequest) -> Result<GetApiResponse, HttpError> {
self.apis.get_api(&self.http, req).await
}
pub async fn delete_api(&self, req: DeleteApiRequest) -> Result<(), HttpError> {
self.apis.delete_api(&self.http, req).await
}
pub async fn update_key(&self, req: UpdateKeyRequest) -> Result<(), HttpError> {
self.keys.update_key(&self.http, req).await
}
pub async fn get_key(&self, req: GetKeyRequest) -> Result<ApiKey, HttpError> {
self.keys.get_key(&self.http, req).await
}
pub async fn update_remaining(
&self,
req: UpdateRemainingRequest,
) -> Result<UpdateRemainingResponse, HttpError> {
self.keys.update_remaining(&self.http, req).await
}
}
#[cfg(test)]
mod test {
use crate::services::ApiService;
use crate::services::KeyService;
use crate::Client;
#[test]
fn new() {
let c = Client::new("");
assert_eq!(c.apis, ApiService);
assert_eq!(c.keys, KeyService);
}
}