Skip to content

Commit

Permalink
Rename Settings to BlockFrostSettings
Browse files Browse the repository at this point in the history
Removing ambiguity with IpfsSettings
  • Loading branch information
marcospb19 committed Oct 20, 2021
1 parent b6961d3 commit f465f48
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -4,11 +4,11 @@ Rust SDK for Blockfrost.io
You can find multiple usage examples in the [`examples folder`](./examples)

```rust
use blockfrost::{env, BlockFrostApi, Settings};
use blockfrost::{env, BlockFrostApi, BlockFrostSettings};

fn build_api() -> blockfrost::Result<BlockFrostApi> {
let project_id = env::load_project_id()?.expect("BLOCKFROST_PROJECT_ID not found.");
let settings = Settings::new();
let settings = BlockFrostSettings::new();
let api = BlockFrostApi::new(project_id, settings);

Ok(api)
Expand Down
4 changes: 2 additions & 2 deletions examples/all_requests.rs
@@ -1,8 +1,8 @@
use blockfrost::{env, BlockFrostApi, Settings};
use blockfrost::{env, BlockFrostApi, BlockFrostSettings};

fn build_api() -> blockfrost::Result<BlockFrostApi> {
let project_id = env::load_project_id()?.expect("BLOCKFROST_PROJECT_ID not found.");
let settings = Settings::new().configure(|query| {
let settings = BlockFrostSettings::new().configure(|query| {
query.set_count(3);
});
let api = BlockFrostApi::new(project_id, settings);
Expand Down
4 changes: 2 additions & 2 deletions examples/custom_query_parameters.rs
@@ -1,8 +1,8 @@
use blockfrost::{env, BlockFrostApi, QueryOrder, Settings};
use blockfrost::{env, BlockFrostApi, BlockFrostSettings, QueryOrder};

fn build_api() -> blockfrost::Result<BlockFrostApi> {
let project_id = env::load_project_id()?.expect("BLOCKFROST_PROJECT_ID not found.");
let settings = Settings::new().configure(|query| {
let settings = BlockFrostSettings::new().configure(|query| {
query.set_count(5).set_page(10).set_order(QueryOrder::Descending);
});
let api = BlockFrostApi::new(project_id, settings);
Expand Down
4 changes: 2 additions & 2 deletions examples/lister.rs
@@ -1,11 +1,11 @@
//! Example using a concurrent lister for listing 20 pages

// NOTE: StreamExt helps treating listers like iterators (actually, they are Streams)
use blockfrost::{env, stream::StreamExt, BlockFrostApi, Settings};
use blockfrost::{env, stream::StreamExt, BlockFrostApi, BlockFrostSettings};

fn build_api() -> blockfrost::Result<BlockFrostApi> {
let project_id = env::load_project_id()?.expect("BLOCKFROST_PROJECT_ID not found.");
let settings = Settings::new().configure(|query| {
let settings = BlockFrostSettings::new().configure(|query| {
// Show 3 elements per page (just for this example)
query.set_count(3);
});
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_request.rs
@@ -1,8 +1,8 @@
use blockfrost::{env, BlockFrostApi, Settings};
use blockfrost::{env, BlockFrostApi, BlockFrostSettings};

fn build_api() -> blockfrost::Result<BlockFrostApi> {
let project_id = env::load_project_id()?.expect("BLOCKFROST_PROJECT_ID not found.");
let settings = Settings::new();
let settings = BlockFrostSettings::new();
let api = BlockFrostApi::new(project_id, settings);

Ok(api)
Expand Down
4 changes: 2 additions & 2 deletions examples/submit_transaction.rs
@@ -1,8 +1,8 @@
use blockfrost::{env, BlockFrostApi, Settings};
use blockfrost::{env, BlockFrostApi, BlockFrostSettings};

fn build_api() -> blockfrost::Result<BlockFrostApi> {
let project_id = env::load_project_id()?.expect("BLOCKFROST_PROJECT_ID not found.");
let api = BlockFrostApi::new(project_id, Settings::new());
let api = BlockFrostApi::new(project_id, BlockFrostSettings::new());
Ok(api)
}

Expand Down
4 changes: 2 additions & 2 deletions src/api/mod.rs
Expand Up @@ -12,7 +12,7 @@ pub use settings::*;

#[derive(Debug, Clone)]
pub struct BlockFrostApi {
pub settings: Settings,
pub settings: BlockFrostSettings,
client: reqwest::Client,
}

Expand All @@ -26,7 +26,7 @@ impl BlockFrostApi {
///
/// [`HeaderValue`]: (reqwest::header::HeaderValue)
/// [`HeaderValue::from_str`]: (reqwest::header::HeaderValue::from_str)
pub fn new(project_id: impl AsRef<str>, settings: Settings) -> Self {
pub fn new(project_id: impl AsRef<str>, settings: BlockFrostSettings) -> Self {
let header_map = build_header_map(project_id.as_ref());
let client = Client::builder().default_headers(header_map).build().unwrap();

Expand Down
6 changes: 3 additions & 3 deletions src/api/settings.rs
Expand Up @@ -3,12 +3,12 @@ use std::{fmt, ops::FnOnce};
use crate::{CARDANO_MAINNET_NETWORK, CARDANO_TESTNET_NETWORK};

#[derive(Debug, Clone)]
pub struct Settings {
pub struct BlockFrostSettings {
pub(crate) network_endpoint: String,
pub(crate) query_parameters: QueryParameters,
}

impl Settings {
impl BlockFrostSettings {
pub fn new() -> Self {
Self {
network_endpoint: CARDANO_MAINNET_NETWORK.to_string(),
Expand Down Expand Up @@ -107,7 +107,7 @@ impl QueryParameters {
}
}

impl Default for Settings {
impl Default for BlockFrostSettings {
fn default() -> Self {
Self::new()
}
Expand Down
11 changes: 7 additions & 4 deletions src/url.rs
@@ -1,12 +1,12 @@
//! Internal crate type to help building the URLs for the requests.

use crate::{QueryParameters, Settings};
use crate::{BlockFrostSettings, QueryParameters};

#[derive(Clone, Debug)]
pub(crate) struct Url(pub String);

impl Url {
pub fn from_endpoint(settings: &Settings, endpoint_url: &str) -> Self {
pub fn from_endpoint(settings: &BlockFrostSettings, endpoint_url: &str) -> Self {
let page = settings.query_parameters().page;
Self::from_endpoint_with_page(settings, endpoint_url, page)
}
Expand All @@ -15,7 +15,7 @@ impl Url {
//
// This is useful when using a lister that increments internally it's page value
pub fn from_endpoint_with_page(
settings: &Settings,
settings: &BlockFrostSettings,
endpoint_url: &str,
page: Option<u64>,
) -> Self {
Expand All @@ -26,7 +26,10 @@ impl Url {
Self(url)
}

pub fn from_endpoint_without_parameters(settings: &Settings, endpoint_url: &str) -> Self {
pub fn from_endpoint_without_parameters(
settings: &BlockFrostSettings,
endpoint_url: &str,
) -> Self {
// url := "https://cardano-mainnet.blockfrost.io/api/v0" + "/blocks"
let url = settings.network_endpoint.clone() + endpoint_url;
Self(url)
Expand Down

0 comments on commit f465f48

Please sign in to comment.