Sha256: 8a2e69bf127851beff76be058d4b754bf088f1188551160076f6884b7e70677c

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

module Octokit
  class Client

    # Methods for licenses API
    #
    module Licenses

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

      # List all licenses
      #
      # @see https://developer.github.com/v3/licenses/#list-all-licenses
      # @return [Array<Sawyer::Resource>] A list of licenses
      # @example
      #   Octokit.licenses
      def licenses(options = {})
        options = ensure_license_api_media_type(options)
        paginate "licenses", options
      end

      # List an individual license
      #
      # @see https://developer.github.com/v3/licenses/#get-an-individual-license
      # @param license_name [String] The license name
      # @return <Sawyer::Resource> An individual license
      # @example
      #   Octokit.license 'mit'
      def license(license_name, options = {})
        options = ensure_license_api_media_type(options)
        get "licenses/#{license_name}", options
      end

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

      def warn_license_preview
        warn <<-EOS
WARNING: The preview version of the License API is not yet suitable for production use.
You can avoid this message by supplying an appropriate media type in the 'Accept' request
header. 
EOS
      end  
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
octokit-4.0.1 lib/octokit/client/licenses.rb
octokit-4.0.0 lib/octokit/client/licenses.rb