Skip to content

Commit

Permalink
feat(pubky): add PubkyClientBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Aug 25, 2024
1 parent 7eecfb3 commit 620e2ad
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion pubky/src/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ impl Default for PubkyClient {
}
}

#[derive(Debug, Default)]
pub struct PubkyClientBuilder {
pkarr_settings: Option<pkarr::Settings>,
}

impl PubkyClientBuilder {
/// Set Pkarr client [pkarr::Settings].
pub fn pkarr_settings(mut self, settings: pkarr::Settings) -> Self {
self.pkarr_settings = settings.into();
self
}

/// Build [PubkyClient]
pub fn build(self) -> PubkyClient {
PubkyClient {
http: reqwest::Client::builder()
.cookie_store(true)
.user_agent(DEFAULT_USER_AGENT)
.build()
.unwrap(),
pkarr: PkarrClient::new(self.pkarr_settings.unwrap_or_default())
.unwrap()
.as_async(),
}
}
}

// === Public API ===

impl PubkyClient {
Expand All @@ -37,11 +64,15 @@ impl PubkyClient {
.user_agent(DEFAULT_USER_AGENT)
.build()
.unwrap(),
#[cfg(not(target_arch = "wasm32"))]
pkarr: PkarrClient::new(Default::default()).unwrap().as_async(),
}
}

/// Returns a builder to edit settings before creating [PubkyClient].
pub fn builder() -> PubkyClientBuilder {
PubkyClientBuilder::default()
}

pub fn test(testnet: &Testnet) -> Self {
Self {
http: reqwest::Client::builder()
Expand Down

0 comments on commit 620e2ad

Please sign in to comment.