Sha256: eb256a228c8233d3b02bf162636297c13dcbbbb50b1ef170be63a84b6f9f8ef3
Contents?: true
Size: 1.52 KB
Versions: 23
Compression:
Stored size: 1.52 KB
Contents
require 'open-uri' require 'json' require 'tins/string_version' module Hackmac class GithubSource GITHUB_API_URL = 'https://api.github.com/repos/%s/releases' include Tins::StringVersion def initialize(github, auth: nil, suffix: nil) @github = github @auth = auth @suffix = (Regexp.quote(suffix) if suffix) account, repo = github.split(?/) @name = repo releases = URI.open( GITHUB_API_URL % github, http_basic_authentication: auth) { |o| JSON.parse(o.read, object_class: JSON::GenericObject) } if max_version = releases.map { |r| next unless r.tag_name.include?(?.) tag = r.tag_name.delete '^.0-9' begin [ Version.new(tag), r ] rescue ArgumentError end }.compact.max_by(&:first) then @version, @release = max_version end end attr_reader :name attr_reader :version attr_reader :github attr_reader :auth def download_asset @release or return asset = @release.assets.find { |a| a.name =~ /#@suffix.*\.(zip|tar\.gz)\z/i } or return data = URI.open( (GITHUB_API_URL % github) + ("/assets/%s" % asset.id), 'Accept' => 'application/octet-stream', http_basic_authentication: auth, &:read ) return asset.name, data end def inspect "#<#{self.class}: #{to_s}>" end def to_s "#{name} #{version}" end def to_s "#{name} #{version}" end end end
Version data entries
23 entries across 23 versions & 1 rubygems