Sha256: dafcd90703413c2ae0dfd0b672ffa437754bdf4e37dbd92a60e673b857418082
Contents?: true
Size: 1.32 KB
Versions: 9
Compression:
Stored size: 1.32 KB
Contents
require "open-uri" class Middleman::HashiCorp::Releases RELEASES_URL = "https://releases.hashicorp.com".freeze class Build < Struct.new(:name, :version, :os, :arch, :url); end def self.fetch(product, version) url = "#{RELEASES_URL}/#{product}/#{version}/index.json" r = JSON.parse(open(url).read, create_additions: false, symbolize_names: true, ) # Convert the builds into the following format: # # { # "os" => { # "arch" => "https://download.url" # } # } # {}.tap do |h| r[:builds].each do |b| build = Build.new(*b.values_at(*Build.members)) h[build.os] ||= {} h[build.os][build.arch] = build.url end end end # # Gets only the most recently released version data for a given product # def self.fetch_latest_version(product) url = "#{RELEASES_URL}/#{product}/index.json" res = JSON.parse(open(url).read, create_additions: false, symbolize_names: true, ) versions = res[:versions] # Releases are formatted as an object rather than an array in the JSON # structure, so we need to convert to an array then sort by version to # get the latest. We then return all info for that version. versions[versions.keys.sort_by(&Gem::Version.method(:new)).last] end end
Version data entries
9 entries across 9 versions & 1 rubygems