Class: LearnConfig::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/learn_config/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(github_username) ⇒ CLI

Returns a new instance of CLI.



6
7
8
# File 'lib/learn_config/cli.rb', line 6

def initialize(github_username)
  @github_username = github_username
end

Instance Attribute Details

#github_usernameObject (readonly)

Returns the value of attribute github_username.



3
4
5
# File 'lib/learn_config/cli.rb', line 3

def github_username
  @github_username
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/learn_config/cli.rb', line 4

def token
  @token
end

Instance Method Details

#ask_for_oauth_token(short_text: false, retries_remaining: 5) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/learn_config/cli.rb', line 10

def ask_for_oauth_token(short_text: false, retries_remaining: 5)
  if !short_text
    puts <<-LONG
To connect with the Learn web application, you will need to configure
the Learn gem with an OAuth token. You can find yours at the bottom of your profile
page at: https://learn.co/#{github_username ? github_username : 'your-github-username'}.

    LONG

    print 'Once you have it, please come back here and paste it in: '
  elsif retries_remaining > 0
    print "Hmm...that token doesn't seem to be correct. Please try again: "
  else
    puts "Sorry, you've tried too many times. Please check your token and try again later."
    exit
  end

  self.token = gets.chomp

  verify_token_or_ask_again!(retries_remaining: retries_remaining)
end