got it ungzipping gzip stream and the get works
This commit is contained in:
parent
7ba4928770
commit
c3755a71d3
1 changed files with 13 additions and 2 deletions
|
@ -1,4 +1,6 @@
|
|||
require 'rest-client'
|
||||
require 'zlib'
|
||||
require 'json'
|
||||
|
||||
class NvdDownloader
|
||||
attr_accessor :base_url, :years
|
||||
|
@ -22,9 +24,18 @@ class NvdDownloader
|
|||
years[year]
|
||||
end
|
||||
|
||||
|
||||
def get(url)
|
||||
|
||||
r = RestClient.get "#{base_url}#{url}"
|
||||
r.body if r.code == 200
|
||||
end
|
||||
|
||||
def read_gzip_stream(gzip_stream)
|
||||
io_stream = StringIO.new(gzip_stream)
|
||||
gz = Zlib::GzipReader.new(io_stream)
|
||||
gz.read
|
||||
end
|
||||
|
||||
def parse_json(json_string)
|
||||
JSON.parse(json_string)
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue