Class: Betavites::Commands

Inherits:
Object
  • Object
show all
Defined in:
lib/betavites/commands.rb

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



5
6
7
8
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
35
36
37
38
39
40
41
# File 'lib/betavites/commands.rb', line 5

def run(args)

  if args[0] == "install" and api_key = args[1]

    config = "# Leave api-key blank to disable Betavites.\n\ndevelopment:\n  api-key: \#{api_key}\n\nproduction:\n  api-key: \#{api_key}\n"

    Dir.mkdir("config") unless File.exists?("config")
    File.open(CONFIG_PATH, "w") {|f| f.write(config) }

    puts "Created config file at #{CONFIG_PATH}"
  elsif args[0] == "test"
    begin
      Betavites::Config.load(CONFIG_PATH)
      code, message = Betavites.add_user(:email => "[email protected]")
      raise message if code != 0
      puts "Test successful! Login to http://www.betavites.com to see it."
    rescue Exception => e
      puts "Test failed:\n  #{e.message}"
    end
  else
    help ="Usage:\n  betavites install <api-key>\n  betavites test\n"
    puts help
  end

end