Created
January 20, 2017 16:48
-
-
Save johnholdun/e535dff3c83258c54e87615cb911407c to your computer and use it in GitHub Desktop.
Find the latest browser versions from the caniuse db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
YES!