class Troo::CLI::Wizard

Public Instance Methods

start() click to toggle source
# File lib/troo/cli/wizard.rb, line 9
def start
  say Troo::Formatter.wordwrap(welcome_message)

  step_zero!

  say Troo::Formatter.wordwrap(step_one_message)
  step_one!

  say Troo::Formatter.wordwrap(step_two_message)

  proceed?
  step_two!

  say 'All done! Run `troo` for further commands.'
end

Private Instance Methods

config() click to toggle source
# File lib/troo/cli/wizard.rb, line 36
def config
  @config ||= Troo::Configuration.new
end
connect_url(api_key) click to toggle source
# File lib/troo/cli/wizard.rb, line 27
def connect_url(api_key)
  "https://trello.com/1/connect?key=#{api_key}" \
  "&name=troo&response_type=token&scope=read,write"
end
copy_configuration() click to toggle source
# File lib/troo/cli/wizard.rb, line 89
def copy_configuration
  FileUtils.cp(source, destination)
end
destination() click to toggle source
# File lib/troo/cli/wizard.rb, line 97
def destination
  Dir.home + '/.trooconf'
end
destination_exists?() click to toggle source
# File lib/troo/cli/wizard.rb, line 93
def destination_exists?
  File.exist?(destination)
end
generate_url() click to toggle source
# File lib/troo/cli/wizard.rb, line 32
def generate_url
  'https://trello.com/1/appKey/generate'
end
proceed?() click to toggle source
# File lib/troo/cli/wizard.rb, line 40
def proceed?
  raise ConfigurationAborted unless yes?(user_input('Proceed?'))
end
source() click to toggle source
# File lib/troo/cli/wizard.rb, line 101
def source
  File.dirname(__FILE__) + '/../../../config/trooconf.yml'
end
step_one!() click to toggle source
# File lib/troo/cli/wizard.rb, line 56
def step_one!
  Launchy.open(generate_url)
  config.api_key   = ask(user_input('Key:'))
  config.api_token = ask(user_input('Secret:'))
end
step_one_message() click to toggle source
# File lib/troo/cli/wizard.rb, line 74
def step_one_message
  "First, you'll need to sign in " \
  "to Trello in the normal way. Copy the API key and paste "   \
  "when prompted, then do the same for the secret.\n"
end
step_two!() click to toggle source
# File lib/troo/cli/wizard.rb, line 62
def step_two!
  Launchy.open(connect_url(config.api_key))
  config.api_oauth_token = ask(user_input('Token:'))
  config.save(Dir.home + '/.trooconf', 'default')
end
step_two_message() click to toggle source
# File lib/troo/cli/wizard.rb, line 80
def step_two_message
  "Thank you. You must now allow this application to use "     \
  "Trello account. Copy and paste the token when prompted.\n"
end
step_zero!() click to toggle source
# File lib/troo/cli/wizard.rb, line 44
def step_zero!
  if destination_exists?
    say "A configuration file already exists.\n"

    raise ConfigurationAborted unless yes?(user_input('Overwrite?'))
  end

  copy_configuration

  say "A configuration file was created.\n"
end
user_input(value) click to toggle source
# File lib/troo/cli/wizard.rb, line 85
def user_input(value)
  [Esc.yellow, value, Esc.reset].join
end
welcome_message() click to toggle source
# File lib/troo/cli/wizard.rb, line 68
def welcome_message
  "Welcome to Troo. This wizard will create a configuration file " \
  "in your home directory and help you configure your API credentials " \
  "for Trello.\n\n"
end