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); }
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); }