public double GetExchangeRate(CurrencyConversionContext cccCurrencyConversionContext) { // Constant definition const string EXCHANGE_RATE_HEADER = "rates"; // Code Section // Build convertion URL string strConversionStringURL = $"https://api.exchangeratesapi.io/latest?" + $"symbols={cccCurrencyConversionContext.DestinationCurrency}&" + $"base={cccCurrencyConversionContext.SourceCurrency}"; // Get API response string strResponse = this.DispatchGetAPI(strConversionStringURL); // Convert API response to object dynamic jsonResponse = JsonParser.Parse(strResponse); // Get exchnange rate double dExchangeRate = (float)(jsonResponse[EXCHANGE_RATE_HEADER][$"{cccCurrencyConversionContext.DestinationCurrency}"]); // Return exchange response return(dExchangeRate); }
public double Convert(CurrencyConversionContext cccCurrencyConversionContext) { // Code Section // Return exchange response return(cccCurrencyConversionContext.Amount * this.GetExchangeRate(cccCurrencyConversionContext)); }
public virtual double GetExchangeRate(CurrencyConversionContext cccCurrencyConversionContext) { // Get exchnange rate return(this.m_erfExchangeRateFetcher.GetExchangeRate(cccCurrencyConversionContext)); }