use unkey::models::VerifyKeyRequest;
use unkey::Client;
async fn verify_key() {
let c = Client::new("unkey_ABC");
let req = VerifyKeyRequest::new("test_DEF", "api_JJJ");
match c.verify_key(req).await {
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::CreateKeyRequest;
use unkey::Client;
async fn create_key() {
let c = Client::new("unkey_ABC");
let req = CreateKeyRequest::new("api_123")
.set_prefix("test")
.set_remaining(100)
.set_name("test_name")
.set_owner_id("jonxslays");
match c.create_key(req).await {
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::{Refill, RefillInterval, UpdateKeyRequest};
use unkey::Client;
async fn update_key() {
let c = Client::new("unkey_ABC");
let req = UpdateKeyRequest::new("key_XYZ")
.set_name(Some("new_name"))
.set_ratelimit(None)
.set_expires(None)
.set_refill(Some(Refill::new(100, RefillInterval::Daily)));
match c.update_key(req).await {
Ok(_) => println!("Success"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::RevokeKeyRequest;
use unkey::Client;
async fn revoke_key() {
let c = Client::new("unkey_ABC");
let req = RevokeKeyRequest::new("key_XYZ");
match c.revoke_key(req).await {
Ok(_) => println!("Success"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::ListKeysRequest;
use unkey::Client;
async fn list_keys() {
let c = Client::new("unkey_ABC");
let req = ListKeysRequest::new("api_123");
match c.list_keys(req).await {
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::GetApiRequest;
use unkey::Client;
async fn get_api() {
let c = Client::new("unkey_ABC");
let req = GetApiRequest::new("api_123");
match c.get_api(req).await {
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::GetKeyRequest;
use unkey::Client;
async fn get_key() {
let c = Client::new("unkey_ABC");
let req = GetKeyRequest::new("key_123");
match c.get_key(req).await {
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
use unkey::models::{UpdateOp, UpdateRemainingRequest};
use unkey::Client;
async fn update_remaining() {
let c = Client::new("unkey_ABC");
let req = UpdateRemainingRequest::new("key_123", Some(100), UpdateOp::Set);
match c.update_remaining(req).await {
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}