Class: Travis::Client::AutoLogin
- Inherits:
-
Object
- Object
- Travis::Client::AutoLogin
- Defined in:
- lib/travis/client/auto_login.rb
Constant Summary collapse
- NoTokenError =
Class.new(RuntimeError)
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
- #authenticate ⇒ Object
- #cli_config ⇒ Object
- #cli_token ⇒ Object
- #github ⇒ Object
-
#initialize(session, options = {}) ⇒ AutoLogin
constructor
A new instance of AutoLogin.
Constructor Details
#initialize(session, options = {}) ⇒ AutoLogin
Returns a new instance of AutoLogin.
11 12 13 14 15 16 17 |
# File 'lib/travis/client/auto_login.rb', line 11 def initialize(session, = {}) @session = session.session config_path = ENV.fetch('TRAVIS_CONFIG_PATH') { File.('.travis', Dir.home) } @config_file = .fetch(:config_file) { File.('config.yml', config_path) } @auto_token = .fetch(:auto_token) { true } @raise = .fetch(:raise) { true } end |
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
9 10 11 |
# File 'lib/travis/client/auto_login.rb', line 9 def session @session end |
Instance Method Details
#authenticate ⇒ Object
19 20 21 22 |
# File 'lib/travis/client/auto_login.rb', line 19 def authenticate return unless session.access_token = cli_token github.with_token { |t| session.github_auth(t) } end |
#cli_config ⇒ Object
40 41 42 |
# File 'lib/travis/client/auto_login.rb', line 40 def cli_config @cli_config ||= YAML.load_file(@config_file) if File.exist? @config_file end |
#cli_token ⇒ Object
33 34 35 36 37 38 |
# File 'lib/travis/client/auto_login.rb', line 33 def cli_token result = cli_config result &&= result['endpoints'] result &&= result[session.uri] result && result['access_token'] end |
#github ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/travis/client/auto_login.rb', line 24 def github @github ||= Tools::Github.new(session.config['github']) do |g| g.explode = true g.manual_login = false g.auto_token = @auto_token g.after_tokens = proc { raise NoTokenError, "no suitable github token found" } if @raise end end |