Skip to content

Commit

Permalink
Better Documentation For factory.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xIchigo committed May 1, 2024
1 parent d15a699 commit fb448f6
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions src/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,54 @@ use crate::types::Cluster;

use reqwest::Client;

/// A factory for creating instances of `Helius`
///
/// This factor allows for a centralized configuration and creation of `Helius` client so work can be done across multiple clusters at the same time.
/// Using a factory simplifies client code and enhances maintainability by ensuring that all `Helius` clients are configured consistently.
pub struct HeliusFactory {
api_key: String,
}

impl HeliusFactory {
/// Initializes a new HeliusFactory instance
/// Creates a new `HeliusFactor` capable of producing `Helius` clients
///
/// # Arguments
/// * `api_key` - The API key used for authenticating requests made by the `Helius` clients
///
/// # Example
/// ```rust
/// let factory = HeliusFactory::new("your_api_key_here");
/// ```
pub fn new(api_key: &str) -> Self {
HeliusFactory {
api_key: api_key.to_string(),
}
}

/// Provides a way to create multiple Helius instances in a thread-safe manner
/// Provides a way to create multiple `Helius` clients in a thread-safe manner
///
/// # Arguments
/// * `cluster` - The Solana cluster for which the `Helius` client will be configured
///
/// # Returns
/// A `Result` wrapping a `Helius` client if successful
///
/// # Errors
/// This method returns a `HeliusError` if the configuration or client instantiation fails, typically due to issues with network settings or the API key provided
///
/// # Example
/// ```rust
/// #[tokio::main]
/// async fn main() {
/// let factory = HeliusFactory::new("your_api_key_here");
///
/// let helius_dev = factory.create(Cluster::Devnet).unwrap();
/// helius_dev.request_name(...).await;
///
/// let helius_main = factory.create(Cluster::MainnetBeta).unwrap();
/// helius_main.request_name(...).await;
/// }
/// ```
pub fn create(&self, cluster: Cluster) -> Result<Helius> {
let config: Arc<Config> = Arc::new(Config::new(&self.api_key, cluster)?);
let client: Client = Client::new();
Expand All @@ -33,17 +68,3 @@ impl HeliusFactory {
})
}
}

// Example Usage

// #[tokio::main]
// async fn main() {
// let api_key = "your_api_key_here";
// let factory = HeliusFactory::new(api_key);

// let helius_dev = factory.create(Cluster::Devnet).unwrap();
// // helius_dev.request_name(...).await;

// let helius_main = factory.create(Cluster::MainnetBeta).unwrap();
// // helius_main.request_name(...).await;
// }

0 comments on commit fb448f6

Please sign in to comment.