Sha256: c352d96a0a27b178cc69145d22b0a73d4879ffd7de6aaf1c0fa6b6bcdb3c7552

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

require "licensed/version"
require "licensed/configuration"
require "licensed/license"
require "licensed/dependency"
require "licensed/source/bundler"
require "licensed/source/bower"
require "licensed/source/manifest"
require "licensed/source/npm"
require "licensed/source/stack"
require "licensed/source/go"
require "licensed/source/cabal"
require "licensed/command/cache"
require "licensed/command/verify"
require "licensed/command/list"
require "licensed/ui/shell"
require "octokit"

module Licensed
  class << self
    attr_accessor :use_github
  end

  self.use_github = true

  GITHUB_URL = %r{\Ahttps://github.com/([a-z0-9]+(-[a-z0-9]+)*/(\w|\.|\-)+)}
  LICENSE_CONTENT_TYPE = "application/vnd.github.drax-preview+json"

  def self.from_github(url)
    return unless use_github && match = GITHUB_URL.match(url)

    license_url = Octokit::Repository.path(match[1]) + "/license"
    response = octokit.get license_url, :accept => LICENSE_CONTENT_TYPE
    content = Base64.decode64(response["content"]).force_encoding('UTF-8')
    Licensee::ProjectFiles::LicenseFile.new(content, response["name"])
  rescue Octokit::NotFound
    nil
  end

  def self.octokit
    @octokit ||=  Octokit::Client.new(:access_token => ENV["GITHUB_TOKEN"])
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
licensed-0.11.1 lib/licensed.rb
licensed-0.11.0 lib/licensed.rb