2016-12-15 11:02:01 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# author: Christoph Hartmann
|
|
|
|
|
|
|
|
require 'json'
|
|
|
|
require 'net/http'
|
|
|
|
|
|
|
|
class LatestInSpecVersion
|
|
|
|
# fetches the latest version from rubygems server
|
|
|
|
def latest
|
|
|
|
uri = URI('https://rubygems.org/api/v1/gems/inspec.json')
|
2017-11-21 07:49:41 +00:00
|
|
|
res = Net::HTTP.start(
|
|
|
|
uri.host, uri.port, use_ssl: uri.scheme == 'https',
|
|
|
|
open_timeout: 0.5, read_timeout: 0.5
|
|
|
|
) { |http|
|
2016-12-15 11:02:01 +00:00
|
|
|
http.get(uri.path)
|
|
|
|
}
|
|
|
|
inspec_info = JSON.parse(res.body)
|
|
|
|
inspec_info['version']
|
2017-11-21 07:49:41 +00:00
|
|
|
rescue StandardError
|
2016-12-15 11:02:01 +00:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|