# encoding: utf-8 module Github class Authorizations < API VALID_AUTH_PARAM_NAMES = %w[ scopes add_scopes remove_scopes ].freeze # Creates new OAuth Authorizations API def initialize(options = {}) super(options) end # List authorizations # # = Examples # github = Github.new :basic_auth => 'login:password' # github.oauth.list # github.oauth.list { |auth| ... } # def list(params={}) _check_if_authenticated _normalize_params_keys(params) response = get_request("/authorizations", params) return response unless block_given? response.each { |el| yield el } end alias :all :list # Get a single authorization # # = Examples # github = Github.new :basic_auth => 'login:password' # github.oauth.get 'authorization-id' # def get(authorization_id, params={}) _validate_presence_of(authorization_id) _check_if_authenticated _normalize_params_keys params get_request("/authorizations/#{authorization_id}", params) end alias :find :get # Create a new authorization # # = Inputs # * :scopes - Optional array - A list of scopes that this authorization is in. # = Examples # github = Github.new :basic_auth => 'login:password' # github.oauth.create # "scopes" => ["public_repo"] # def create(params={}) _check_if_authenticated _normalize_params_keys(params) _filter_params_keys(VALID_AUTH_PARAM_NAMES, params) post_request("/authorizations", params) end # Update an existing authorization # # = Inputs # * :scopes - Optional array - A list of scopes that this authorization is in. # * :add_scopes - Optional array - A list of scopes to add to this authorization. # * :remove_scopes - Optional array - A list of scopes to remove from this authorization. # # = Examples # github = Github.new :basic_auth => 'login:password' # github.oauth.update "authorization-id", "add_scopes" => ["repo"], # def update(authorization_id, params={}) _check_if_authenticated _validate_presence_of(authorization_id) _normalize_params_keys(params) _filter_params_keys(VALID_AUTH_PARAM_NAMES, params) patch_request("/authorizations/#{authorization_id}", params) end # Delete an authorization # # = Examples # github.oauth.delete 'authorization-id' # def delete(authorization_id, params={}) _check_if_authenticated _validate_presence_of(authorization_id) _normalize_params_keys(params) _filter_params_keys(VALID_AUTH_PARAM_NAMES, params) delete_request("/authorizations/#{authorization_id}", params) end alias :remove :delete private def _check_if_authenticated raise ArgumentError, 'You can only access authentication tokens through Basic Authentication' unless authenticated? end end # Authorizations end # Github