:version attr_reader :homepage attr_reader :source def initialize(owner, name, version, source) @version = version @homepage = "https://github.com/#{owner}/#{name}" @source = source end end class SpecLoader def initialize(owner, name, version, token) @owner = owner @name = name @version = version if !token.nil? && !token.empty? @authorizationToken = "Authorization: token #{token}" else @authorizationToken = nil end end def loadPrivateSpec tagResponse = loadTag assetURL = getAssetURL(tagResponse) headers = ["Accept: application/octet-stream"] if
[email protected]? headers.push(@authorizationToken) end source = { :http => assetURL, :headers => headers, :type => "zip" } return PrivateRepository::Spec.new(@owner, @name, @version, source) end private def loadTag requestURL = "https://api.github.com/repos/#{@owner}/#{@name}/releases/tags/#{@version}" cmdElements = ["curl"] if
[email protected]? cmdElements.push("-sL") cmdElements.push("-H \"#{@authorizationToken}\"") else cmdElements.push("-nsL") end cmdElements.push(requestURL) cmd = cmdElements.join(" ") response = %x[#{cmd}] if response.nil? puts "Failed Request: #{requestURL}" exit! else return response end end def getAssetURL(tagResponse) tag_hash = JSON.load(tagResponse) asset = tag_hash["assets"]&.first assetURL = asset && asset["url"] if assetURL.nil? puts "Can't get asset URL." exit! else return assetURL end end end end privateSpecLoader = PrivateRepository::SpecLoader.new("marty-suzuki", "kmm", "0.1.0", ENV["GITHUB_ACCESS_TOKEN"]) privateSpec = privateSpecLoader.loadPrivateSpec spec.name = 'iOSKMM' spec.version = privateSpec.version spec.homepage = privateSpec.homepage spec.authors = 'marty-suzuki' spec.license = 'LICENSE' spec.summary = 'SUMMARY' spec.source = privateSpec.source spec.vendored_frameworks = 'iOSKMM.framework' end