public class OpenExchangeRatesOrgProvider extends Object implements ExchangeRateProvider
Exchange Rates Provider for CurrencyField
and CurrencyFieldType
capable of fetching &
parsing the freely available exchange rates from openexchangerates.org
Configuration Options:
ratesFileLocation
- A file path or absolute URL specifying the JSON data to load (mandatory)refreshInterval
- How frequently (in minutes) to reload the exchange rate data (default: 1440)Disclaimer: This data is collected from various providers and provided free of charge for informational purposes only, with no guarantee whatsoever of accuracy, validity, availability or fitness for any purpose; use at your own risk. Other than that - have fun, and please share/watch/fork if you think data like this should be free!
Modifier and Type | Field and Description |
---|---|
protected static String |
DEFAULT_REFRESH_INTERVAL |
protected static String |
PARAM_RATES_FILE_LOCATION |
protected static String |
PARAM_REFRESH_INTERVAL |
protected org.apache.solr.schema.OpenExchangeRatesOrgProvider.OpenExchangeRates |
rates |
protected String |
ratesFileLocation |
protected int |
refreshIntervalSeconds |
protected ResourceLoader |
resourceLoader |
Constructor and Description |
---|
OpenExchangeRatesOrgProvider() |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object o) |
double |
getExchangeRate(String sourceCurrencyCode,
String targetCurrencyCode)
Returns the currently known exchange rate between two currencies.
|
int |
hashCode() |
void |
inform(ResourceLoader loader)
Passes a ResourceLoader, used to read config files from e.g.
|
void |
init(Map<String,String> params)
Initializes the provider by passing in a set of key/value configs as a map.
|
Set<String> |
listAvailableCurrencies()
List all configured currency codes which are valid as source/target for this Provider
|
boolean |
reload()
Ask the currency provider to explicitly reload/refresh its configuration.
|
String |
toString() |
protected static final String PARAM_RATES_FILE_LOCATION
protected static final String PARAM_REFRESH_INTERVAL
protected static final String DEFAULT_REFRESH_INTERVAL
protected String ratesFileLocation
protected int refreshIntervalSeconds
protected ResourceLoader resourceLoader
protected org.apache.solr.schema.OpenExchangeRatesOrgProvider.OpenExchangeRates rates
public double getExchangeRate(String sourceCurrencyCode, String targetCurrencyCode)
getExchangeRate
in interface ExchangeRateProvider
sourceCurrencyCode
- The source currency being converted from.targetCurrencyCode
- The target currency being converted to.SolrException
- if the requested currency pair cannot be foundpublic Set<String> listAvailableCurrencies()
ExchangeRateProvider
listAvailableCurrencies
in interface ExchangeRateProvider
public boolean reload() throws SolrException
ExchangeRateProvider
reload
in interface ExchangeRateProvider
SolrException
- if there is a problem reloadingpublic void init(Map<String,String> params) throws SolrException
ExchangeRateProvider
Important: Custom config params must be removed from the map before returning
init
in interface ExchangeRateProvider
params
- a @Map of key/value config params to initialize the providerSolrException
public void inform(ResourceLoader loader) throws SolrException
ExchangeRateProvider
Typically called after init
inform
in interface ExchangeRateProvider
loader
- a @ResourceLoader instanceSolrException
Copyright © 2000-2021 Apache Software Foundation. All Rights Reserved.