Module: Octokit::Client::Authorizations

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

Instance Method Summary collapse

Instance Method Details

#authorization(number) ⇒ Authorization

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:

  • (Authorization)

    A single authorization for the authenticated user

See Also:



31
32
33
# File 'lib/octokit/client/authorizations.rb', line 31

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

#authorizationsArray

List a users 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)

    A list of authorizations for the authenticated user

See Also:



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

def authorizations
  get('authorizations')
end

#create_authorization(options = {}) ⇒ Authorization

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. See developer.github.com/v3/oauth/#scopes for available scopes

  • :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:

  • (Authorization)

    A single authorization for the authenticated user

See Also:



51
52
53
54
55
56
# File 'lib/octokit/client/authorizations.rb', line 51

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.
  options = {:scopes => ""}.merge(options)
  post('authorizations', options)
end

#delete_authorization(number) ⇒ Status

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:

  • (Status)

    A raw status response

See Also:



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

def delete_authorization(number)
  delete("authorizations/#{number}", {}, 3, true, true)
end

#update_authorization(number, options = {}) ⇒ Authorization

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.create_authorization({: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:

  • (Authorization)

    A single (updated) authorization for the authenticated user

See Also:



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

def update_authorization(number, 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.
  options = {:scopes => ""}.merge(options)
  patch("authorizations/#{number}", options)
end