Skip to content

Commit

Permalink
fix(tests): update apis on docs (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
SHAcollision authored Feb 21, 2025
1 parent 2f42481 commit bc7c723
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 24 deletions.
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ anyhow = "1.0.95"
base64 = "0.22.1"
clap = { version = "4.5.29", features = ["derive"] }
pubky = { path = "../pubky" }
pubky-common = { version = "0.3.0", path = "../pubky-common" }
pubky-common = { path = "../pubky-common" }
reqwest = "0.12.12"
rpassword = "7.3.1"
tokio = { version = "1.43.0", features = ["macros", "rt-multi-thread"] }
Expand Down
16 changes: 8 additions & 8 deletions pubky-homeserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ A pubky-core homeserver that acts as users' agent on the Internet, providing dat
You can use the Homeserver as a library in other crates/binaries or for testing purposes.

```rust
use anyhow::Result;
use pubky_homeserver::Homeserver;

#[tokio::main]
async fn main() -> Result<()> {
Homeserver::builder().run().await?
async fn main() {
let homeserver = unsafe {
Homeserver::builder().run().await.unwrap()
};

tokio::signal::ctrl_c().await?;
println!("Shutting down Homeserver");

tracing::info!("Shutting down Homeserver");

server.shutdown();

Ok(())
homeserver.shutdown();
}
```

Expand Down
32 changes: 17 additions & 15 deletions pubky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,46 +5,48 @@ Rust implementation implementation of [Pubky](https://github.com/pubky/pubky-cor
## Quick Start

```rust
use pkarr::mainline::Testnet;
use pkarr::Keypair;
use pubky_homeserver::Homeserver;
use pubky::Client;
use pubky_testnet::Testnet;
use pubky::{Client, Keypair};

#[tokio::main]
async fn main () {
// Mainline Dht testnet and a temporary homeserver for unit testing.
let testnet = Testnet::new(10);
let server = Homeserver::run_test(&testnet).await.unwrap();
let testnet = Testnet::run_with_hardcoded_configurations().await.unwrap();
let homeserver = testnet.run_homeserver().await.unwrap();

let client = Client::test(&testnet);
let client = Client::builder().testnet().build().unwrap();

// Uncomment the following line instead if you are not just testing.
// let client Client::new().unwrap();
// let client Client::builder().build().unwrap();

// Generate a keypair
let keypair = Keypair::random();

// Signup to a Homeserver
let keypair = Keypair::random();
client.signup(&keypair, &server.public_key()).await.unwrap();
client.signup(&keypair, &homeserver.public_key()).await.unwrap();

// Write data.
let url = format!("pubky://{}/pub/foo.txt", keypair.public_key());
let url = url.as_str();

client.put(url, &[0, 1, 2, 3, 4]).await.unwrap();
let data = [0, 1, 2, 3, 4].to_vec();

// The client has the same familiar API of a reqwest client
client.put(url).body(data.clone()).send().await.unwrap();

// Read using a Public key based link
let response = client.get(url).await.unwrap().unwrap();
let response = client.get(url).send().await.unwrap();
let response_data = response.bytes().await.unwrap();

assert_eq!(response, bytes::Bytes::from(vec![0, 1, 2, 3, 4]));
assert_eq!(response_data, data);

// Delete an entry.
client.delete(url).await.unwrap();
client.delete(url).send().await.unwrap();

let response = client.get(url).await.unwrap();
let response = client.get(url).send().await.unwrap();

assert_eq!(response, None);
assert_eq!(response.status(), 404);
}
```

Expand Down

0 comments on commit bc7c723

Please sign in to comment.