Class: Octoauth::Auth

Inherits:
Object
  • Object
show all
Defined in:
lib/octoauth/auth.rb

Overview

Authentication object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Auth

Returns a new instance of Auth.



24
25
26
27
28
29
30
31
32
# File 'lib/octoauth/auth.rb', line 24

def initialize(params = {})
  params[:config_note] = "#{params[:note]}"
  if params[:api_endpoint]
    params[:config_note] << "--#{params[:api_endpoint]}"
  end
  @config = ConfigFile.new file: params[:file], note: params[:config_note]
  @token = load_token params
  save if params[:autosave]
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



22
23
24
# File 'lib/octoauth/auth.rb', line 22

def token
  @token
end

Instance Method Details

#saveObject



34
35
36
37
38
39
# File 'lib/octoauth/auth.rb', line 34

def save
  fail 'No token to save' unless @token
  fail 'No file given for config' unless @config.file
  @config.token = @token
  @config.write
end