Skip to content

Commit

Permalink
fix new calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ecklf committed Feb 8, 2025
1 parent 82e2164 commit 81fe4da
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ pub struct CoinGeckoClient {
impl Default for CoinGeckoClient {
fn default() -> Self {
std::env::var("COINGECKO_PRO_API_KEY")
.map(CoinGeckoClient::new_with_pro_api_key)
.map(|k| CoinGeckoClient::new_with_pro_api_key(&k))
.or_else(|_| {
std::env::var("COINGECKO_DEMO_API_KEY").map(CoinGeckoClient::new_with_demo_api_key)
std::env::var("COINGECKO_DEMO_API_KEY")
.map(|k| CoinGeckoClient::new_with_demo_api_key(&k))
})
.unwrap_or_else(|_| CoinGeckoClient::new(COINGECKO_API_DEMO_URL))
}
Expand All @@ -81,31 +82,31 @@ impl CoinGeckoClient {
}
}

/// Creates a new CoinGeckoClient client with a custom host url and api key
/// Creates a new CoinGeckoClient client with demo api key
///
/// # Examples
///
/// ```rust
/// use coingecko::CoinGeckoClient;
/// let client = CoinGeckoClient::new_with_api_key("https://some.url", "x_cg_demo_api_key=some_api_key");
/// let client = CoinGeckoClient::new_with_demo_api_key("x_cg_demo_api_key=some_api_key");
/// ```
pub fn new_with_demo_api_key(api_key: String) -> Self {
pub fn new_with_demo_api_key(api_key: &str) -> Self {
CoinGeckoClient {
host: COINGECKO_API_DEMO_URL,
client: reqwest::Client::new(),
api_key: Some(format!("x_cg_demo_api_key={}", api_key)),
}
}

/// Creates a new CoinGeckoClient client with a custom host url and api key
/// Creates a new CoinGeckoClient client with pro api key
///
/// # Examples
///
/// ```rust
/// use coingecko::CoinGeckoClient;
/// let client = CoinGeckoClient::new_with_api_key("https://some.url", "x_cg_demo_api_key=some_api_key");
/// let client = CoinGeckoClient::new_with_pro_api_key("x_cg_demo_api_key=some_api_key");
/// ```
pub fn new_with_pro_api_key(api_key: String) -> Self {
pub fn new_with_pro_api_key(api_key: &str) -> Self {
CoinGeckoClient {
host: COINGECKO_API_PRO_URL,
client: reqwest::Client::new(),
Expand All @@ -121,11 +122,11 @@ impl CoinGeckoClient {
/// use coingecko::CoinGeckoClient;
/// let client = CoinGeckoClient::new_with_api_key("https://some.url", "x_cg_demo_api_key=some_api_key");
/// ```
pub fn new_with_api_key(host: &'static str, api_key: String) -> Self {
pub fn new_with_api_key(host: &'static str, api_key: &str) -> Self {
CoinGeckoClient {
host,
client: reqwest::Client::new(),
api_key: Some(api_key),
api_key: Some(api_key.to_owned()),
}
}

Expand Down

0 comments on commit 81fe4da

Please sign in to comment.