Module: NVD::Feed::CPE

Defined in:
lib/nvd/feed/cpe.rb

Constant Summary collapse

LOCATIONS =
{}

Class Method Summary collapse

Class Method Details

.fetch(tag, etag = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nvd/feed/cpe.rb', line 8

def self.fetch(tag,etag=nil)
  location = LOCATIONS[tag]
  return nil unless location
  retval = {}
  etag = (NVD::Feed.etags[tag] || "" ) unless etag
  data = HTTParty.get(location, {:headers => {"If-None-Match" => etag}})
  NVD::Feed.etags[tag] = data.response.header["etag"]
  return NVD::Feed.etags[tag] if data.nil?
  if location.match(/gz$/)
    data = NVD::Feed.gunzip(data)
    if location.match(/\.xml/)
      xml = HTTParty::Parser.new(data, :xml).parse
      data = []
      xml["cpe_list"]["cpe_item"].each do |item|
        item.each do |k,v|
          v = v.detect {|i| i["lang"] == "en-US"} if v.is_a?(Array)
          item[k] = v["__content__"] if v && v["__content__"]
        end
        item.delete "cpe23_item"
        data << item
      end
    end
  end
  retval[name] = data
end

.fetch_allObject



34
35
36
37
38
39
# File 'lib/nvd/feed/cpe.rb', line 34

def self.fetch_all
  retval = {}
  LOCATIONS.each do |name, location|
  end
  retval
end