Exemplo n.º 1
0
        public async Task <NewsModel> GetNews()
        {
            string      apiKey     = options.Value.NewsApiKey;
            INewsClient newsClient = new ClientBuilder()
            {
                ApiKey = apiKey
            }.Build();
            INewsArticles newsArticles = await newsClient.GetTopHeadlines(new TopHeadlinesBuilder().WithSourcesQuery(Source.BBC_NEWS).Build());

            List <HeadlineModel> headlinesList = new List <HeadlineModel>();

            for (int i = 0; i < 3; i++)
            {
                var headline = new HeadlineModel()
                {
                    Id              = i + 1,
                    NewsTitle       = newsArticles[i].Title,
                    NewsDescription = newsArticles[i].Description
                };
                headlinesList.Add(headline);
            }

            NewsModel news = new NewsModel()
            {
                Headlines = headlinesList
            };

            return(news);
        }
Exemplo n.º 2
0
        public IActionResult About(string query)
        {
            var           newsApiKey = _config["NewsApi:apiKey"];
            HeadlineModel articles   = new HeadlineModel();
            var           url        = "http://newsapi.org/v2/everything?q=" + query +
                                       "&apiKey=" + newsApiKey;

            var json = new WebClient().DownloadString(url);

            articles = JsonConvert.DeserializeObject <HeadlineModel>(json);
            return(View(articles));
        }
Exemplo n.º 3
0
        public IActionResult Index()
        {
            var           newsApiKey = _config["NewsApi:apiKey"];
            HeadlineModel articles   = new HeadlineModel();
            var           url        = "http://newsapi.org/v2/top-headlines?" +
                                       "country=us&" +
                                       "apiKey=" + newsApiKey;

            var json = new WebClient().DownloadString(url);

            articles = JsonConvert.DeserializeObject <HeadlineModel>(json);
            return(View(articles));
        }