Exemple #1
0
        public async Task <NewsApiTopHeadlinesResult> GetHeadlines()
        {
            string uri = $"https://newsapi.org/v2/top-headlines?country=us&apiKey={apiKey}";
            NewsApiTopHeadlinesResult result = await _http.GetJsonAsync <NewsApiTopHeadlinesResult>(uri);

            return(result);
        }
Exemple #2
0
        public static Tree From(NewsApiTopHeadlinesResult headlines)
        {
            var items = headlines.Articles
                        .Select((NewsApiArticle x) => ContentItem.From(x))
                        .ToList();
            var result = new Tree()
            {
                Items = items
            };

            result.SourceCounts = items
                                  .GroupBy(
                x => x.ContentSource.Name,
                (key, g) => new KeyValuePair <string, int>(key, g.Count())
                )
                                  .OrderByDescending(kvp => kvp.Value)
                                  .ToList();

            return(result);
        }