public List <Currency> GetAvailableCurrencies() { Dictionary <string, double> currenciesDict = new Dictionary <string, double>(); string url = $"{_appSettings.Value.BaseEndpoint}/{_appSettings.Value.ApiKey}/latest/USD"; using (HttpClient client = new HttpClient()) { var response = client.GetAsync(url).Result; string json = response.Content.ReadAsStringAsync().Result; CurrencyListResponse currencyListResponse = JsonConvert.DeserializeObject <CurrencyListResponse>(json); currencyListResponse.conversion_rates.TryGetValue("conversion_rates", out var outObj); currenciesDict = JObject.FromObject(outObj).ToObject <Dictionary <string, double> >(); } return(currenciesDict.Select(c => new Currency { Code = c.Key, Name = TryGetCurrencyName(c.Key) }).ToList()); }
public Dictionary <string, double> GetConversionRate(string code) { Dictionary <string, double> currenciesDict = new Dictionary <string, double>(); string url = $"{_appSettings.Value.BaseEndpoint}/{_appSettings.Value.ApiKey}/latest/{code}"; using (HttpClient client = new HttpClient()) { var response = client.GetAsync(url).Result; string json = response.Content.ReadAsStringAsync().Result; CurrencyListResponse currencyListResponse = JsonConvert.DeserializeObject <CurrencyListResponse>(json); if (!currencyListResponse.conversion_rates.TryGetValue("conversion_rates", out var outObj)) { return(null); } currenciesDict = JObject.FromObject(outObj).ToObject <Dictionary <string, double> >(); } return(currenciesDict); }