Class: Voicemail::MailboxController

Inherits:
ApplicationController show all
Defined in:
lib/voicemail/mailbox_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#main_menu

Instance Method Details

#authenticateObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/voicemail/mailbox_controller.rb', line 14

def authenticate
  current_tries = 0
  auth_ok = false
  while current_tries < config.mailbox.pin_tries
    input = ask config.mailbox.please_enter_pin, terminator: "#", timeout: config.prompt_timeout
    logger.info input.to_s
    logger.info mailbox[:pin].to_s
    auth_ok = true if input.to_s == mailbox[:pin].to_s
    break if auth_ok
    play config.mailbox.pin_wrong
    current_tries += 1
  end
  auth_ok
end

#play_number_of_messagesObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/voicemail/mailbox_controller.rb', line 29

def play_number_of_messages
  number = storage.count_new_messages(mailbox[:id])
  if number > 0
    play config.mailbox.number_before
    play_numeric number
    play config.mailbox.number_after
  else
    play config.messages.no_new_messages
  end
end

#runObject



3
4
5
6
7
8
9
10
11
12
# File 'lib/voicemail/mailbox_controller.rb', line 3

def run
  if mailbox
    play_greeting
    fail_auth unless authenticate
    play_number_of_messages
    main_menu
  else
    mailbox_not_found
  end
end