class SantasTwilioHelper::Cli::Application

Public Instance Methods

add_child(name) click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 71
def add_child(name)
  file = File.read('santarc.json')
  data_hash = JSON.parse(file)
  children = data_hash['children']
  children.push name
  data_hash['children'] = children
  puts data_hash

  write_file(data_hash)
  puts "Added #{name} to children"
end
begin() click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 17
def begin
  say("#{Paint["Hi I'm one of Santa's Twilio Elves, and I'm about to deputize you as an ambassador to Santa. To get started I need your name.", :red]}")
  santa_helper = ask("Parent Name: ")

  children = []
  say("Great Gumdrops. We also need your child's name to verify they are on Santa's list. ")
  child = ask("Child Name: ")
  children.push(child)

  say("Fantastic. You can always add more children by running add_child later.")
  say("Next I need to know your telephone number so Santa's helpers can get in touch with you.")
  telephone = ask("#{Paint['Telephone Number: ', :red]}")

  say("The last thing I need is your city so we can verify we have the correct location for #{child}.")
  zip_code = ask("#{Paint['Zip Code: ', :blue]}")

  data = {
    'santa_helper' => santa_helper,
    'children' => children,
    'telephone' => telephone,
    'zip_code'=> zip_code
  }

  write_file(data)

  say("#{Paint["Okay you're off to the races. You can type `santa help` at any time to see the list of available commands.", "#55C4C2"]}")
end
english_join(array = nil) click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 64
def english_join(array = nil)
  return array.to_s if array.nil? or array.length <= 1
  array[0..-2].join(", ") + " and " + array[-1]
end
ping() click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 84
def ping
  file = File.read('messages.json')
  messages = JSON.parse(file)
  santaMs = messages['SANTA_SNIPPETS']
  a = rand(0..(santaMs.length-1))
  msg = santaMs[a]
  puts "sending message..."
  sendMessage(msg)
end
sendMessage(msg) click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 50
def sendMessage(msg)
  file = File.read('santarc.json')
  data_hash = JSON.parse(file)
  phone = data_hash['telephone']
  children = english_join(data_hash['children'])
  msg = "Hi #{children}. #{msg} - the elves"
  message = @@client.account.messages.create(
    :from => @@twilio_number,
    :to => phone,
    :body => msg
  )
  puts "message sent: #{msg}"
end
telegraph(message) click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 106
def telegraph(message)
  puts "delay: #{options[:delay]}" if options[:delay]
  sleep(options[:delay])
  puts Paint["sending message as SMS...", :red]
  sendMessage(message)
  puts "#{Paint["Santa has approved that communication and we'll forward to the appropriate phone soon. -the elves", :white]}"
end
write_file(data_hash) click to toggle source
# File lib/santas_twilio_helper/cli/application.rb, line 46
def write_file(data_hash)
  create_file "santarc.json", "// Your Santas Helper configuration.\n #{data_hash.to_json}", :force => true
end