Module: Octokit::Client::Authorizations

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

Overview

Methods for the Authorizations API

Instance Method Summary collapse

Instance Method Details

#authorization(number, options = {}) ⇒ Sawyer::Resource

Get a single authorization for the authenticated user.

You can only access your own tokens, and only through Basic Authentication.

Examples:

Show authorization for user ctshryock’s Travis auth

client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
client.authorization(999999)

Returns:

  • (Sawyer::Resource)

    A single authorization for the authenticated user

See Also:



35
36
37
# File 'lib/octokit/client/authorizations.rb', line 35

def authorization(number, options = {})
  get "authorizations/#{number}", options
end

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

List the authenticated user’s authorizations

API for users to manage their own tokens. You can only access your own tokens, and only through Basic Authentication.

Examples:

List authorizations for user ctshryock

client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
client.authorizations

Returns:

  • (Array<Sawyer::Resource>)

    A list of authorizations for the authenticated user

See Also:



20
21
22
# File 'lib/octokit/client/authorizations.rb', line 20

def authorizations(options = {})
  paginate 'authorizations', options
end

#create_authorization(options = {}) ⇒ Sawyer::Resource

Create an authorization for the authenticated user.

You can create your own tokens, and only through Basic Authentication.

Examples:

Create a new authorization for user ctshryock’s project Zoidberg

client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
client.create_authorization({:scopes => ["public_repo","gist"], :note => "Why not Zoidberg?", :note_url=> "https://en.wikipedia.org/wiki/Zoidberg"})

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :scopes (Array)

    A list of scopes that this authorization is in.

  • :note (String)

    A note to remind you what the OAuth token is for.

  • :note_url (String)

    A URL to remind you what app the OAuth token is for.

Returns:

  • (Sawyer::Resource)

    A single authorization for the authenticated user

See Also:



55
56
57
58
59
# File 'lib/octokit/client/authorizations.rb', line 55

def create_authorization(options = {})
  # Techincally we can omit scopes as GitHub has a default, however the
  # API will reject us if we send a POST request with an empty body.
  post 'authorizations', options
end

#delete_authorization(number, options = {}) ⇒ Boolean

Delete an authorization for the authenticated user.

You can delete your own tokens, and only through Basic Authentication.

Examples:

Delete an authorization

client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
client.delete_authorization(999999)

Parameters:

  • number (Number)

    An existing Authorization ID

Returns:

  • (Boolean)

    Success

See Also:



95
96
97
# File 'lib/octokit/client/authorizations.rb', line 95

def delete_authorization(number, options = {})
  boolean_from_response :delete, "authorizations/#{number}", options
end

#scopes(token = @access_token) ⇒ Array<String>

Check scopes for a token

Parameters:

  • token (String) (defaults to: @access_token)

    GitHub OAuth token

Returns:

  • (Array<String>)

    OAuth scopes

Raises:

  • (ArgumentError)

See Also:



104
105
106
107
108
109
110
111
112
113
# File 'lib/octokit/client/authorizations.rb', line 104

def scopes(token = @access_token)
  raise ArgumentError.new("Access token required") if token.nil?

  agent.call(:get, "user", :headers => {"Authorization" => "token #{token}" }).
    headers['X-OAuth-Scopes'].
    to_s.
    split(',').
    map(&:strip).
    sort
end

#update_authorization(number, options = {}) ⇒ Sawyer::Resource

Update an authorization for the authenticated user.

You can update your own tokens, but only through Basic Authentication.

Examples:

Update the authorization for user ctshryock’s project Zoidberg

client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
client.update_authorization(999999, {:add_scopes => ["gist", "repo"], :note => "Why not Zoidberg possibly?"})

Parameters:

  • options (Hash) (defaults to: {})

    A customizable set of options.

Options Hash (options):

  • :scopes (Array)

    Replace the authorization scopes with these.

  • :add_scopes (Array)

    A list of scopes to add to this authorization.

  • :remove_scopes (Array)

    A list of scopes to remove from this authorization.

  • :note (String)

    A note to remind you what the OAuth token is for.

  • :note_url (String)

    A URL to remind you what app the OAuth token is for.

Returns:

  • (Sawyer::Resource)

    A single (updated) authorization for the authenticated user

See Also:



79
80
81
# File 'lib/octokit/client/authorizations.rb', line 79

def update_authorization(number, options = {})
  patch "authorizations/#{number}", options
end