Module: Termtter::ConfigSetup

Defined in:
lib/termtter/config_setup.rb

Class Method Summary collapse

Class Method Details

.reauthObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/termtter/config_setup.rb', line 36

def reauth
  token_and_secret = Termtter::API.authorize_by_oauth
  token = token_and_secret[:token]
  secret = token_and_secret[:secret]

  File.open(Termtter::CONF_FILE, 'a+') do |file|
    file << "\nconfig.dmsg_permission = true\n"
  end

  puts "Setup is completed. Enjoy!"
rescue OAuth::Unauthorized
  puts 'Failed to authenticate!'
  exit!
end

.runObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/termtter/config_setup.rb', line 9

def run

  plugins = Dir.glob(File.expand_path(File.dirname(__FILE__) + "/../plugins/*.rb")).map  {|f|
    f.match(%r|lib/plugins/(.*?).rb$|)[1]
  }
  standard_plugins = %w[stdout standard_commands auto_reload defaults]

  template = open(File.dirname(__FILE__) + '/config_template.erb').read
  config = ERB.new(template, nil, '-').result(binding) # trim_mode => '-'

  Dir.mkdir(Termtter::CONF_DIR) unless File.exists?(Termtter::CONF_DIR)
  File.open(Termtter::CONF_FILE, 'w', 0600) {|io|
    io << config
  }

  puts "generated: ~/.termtter/config"

  token_and_secret = Termtter::API.authorize_by_oauth
  token = token_and_secret[:token]
  secret = token_and_secret[:secret]

  puts "Setup is completed. Enjoy!"
rescue OAuth::Unauthorized
  puts 'Failed to authenticate!'
  exit!
end