Class: AiNotoCLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ai_noto_cli.rb

Overview

Command line suite

Available commands: init new

Constant Summary collapse

CONFIG_FILE =
File.join(Dir.home, ".ai_noto.rc.yml")

Instance Method Summary collapse

Instance Method Details

#initObject



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

def init
  options = {
    "from_number" => "+18001234567",
    "to_number" => "+18001234567",
    "twilio_account_sid" => "enter your account sid",
    "twilio_auth_token" => "enter your auth token",
    "default_recipient" => "+18001234567",
    "John" => "+18001112222",
  }

  if !File.exists? CONFIG_FILE
    File.open(CONFIG_FILE, 'w') { |file| YAML::dump(options, file) }
    STDOUT.puts "Initialized default configuration file in #{CONFIG_FILE}"
    STDOUT.puts "Please ensure it properly configured"
  else
    STDOUT.puts "Configuration file already exists in #{CONFIG_FILE}"
  end
end

#new(recipient = nil, message) ⇒ Object

Raises:

  • (RuntimeError)


32
33
34
35
36
37
# File 'lib/ai_noto_cli.rb', line 32

def new(recipient=nil, message)
  raise RuntimeError, "No configuration found, please run ainoto init" if !File.exists? CONFIG_FILE

  puts "Sending a message to #{AiNoto.to_number(recipient)}"
  AiNoto.send(recipient, message)
end