Module: GoogleNews
- Defined in:
- lib/google_news.rb,
lib/google_news/cli.rb,
lib/google_news/version.rb
Defined Under Namespace
Classes: CLI, InvalidTopicError
Constant Summary collapse
- HEADLINES_RSS =
'https://news.google.com/news/rss'.freeze
- TOPICS_RSS =
'https://news.google.com/news/rss/headlines/section/topic/'.freeze
- GEO_RSS =
'https://news.google.com/news/rss/headlines/section/geo/'.freeze
- SEARCH_RSS =
'https://news.google.com/rss/search?q='.freeze
- TOPICS =
%w[WORLD NATION BUSINESS TECHNOLOGY ENTERTAINMENT SPORTS SCIENCE HEALTH].freeze
- VERSION =
'0.1.0'.freeze
Class Method Summary collapse
-
.geo(position, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Get top headlines for a specific geographic location from Google News.
-
.headlines(country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Get top headlines from Google News.
-
.search(query, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Search Google News for a query.
-
.topic(topic_name, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Get top headlines for a specific topic from Google News.
-
.website(query, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Search Google News for articles from a specific website.
Class Method Details
.geo(position, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Get top headlines for a specific geographic location from Google News
Note: Google may not support all locations.
62 63 64 65 66 |
# File 'lib/google_news.rb', line 62 def self.geo(position, country: 'us', language: 'en', n: 10) encoded = URI.encode_www_form_component(position.to_s) url = GEO_RSS + encoded + '?' + fill_country_lang_params(country, language) limited_items(url, n) end |
.headlines(country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Get top headlines from Google News
29 30 31 32 |
# File 'lib/google_news.rb', line 29 def self.headlines(country: 'us', language: 'en', n: 10) url = HEADLINES_RSS + '?' + fill_country_lang_params(country, language) limited_items(url, n) end |
.search(query, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Search Google News for a query
Note: This is not the same as a web search. Only news articles are returned.
For a web search, consider using the Google Custom Search API.
83 84 85 86 87 |
# File 'lib/google_news.rb', line 83 def self.search(query, country: 'us', language: 'en', n: 10) encoded = URI.encode_www_form_component(query.to_s) url = SEARCH_RSS + encoded + '&' + fill_country_lang_params(country, language) limited_items(url, n) end |
.topic(topic_name, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Get top headlines for a specific topic from Google News
44 45 46 47 48 49 |
# File 'lib/google_news.rb', line 44 def self.topic(topic_name, country: 'us', language: 'en', n: 10) topic_name = topic_name.to_s.upcase raise InvalidTopicError, 'Invalid topic name. See GoogleNews::TOPICS.' unless TOPICS.include?(topic_name) url = TOPICS_RSS + topic_name + '?' + fill_country_lang_params(country, language) limited_items(url, n) end |
.website(query, country: 'us', language: 'en', n: 10) ⇒ Array<Hash>
Search Google News for articles from a specific website
Note: This is not the same as a web search. Only news articles are returned.
For a web search, consider using the Google Custom Search API.
Note: The parameter logic mimics the (possibly flawed) JavaScript version.
It may not yield expected results for all websites.
114 115 116 117 118 119 |
# File 'lib/google_news.rb', line 114 def self.website(query, country: 'us', language: 'en', n: 10) # Repliziert die (möglicherweise fehlerhafte) Param-Logik aus JS: "site%3A..." + fillWebsiteParams encoded = 'site%3A' + URI.encode_www_form_component(query.to_s) url = SEARCH_RSS + encoded + '&' + fill_website_params(country, language) limited_items(url, n) end |