Skip to content

Commit

Permalink
Use Result in place of Wrapped in the public api (#38)
Browse files Browse the repository at this point in the history
* Return result from async client methods

* Return result from service methods

* Update changelog
  • Loading branch information
Jonxslays authored Jul 20, 2024
1 parent 296f8a7 commit 58f7b24
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 119 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
# v0.4.0 (Jul 2024)

## Breaking changes

- All async `Client` methods and service methods now return a `Result` instead of `Wrapped`.
- Wrapped is now `pub(crate)` and considered internal implementation detail.

## Additions

- `Result<T, HttpErrorResponse>` now implements `From<Wrapped<T>>`.

---

# v0.3.0 (Dec 2023)

## Breaking changes
Expand Down Expand Up @@ -33,6 +46,8 @@

- Rename `UsageExceeded` error code to `KeyUsageExceeded`.

---

# v0.1.0 (Aug 2023)

## Additions
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "unkey"
description = "An asynchronous Rust SDK for the Unkey API."
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["Jonxslays"]
readme = "README.md"
Expand All @@ -24,4 +24,4 @@ serde_json = "1"
[dependencies.reqwest]
version = "0.11"
features = ["json", "rustls-tls"]
default_features = false
default-features = false
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ All the API key management features you love, now with more type safety!

## MSRV

The minimum supported Rust verision for the project is `1.63.0`.
The minimum supported Rust version for the project is `1.63.0`.

## Documentation

Expand All @@ -17,7 +17,7 @@ Full documentation can be found at [https://docs.rs/unkey](https://docs.rs/unkey
### Using `cargo`

```bash
$ cargo add unkey
cargo add unkey
```

### Manually
Expand All @@ -33,24 +33,24 @@ unkey = "0.3" # I won't forget to update this™
### Verifying a key

```rust
use unkey::models::{VerifyKeyRequest, Wrapped};
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 {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Creating a key

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

async fn create_key() {
Expand All @@ -62,16 +62,16 @@ async fn create_key() {
.set_owner_id("jonxslays");

match c.create_key(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Updating a key

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

async fn update_key() {
Expand All @@ -83,93 +83,93 @@ async fn update_key() {
.set_refill(Some(Refill::new(100, RefillInterval::Daily)));

match c.update_key(req).await {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Revoking a key

```rust
use unkey::models::{RevokeKeyRequest, Wrapped};
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 {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Listing api keys

```rust
use unkey::models::{ListKeysRequest, Wrapped};
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 {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Getting api information

```rust
use unkey::models::{GetApiRequest, Wrapped};
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 {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Getting key details

```rust
use unkey::models::{GetKeyRequest, Wrapped};
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 {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```

### Update remaining verifications

```rust
use unkey::models::{UpdateOp, UpdateRemainingRequest, Wrapped};
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 {
Wrapped::Ok(res) => println!("{res:?}"),
Wrapped::Err(err) => eprintln!("{err:?}"),
Ok(res) => println!("{res:?}"),
Err(err) => eprintln!("{err:?}"),
}
}
```
Expand Down
Loading

0 comments on commit 58f7b24

Please sign in to comment.