pub struct Client { /* private fields */ }Expand description
Async client for the UniRate API.
Construct via Client::new for the common case, or Client::builder
when you need to customize the timeout, base URL, or underlying
reqwest::Client (the customization path used by the mock test suite).
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(api_key: impl Into<String>) -> Self
pub fn new(api_key: impl Into<String>) -> Self
Create a new client with default settings.
Points at https://api.unirateapi.com with a 30-second timeout.
Sourcepub fn builder(api_key: impl Into<String>) -> ClientBuilder
pub fn builder(api_key: impl Into<String>) -> ClientBuilder
Begin a fluent ClientBuilder.
Source§impl Client
impl Client
Sourcepub async fn get_rate(
&self,
from: impl AsRef<str>,
to: impl AsRef<str>,
) -> Result<f64, UniRateError>
pub async fn get_rate( &self, from: impl AsRef<str>, to: impl AsRef<str>, ) -> Result<f64, UniRateError>
Fetch the current exchange rate between two currencies.
Corresponds to GET /api/rates?from=<FROM>&to=<TO>.
Sourcepub async fn get_all_rates(
&self,
from: impl AsRef<str>,
) -> Result<HashMap<String, f64>, UniRateError>
pub async fn get_all_rates( &self, from: impl AsRef<str>, ) -> Result<HashMap<String, f64>, UniRateError>
Fetch all current exchange rates for a given base currency.
Sourcepub async fn convert(
&self,
amount: f64,
from: impl AsRef<str>,
to: impl AsRef<str>,
) -> Result<f64, UniRateError>
pub async fn convert( &self, amount: f64, from: impl AsRef<str>, to: impl AsRef<str>, ) -> Result<f64, UniRateError>
Convert an amount from one currency to another using the current rate.
Sourcepub async fn get_supported_currencies(
&self,
) -> Result<Vec<String>, UniRateError>
pub async fn get_supported_currencies( &self, ) -> Result<Vec<String>, UniRateError>
Fetch the full list of supported currency codes.
Sourcepub async fn get_historical_rate(
&self,
date: impl Into<String>,
from: impl AsRef<str>,
to: impl AsRef<str>,
) -> Result<f64, UniRateError>
pub async fn get_historical_rate( &self, date: impl Into<String>, from: impl AsRef<str>, to: impl AsRef<str>, ) -> Result<f64, UniRateError>
Fetch a historical exchange rate for a specific date (YYYY-MM-DD).
Pro-gated — returns UniRateError::Api with status = 403 on free-tier keys.
Sourcepub async fn get_historical_rates(
&self,
date: impl Into<String>,
from: impl AsRef<str>,
) -> Result<HashMap<String, f64>, UniRateError>
pub async fn get_historical_rates( &self, date: impl Into<String>, from: impl AsRef<str>, ) -> Result<HashMap<String, f64>, UniRateError>
Fetch all historical exchange rates for a base currency on a given date.
Pro-gated — returns UniRateError::Api with status = 403 on free-tier keys.
Sourcepub async fn convert_historical(
&self,
amount: f64,
from: impl AsRef<str>,
to: impl AsRef<str>,
date: impl Into<String>,
) -> Result<f64, UniRateError>
pub async fn convert_historical( &self, amount: f64, from: impl AsRef<str>, to: impl AsRef<str>, date: impl Into<String>, ) -> Result<f64, UniRateError>
Convert an amount using a historical exchange rate.
Pro-gated — returns UniRateError::Api with status = 403 on free-tier keys.
Sourcepub async fn get_time_series(
&self,
start_date: impl Into<String>,
end_date: impl Into<String>,
base: impl AsRef<str>,
currencies: Option<&[&str]>,
amount: f64,
) -> Result<HashMap<String, HashMap<String, f64>>, UniRateError>
pub async fn get_time_series( &self, start_date: impl Into<String>, end_date: impl Into<String>, base: impl AsRef<str>, currencies: Option<&[&str]>, amount: f64, ) -> Result<HashMap<String, HashMap<String, f64>>, UniRateError>
Fetch a time series of exchange rates between two dates (max 5-year span).
Pro-gated — returns UniRateError::Api with status = 403 on free-tier keys.
Sourcepub async fn get_historical_limits(
&self,
) -> Result<HistoricalLimitsResponse, UniRateError>
pub async fn get_historical_limits( &self, ) -> Result<HistoricalLimitsResponse, UniRateError>
Fetch the available historical-data coverage per currency.
Pro-gated — returns UniRateError::Api with status = 403 on free-tier keys.
Sourcepub async fn get_vat_rates(&self) -> Result<VatRatesResponse, UniRateError>
pub async fn get_vat_rates(&self) -> Result<VatRatesResponse, UniRateError>
Fetch VAT rates for all supported countries.
Sourcepub async fn get_vat_rate(
&self,
country: impl AsRef<str>,
) -> Result<VatRateResponse, UniRateError>
pub async fn get_vat_rate( &self, country: impl AsRef<str>, ) -> Result<VatRateResponse, UniRateError>
Fetch the VAT rate for a specific country (ISO-3166 alpha-2 code, e.g. "DE").