Class: GovKit::SearchEngines::GoogleBlog

Inherits:
Object
  • Object
show all
Defined in:
lib/gov_kit/search_engines/google_blog.rb

Class Method Summary collapse

Class Method Details

.make_request(host, path) ⇒ Object



27
28
29
# File 'lib/gov_kit/search_engines/google_blog.rb', line 27

def self.make_request(host, path)
  response = Net::HTTP.get(host, path)
end

.search(query = [], options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gov_kit/search_engines/google_blog.rb', line 4

def self.search(query=[], options = {})
  query = [query, options[:geo]].compact.join('+')
  host = GovKit::configuration.google_blog_base_url
  path = "/blogsearch_feeds?q=#{URI::encode(query)}&hl=en&output=rss&num=50"

  doc = Nokogiri::XML(make_request(host, path))

  mentions = []

  doc.xpath('//item').each do |i|
    mention = GovKit::Mention.new
    mention.title = i.xpath('title').inner_text
    mention.search_source = 'Google Blogs'
    mention.date = i.xpath('dc:date').inner_text
    mention.excerpt = i.xpath('description').inner_text
    mention.source = i.xpath('dc:publisher').inner_text
    mention.url = i.xpath('link').inner_text

    mentions << mention
  end
  mentions
end