Module: Octokit::Client::Licenses

Included in:
Octokit::Client
Defined in:
lib/octokit/client/licenses.rb

Overview

Methods for licenses API

Constant Summary collapse

LICENSES_PREVIEW_MEDIA_TYPE =
"application/vnd.github.drax-preview+json".freeze

Instance Method Summary collapse

Instance Method Details

#ensure_license_api_media_type(options = {}) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/octokit/client/licenses.rb', line 33

def ensure_license_api_media_type(options = {})
  if options[:accept].nil?
    options[:accept] = LICENSES_PREVIEW_MEDIA_TYPE
    warn_license_preview
  end
  options
end

#license(license_name, options = {}) ⇒ Sawyer::Resource

List an individual license

Examples:

Octokit.license 'mit'

Parameters:

  • license_name (String)

    The license name

Returns:

  • (Sawyer::Resource)

    An individual license

See Also:



28
29
30
31
# File 'lib/octokit/client/licenses.rb', line 28

def license(license_name, options = {})
  options = ensure_license_api_media_type(options)
  get "licenses/#{license_name}", options
end

#licenses(options = {}) ⇒ Array<Sawyer::Resource>

List all licenses

Examples:

Octokit.licenses

Returns:

  • (Array<Sawyer::Resource>)

    A list of licenses

See Also:



16
17
18
19
# File 'lib/octokit/client/licenses.rb', line 16

def licenses(options = {})
  options = ensure_license_api_media_type(options)
  paginate "licenses", options
end

#warn_license_previewObject



41
42
43
44
45
46
47
# File 'lib/octokit/client/licenses.rb', line 41

def warn_license_preview
  warn "WARNING: The preview version of the License API is not yet suitable for production use.\nYou can avoid this message by supplying an appropriate media type in the 'Accept' request\nheader. \n"
end