public static IexObject SelectEnum(string s, IexObject iex) { s = CleanString(s, "-"); if (Enum.TryParse(s, true, out iex)) { if (Enum.IsDefined(typeof(IexObject), iex)) { return(iex); } } return(iex); }
public async Task <ActionResult> GetIEXObject(string symbol, string function, string apiToken = null) { string getUrl = "stock/" + symbol + "/" + function + "?token=" + (apiToken ?? _configuration["API:IEXSandbox:Token"]); string client = _configuration["API:IEXSandbox:Client"]; IexObject iex = Helpers.SelectEnum(function, new IexObject()); switch (iex) { case IexObject.balancesheet: return(Ok(await Helpers.GetJson <BalanceSheet>(getUrl, client, _httpClientFactory))); case IexObject.cashflow: return(Ok(await Helpers.GetJson <CashFlow>(getUrl, client, _httpClientFactory))); case IexObject.company: return(Ok(await Helpers.GetJson <Company>(getUrl, client, _httpClientFactory))); case IexObject.dividends: return(Ok(await Helpers.GetJson <List <Dividends> >(getUrl, client, _httpClientFactory))); case IexObject.earnings: return(Ok(await Helpers.GetJson <Earnings>(getUrl, client, _httpClientFactory))); case IexObject.estimates: return(Ok(await Helpers.GetJson <EpsEstimate>(getUrl, client, _httpClientFactory))); case IexObject.financials: return(Ok(await Helpers.GetJson <Financials>(getUrl, client, _httpClientFactory))); case IexObject.income: return(Ok(await Helpers.GetJson <Income>(getUrl, client, _httpClientFactory))); case IexObject.stats: return(Ok(await Helpers.GetJson <KeyStats>(getUrl, client, _httpClientFactory))); case IexObject.news: return(Ok(await Helpers.GetJson <List <News> >(getUrl, client, _httpClientFactory))); case IexObject.peers: return(Ok(await Helpers.GetJson <List <string> >(getUrl, client, _httpClientFactory))); case IexObject.recommendationtrends: return(Ok(await Helpers.GetJson <List <RecommendationTrends> >(getUrl, client, _httpClientFactory))); default: return(new BadRequestObjectResult("IEX data for " + function + " NOT FOUND")); } }