Skip to content

Commit

Permalink
refactor(pubky): refactor modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Jul 26, 2024
1 parent 42156b1 commit cdfd6c3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 31 deletions.
6 changes: 2 additions & 4 deletions pubky/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use std::{collections::HashMap, fmt::format, time::Duration};
use ureq::{Agent, Response};
use url::Url;

use crate::error::{Error, Result};

use pkarr::{DhtSettings, PkarrClient, Settings, Testnet};

use crate::error::{Error, Result};

#[derive(Debug, Clone)]
pub struct PubkyClient {
agent: Agent,
Expand Down Expand Up @@ -40,8 +40,6 @@ impl PubkyClient {
}
}

// === Public Methods ===

// === Private Methods ===

fn request(&self, method: HttpMethod, url: &Url) -> ureq::Request {
Expand Down
5 changes: 2 additions & 3 deletions pubky/src/client/auth.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::PubkyClient;
use pkarr::{Keypair, PublicKey};

use pubky_common::{auth::AuthnSignature, session::Session};

use super::{Error, HttpMethod, Result};
use pkarr::{Keypair, PublicKey};
use super::{Error, HttpMethod, PubkyClient, Result};

impl PubkyClient {
/// Signup to a homeserver and update Pkarr accordingly.
Expand Down
4 changes: 1 addition & 3 deletions pubky/src/client/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ use bytes::Bytes;

use pkarr::PublicKey;

use crate::PubkyClient;

use super::Result;
use super::{PubkyClient, Result};

impl PubkyClient {
pub fn put(&self, pubky: &PublicKey, path: &str, content: &[u8]) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion pubky/src/client_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use bytes::Bytes;
use pkarr::{Keypair, PublicKey};
use pubky_common::session::Session;

use crate::{error::Result, PubkyClient};
use crate::{client::PubkyClient, error::Result};

pub struct PubkyClientAsync(PubkyClient);

Expand Down
13 changes: 8 additions & 5 deletions pubky/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ macro_rules! if_wasm {
)*}
}

mod error;
pub use error::Error;

if_not_wasm! {
mod client;
mod client_async;

pub use client::PubkyClient;
use pkarr::{PkarrClient};
use ureq::{Agent, Response};
use url::Url;
}

if_wasm! {
mod wasm;

pub use wasm::{PubkyClient, Keypair};
pub use wasm::keys::Keypair;
pub use wasm::PubkyClient;
}

mod error;
pub use error::Error;
14 changes: 9 additions & 5 deletions pubky/src/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
mod client;
mod keys;
mod pkarr;
use wasm_bindgen::prelude::*;

pub use client::PubkyClient;
pub use keys::Keypair;
pub mod auth;
pub mod keys;
pub mod pkarr;

#[wasm_bindgen]
pub struct PubkyClient {
pub(crate) pkarr: pkarr::PkarrRelayClient,
}
10 changes: 1 addition & 9 deletions pubky/src/wasm/client.rs → pubky/src/wasm/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,7 @@ use web_sys::RequestMode;

use pkarr::PkarrRelayClient;

use super::Keypair;

#[wasm_bindgen]
pub struct Error {}

#[wasm_bindgen]
pub struct PubkyClient {
pub(crate) pkarr: PkarrRelayClient,
}
use super::{keys::Keypair, PubkyClient};

#[wasm_bindgen]
impl PubkyClient {
Expand Down
2 changes: 1 addition & 1 deletion pubky/src/wasm/pkarr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use wasm_bindgen::prelude::*;

pub use pkarr::{
dns::{rdata::SVCB, Packet},
Keypair, PublicKey, SignedPacket,
Keypair, PkarrRelayClient, PublicKey, SignedPacket,
};

use crate::error::Result;
Expand Down

0 comments on commit cdfd6c3

Please sign in to comment.