Skip to content

Instantly share code, notes, and snippets.

@johnholdun
Created January 20, 2017 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnholdun/e535dff3c83258c54e87615cb911407c to your computer and use it in GitHub Desktop.
Save johnholdun/e535dff3c83258c54e87615cb911407c to your computer and use it in GitHub Desktop.
Find the latest browser versions from the caniuse db
require 'json'
require 'net/https'
require 'uri'
def latest_browser_versions
uri = URI.parse('https://cdn.rawgit.com/Fyrd/caniuse/master/data.json')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
response.body
if response.code != '200'
return
end
agents = JSON.load(response.body)['agents']
agents.map do |key, agent|
versions = agent['versions'].select { |_| _ }
{
key: key,
name: agent['browser'],
versions: versions,
latest: versions.last
}
end
end
puts JSON.pretty_generate(latest_browser_versions)
@lovisaNamely
Copy link

YES!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment