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-03-06 16:23:42 +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']
|
|
|
|
rescue Exception # rubocop:disable Lint/RescueException
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|