コード例 #1
0
        /// <summary>
        /// Fetch News from a specific source.
        /// </summary>
        /// <param name="sources">The sources you want to request news for.</param>
        /// <returns><see cref="NewsResult"/> The result of the search with an IEnumerable collection of articles.</returns>
        public async Task <NewsResult> FetchNewsFromSource(NewsSource[] sources)
        {
            var baseUrl       = Constants.BaseUrl;
            var requestSource = NewsSourceFormatter.FormatNewsSources(sources);
            var query         = NewsSourceFormatter.FormatRequestSourceUrl(requestSource, baseUrl);

            var response = await SendRequestAsync(query);

            return(GetResult(response));
        }
コード例 #2
0
        /// <summary>
        /// Fetch News from a specific source.
        /// </summary>
        /// <param name="source">The source you want to request news for. (comma seperated)</param>
        /// <returns><see cref="NewsResult"/> The result of the search with an IEnumerable collection of articles.</returns>
        /// <exception cref="System.NotSupportedException">Throws for an invalid source.</exception>
        public async Task <NewsResult> FetchNewsFromSource(string requestSources)
        {
            var baseUrl = Constants.BaseUrl;
            var query   = NewsSourceFormatter.FormatRequestSourceUrl(requestSources, baseUrl);

            var response = await SendRequestAsync(query);

            if (response.NewsArticles.Count() < 1)
            {
                throw new NotSupportedException("The requested news sources don't seem to be valid. If you have checked the source and it is valid, please open an issue.");
            }

            return(GetResult(response));
        }