Sha256: ee11bd8c514e311ee1e395f361aa421e0c6328ce203a11830c346cbc1a71dea9

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8

require_relative '../api'

module Github
  class Client::Scopes < API
    # Check what OAuth scopes you have.
    #
    # @see https://developer.github.com/v3/oauth/#scopes
    #
    # @example
    #   github = Github.new oauth_token: 'e72e16c7e42f292c6912e7710c838347ae17'
    #   github.scopes.all
    #
    # @example
    #   github = Github.new
    #   github.scopes.list 'e72e16c7e42f292c6912e7710c838347ae17'
    #
    # @example
    #   github = Github.new
    #   github.scopes.list token: 'e72e16c7e42f292c6912e7710c838347ae17'
    #
    # @api public
    def list(*args)
      arguments(args)
      params = arguments.params
      token = args.shift

      if token.is_a?(Hash) && !params['token'].nil?
        token = params.delete('token')
      elsif token.nil?
        token = oauth_token
      end

      if token.nil?
        raise ArgumentError, 'Access token required'
      end

      headers = { 'Authorization' => "token #{token}" }
      params['headers'] = headers
      response = get_request("/user", params)
      response.headers.oauth_scopes.split(',').map(&:strip)
    end
    alias all list
  end # Client::Scopes
end # Github

Version data entries

6 entries across 6 versions & 3 rubygems

Version Path
github_api2-1.0.1 lib/github_api2/client/scopes.rb
github_api2-1.0.0 lib/github_api2/client/scopes.rb
github_api-0.19.0 lib/github_api/client/scopes.rb
lingfennan-github_api-0.18.2 lib/github_api/client/scopes.rb
github_api-0.18.2 lib/github_api/client/scopes.rb
github_api-0.18.1 lib/github_api/client/scopes.rb