Skip to content

Commit

Permalink
Add documentation for remaining public api (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonxslays authored Aug 27, 2023
1 parent 6311cb1 commit 305e216
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 34 deletions.
34 changes: 15 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Full documentation can be found at [https://docs.rs/unkey](https://docs.rs/unkey

## Setup

Add the following to your `Cargo.toml` [dependencies]
Add the following to your `Cargo.toml` dependencies array:

```toml
unkey = "0.1"
Expand All @@ -24,12 +24,11 @@ unkey = "0.1"

### Verifying a key

```rs
```rust
use unkey::models::{VerifyKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
async fn verify_key() {
let c = Client::new("unkey_ABC");
let req = VerifyKeyRequest::new("test_DEF");

Expand All @@ -42,12 +41,11 @@ async fn main() {

### Creating a key

```rs
```rust
use unkey::models::{CreateKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
async fn create_key()-> Result<(), ()> {
let c = Client::new("unkey_ABC");
let req = CreateKeyRequest::new("api_123")
.set_prefix("test")
Expand All @@ -59,17 +57,18 @@ async fn main() {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
}

Ok(())
}
```

### Updating a key

```rs
```rust
use unkey::models::{UpdateKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
async fn update_key() {
let c = Client::new("unkey_ABC");
let req = UpdateKeyRequest::new("key_XYZ")
.set_name(Some("new_name")) // Update the keys name
Expand All @@ -84,12 +83,11 @@ async fn main() {

### Revoking a key

```rs
```rust
use unkey::models::{RevokeKeyRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
async fn revoke_key() {
let c = Client::new("unkey_ABC");
let req = RevokeKeyRequest::new("key_XYZ");

Expand All @@ -102,12 +100,11 @@ async fn main() {

### Listing api keys

```rs
```rust
use unkey::models::{ListKeysRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
async fn list_keys() {
let c = Client::new("unkey_ABC");
let req = ListKeysRequest::new("api_123");

Expand All @@ -120,12 +117,11 @@ async fn main() {

### Getting api information

```rs
```rust
use unkey::models::{GetApiRequest, Wrapped};
use unkey::Client;

#[tokio::main]
async fn main() {
async fn get_api() {
let c = Client::new("unkey_ABC");
let req = GetApiRequest::new("api_123");

Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod logging;
pub mod models;
mod routes;
mod services;
pub mod undefined;

use serde::Deserialize;

Expand Down
7 changes: 6 additions & 1 deletion src/logging.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
lazy_static::lazy_static! {
/// An evenironment variable containing the log level env var.
/// An environment variable containing the log level env var.
pub(crate) static ref UNKEY_LOG: Log = match option_env!("UNKEY_LOG") {
None => Log::None,
Some(level) => match level {
Expand All @@ -14,6 +14,7 @@ lazy_static::lazy_static! {
};
}

/// The different logging levels supported by the crate.
#[derive(Eq, PartialEq, PartialOrd)]
pub(crate) enum Log {
None,
Expand Down Expand Up @@ -48,6 +49,7 @@ impl std::fmt::Display for Log {
}
}

/// Logs the given message at the given level.
macro_rules! log {
($level:expr, $message:expr) => {
if *$crate::logging::UNKEY_LOG >= $level {
Expand All @@ -62,18 +64,21 @@ macro_rules! log {
};
}

/// Logs the given message at the debug level.
macro_rules! debug {
($message:expr) => {
$crate::logging::log!($crate::logging::Log::Debug, $message)
};
}

/// Logs the given message at the infomation level.
macro_rules! info {
($message:expr) => {
$crate::logging::log!($crate::logging::Log::Info, $message)
};
}

/// Logs the given message at the error level.
macro_rules! error {
($message:expr) => {
$crate::logging::log!($crate::logging::Log::Error, $message)
Expand Down
16 changes: 8 additions & 8 deletions src/models/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_json::Value;

use super::Ratelimit;
use super::RatelimitState;
use crate::undefined::UndefinedOr;
use super::UndefinedOr;

/// An outgoing verify key request.
#[derive(Debug, Clone, Serialize)]
Expand Down Expand Up @@ -463,7 +463,7 @@ impl UpdateKeyRequest {
/// # Example
/// ```
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let r = UpdateKeyRequest::new("test_123");
///
/// assert_eq!(r.key_id, String::from("test_123"));
Expand Down Expand Up @@ -493,7 +493,7 @@ impl UpdateKeyRequest {
/// # Example
/// ```
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let r = UpdateKeyRequest::new("test");
///
/// assert_eq!(r.owner_id, UndefinedOr::Undefined);
Expand Down Expand Up @@ -530,7 +530,7 @@ impl UpdateKeyRequest {
/// # Example
/// ```
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let r = UpdateKeyRequest::new("test");
///
/// assert_eq!(r.name, UndefinedOr::Undefined);
Expand Down Expand Up @@ -567,7 +567,7 @@ impl UpdateKeyRequest {
/// # Example
/// ```
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// # use serde_json::json;
/// let r = UpdateKeyRequest::new("test");
///
Expand Down Expand Up @@ -605,7 +605,7 @@ impl UpdateKeyRequest {
/// # Example
/// ```
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let r = UpdateKeyRequest::new("test");
///
/// assert_eq!(r.expires, UndefinedOr::Undefined);
Expand Down Expand Up @@ -638,7 +638,7 @@ impl UpdateKeyRequest {
/// # Example
/// ```
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let r = UpdateKeyRequest::new("test");
///
/// assert_eq!(r.remaining, UndefinedOr::Undefined);
Expand Down Expand Up @@ -673,7 +673,7 @@ impl UpdateKeyRequest {
/// # use unkey::models::UpdateKeyRequest;
/// # use unkey::models::Ratelimit;
/// # use unkey::models::RatelimitType;
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let r = UpdateKeyRequest::new("test");
///
/// assert_eq!(r.ratelimit, UndefinedOr::Undefined);
Expand Down
8 changes: 8 additions & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
//! This module houses the types you will be dealing with when sending and
//! receiving requests from unkey.
//!
//! Mostly you will be constructing the structs suffixed with `Request`, and
//! receiving the structs suffixed with `Response`. With some minor exceptions
//! like [`Wrapped`] and [`UndefinedOr`].
mod apis;
mod http;
mod keys;
mod ratelimit;
mod undefined;

pub use apis::*;
pub use http::*;
pub use keys::*;
pub use ratelimit::*;
pub use undefined::*;
10 changes: 5 additions & 5 deletions src/undefined.rs → src/models/undefined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl<T> UndefinedOr<T> {
///
/// # Example
/// ```
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let val = UndefinedOr::Value(0);
///
/// assert!(val.is_some());
Expand All @@ -34,7 +34,7 @@ impl<T> UndefinedOr<T> {
///
/// # Example
/// ```
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let val = UndefinedOr::<u8>::Undefined;
///
/// assert!(val.is_undefined());
Expand All @@ -47,7 +47,7 @@ impl<T> UndefinedOr<T> {
///
/// # Example
/// ```
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let val = UndefinedOr::<u8>::Null;
///
/// assert!(val.is_null());
Expand All @@ -60,7 +60,7 @@ impl<T> UndefinedOr<T> {
///
/// # Example
/// ```
/// # use unkey::undefined::UndefinedOr;
/// # use unkey::models::UndefinedOr;
/// let val = UndefinedOr::Value(420);
///
/// assert_eq!(val.inner(), Some(&420));
Expand Down Expand Up @@ -113,7 +113,7 @@ impl<T> From<Option<T>> for UndefinedOr<T> {
mod test {
use serde::Serialize;

use crate::undefined::UndefinedOr;
use crate::models::UndefinedOr;

#[derive(Serialize)]
struct TestStruct {
Expand Down

0 comments on commit 305e216

Please sign in to comment.