class NVD::JSONFeeds::FeedURI
Base class for all feed URIs.
Constants
- BASE_URI
- SCHEMA_VERSION
Attributes
ext[R]
The feed file extension.
@return [String]
filename[R]
The file name of the feed.
@return [String]
name[R]
The feed name or year.
@return [:modified, :recent, Integer]
uri[R]
The feed URI.
@return [URI::HTTPS]
Public Class Methods
new(name,ext)
click to toggle source
Initializes the feed URI.
@param [:modified, :recent, Integer] name
The feed name or year.
@param [String] ext
The feed file extension (ex: `.json.gz`).
# File lib/nvd/json_feeds/feed_uri.rb, line 45 def initialize(name,ext) @name = name @ext = ext @filename = "nvdcve-#{SCHEMA_VERSION}-#{@name}#{@ext}" @uri = URI("#{BASE_URI}/#{@filename}") end
Public Instance Methods
download(dest)
click to toggle source
Downloads the feed to the given destination.
@param [String] dest
Either a destination file or directory.
# File lib/nvd/json_feeds/feed_uri.rb, line 86 def download(dest) dest_path = if File.directory?(dest) then File.join(dest,@filename) else dest end File.open(dest_path,'w') do |file| get do |chunk| file.write(chunk) end end return dest_path end
get(&block)
click to toggle source
Performs and HTTP GET request to the feed URI.
@yield [chunk]
If a block is given, it will be passed each chunk read from the response.
@yieldparam [String] chunk
A chunk of data read from the response body.
@return [String]
If no block is given, the full response body will be returned.
# File lib/nvd/json_feeds/feed_uri.rb, line 66 def get(&block) if block Net::HTTP.start(@uri.host,@uri.port, use_ssl: true) do |http| request = Net::HTTP::Get.new(uri) http.request(request) do |response| response.read_body(&block) end end else Net::HTTP.get(@uri) end end
inspect()
click to toggle source
Inspects the feed URI.
@return [String]
# File lib/nvd/json_feeds/feed_uri.rb, line 125 def inspect "#<#{self.class}: #{self}>" end
to_s()
click to toggle source
Converts the feed URI to a String.
@return [String]
The String version of the feed URI.
# File lib/nvd/json_feeds/feed_uri.rb, line 116 def to_s @uri.to_s end
to_uri()
click to toggle source
Converts the feed URI to a regular URI.
@return [URI::HTTPS]
The feed URI.
# File lib/nvd/json_feeds/feed_uri.rb, line 106 def to_uri @uri end