Ejemplo n.º 1
0
        /// <summary>
        /// Gets stock data using a Yql query
        /// </summary>
        /// <param name="symbols"></param>
        /// <returns></returns>
        public IEnumerable <StockData> GetStockData(IEnumerable <string> symbols)
        {
            // if no stocks provided, return empty list
            if (symbols == null)
            {
                return(new List <StockData>());
            }

            // enumerate and check count; if no stocks provided, return empty list
            var symbolList = symbols as IList <string> ?? symbols.ToList();

            if (symbolList.Count == 0)
            {
                return(new List <StockData>());
            }

            // get url for query
            var queryUrl = _urlProvider.GetStockUrl(symbolList);

            if (string.IsNullOrWhiteSpace(queryUrl))
            {
                throw new QueryUrlNotProvidedException();
            }

            // get results of query
            var results = _webRequestExecutor.ExecuteRequest(queryUrl);

            if (string.IsNullOrWhiteSpace(results))
            {
                throw new QueryResultsAreEmptyException();
            }

            // interpret response and return
            return(_stockDataResultTranslator.TranslateResultsToStockData(results));
        }