public static QuandlObject SelectEnum(string s, QuandlObject qdl) { s = CleanString(s, "-"); if (Enum.TryParse(s, out qdl)) { if (Enum.IsDefined(typeof(QuandlObject), qdl)) { return(qdl); } } return(qdl); }
public async Task <ActionResult> GetQuandlObject(string route, string function, string apiToken) { string getUrl = (route ?? _configuration["API:Quandl:DefaultRoute"]) + "/" + function + ".json?api_key=" + (apiToken ?? _configuration["API:Quandl:Token"]); string client = _configuration["API:Quandl:Client"]; QuandlObject quandl = Helpers.SelectEnum(function, new QuandlObject()); switch (quandl) { case QuandlObject.SP500_DIV_GROWTH_YEAR: return(Ok(await Helpers.GetJson <Sp500DivGrowthYearly>(getUrl, client, _httpClientFactory))); case QuandlObject.SP500_DIV_YIELD_YEAR: return(Ok(await Helpers.GetJson <Sp500DivYieldYearly>(getUrl, client, _httpClientFactory))); case QuandlObject.SP500_PSR_YEAR: return(Ok(await Helpers.GetJson <Sp500PriceSalesYearly>(getUrl, client, _httpClientFactory))); case QuandlObject.YIELD: return(Ok(await Helpers.GetJson <TBillYield>(getUrl, client, _httpClientFactory))); default: return(new BadRequestObjectResult("Quandl data for " + function + " NOT FOUND")); } }