Class: NVD::JSONFeeds::FeedURI
- Inherits:
-
Object
- Object
- NVD::JSONFeeds::FeedURI
- Defined in:
- lib/nvd/json_feeds/feed_uri.rb
Overview
Base class for all feed URIs.
Direct Known Subclasses
Constant Summary collapse
- SCHEMA_VERSION =
'1.1'
- BASE_URI =
"https://nvd.nist.gov/feeds/json/cve/#{SCHEMA_VERSION}"
Instance Attribute Summary collapse
-
#ext ⇒ String
readonly
The feed file extension.
-
#filename ⇒ String
readonly
The file name of the feed.
-
#name ⇒ :modified, ...
readonly
The feed name or year.
-
#uri ⇒ URI::HTTPS
readonly
The feed URI.
Instance Method Summary collapse
-
#download(dest) ⇒ Object
Downloads the feed to the given destination.
-
#get {|chunk| ... } ⇒ String
Performs and HTTP GET request to the feed URI.
-
#initialize(name, ext) ⇒ FeedURI
constructor
Initializes the feed URI.
-
#inspect ⇒ String
Inspects the feed URI.
-
#to_s ⇒ String
Converts the feed URI to a String.
-
#to_uri ⇒ URI::HTTPS
Converts the feed URI to a regular URI.
Constructor Details
#initialize(name, ext) ⇒ FeedURI
Initializes the feed URI.
45 46 47 48 49 50 51 |
# 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 |
Instance Attribute Details
#ext ⇒ String (readonly)
The feed file extension.
24 25 26 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 24 def ext @ext end |
#filename ⇒ String (readonly)
The file name of the feed.
29 30 31 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 29 def filename @filename end |
#name ⇒ :modified, ... (readonly)
The feed name or year.
19 20 21 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 19 def name @name end |
#uri ⇒ URI::HTTPS (readonly)
The feed URI.
34 35 36 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 34 def uri @uri end |
Instance Method Details
#download(dest) ⇒ Object
Downloads the feed to the given destination.
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# 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 {|chunk| ... } ⇒ String
Performs and HTTP GET request to the feed URI.
66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ String
Inspects the feed URI.
125 126 127 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 125 def inspect "#<#{self.class}: #{self}>" end |
#to_s ⇒ String
Converts the feed URI to a String.
116 117 118 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 116 def to_s @uri.to_s end |
#to_uri ⇒ URI::HTTPS
Converts the feed URI to a regular URI.
106 107 108 |
# File 'lib/nvd/json_feeds/feed_uri.rb', line 106 def to_uri @uri end |