inspec/lib/utils/latest_version.rb
Miah Johnson 659b4b373a Remove # encoding: utf8 magic comments
Signed-off-by: Miah Johnson <miah@chia-pet.org>
2019-05-07 16:06:23 -07:00

21 lines
499 B
Ruby

# 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')
res = Net::HTTP.start(
uri.host, uri.port, use_ssl: uri.scheme == 'https',
open_timeout: 0.5, read_timeout: 0.5
) { |http|
http.get(uri.path)
}
inspec_info = JSON.parse(res.body)
inspec_info['version']
rescue StandardError
nil
end
end