Skip to content

Commit

Permalink
Allow per-mailbox override options for #record calls
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinAiken committed Oct 24, 2013
1 parent 97d8a67 commit 9441d14
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#v1.0.0..
* FEATURE - Optional per-mailbox override of default recording hash
* FEATURE - Optional rerecording of voicemail messages
* FEATURE - I18n numeric methods
* FEATURE - I18n support for keys
Expand Down
8 changes: 8 additions & 0 deletions lib/voicemail/call_controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ def fetch_mailbox
storage.get_mailbox mailbox_id
end

def record_options
if config.use_mailbox_opts_for_recording
config.recording.to_hash.merge mailbox[:record_options]
else
config.recording.to_hash
end
end

def mailbox_not_found
play config.mailbox_not_found
hangup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def listen_to_current_greeting

def record_greeting
play config.set_greeting.before_record
record_comp = record config.set_greeting.recording.to_hash
record_comp = record record_options
@temp_recording = record_comp.complete_event.recording.uri
play_audio @temp_recording

Expand Down
2 changes: 1 addition & 1 deletion lib/voicemail/call_controllers/voicemail_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def play_greeting
end

def record_message
@recording = record config.recording.to_hash
@recording = record record_options

config.allow_rerecording ? recording_menu : save_recording
end
Expand Down
7 changes: 2 additions & 5 deletions lib/voicemail/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Plugin < Adhearsion::Plugin
allow_rerecording true, desc: "Allow caller to rerecord their voicemail"
after_record "Press 1 to save your voicemail. Press 2 to rerecord.", desc: "Message to play if allow_rerecording is set"

desc "Voicemail recording options"
desc "Default recording options"
recording {
interruptible true, desc: "Whether you can stop the recording with a DTMF input"
direction :send, desc: "The direction to record; you probably want :send"
Expand All @@ -38,6 +38,7 @@ class Plugin < Adhearsion::Plugin
start_beep true, desc: "Play a beep before recording"
stop_beep false, desc: "Play a beep after recording"
}
use_mailbox_opts_for_recording false, desc: "Whether per-mailbox settings can override defaults"

desc "Configuration for registered users"
mailbox {
Expand All @@ -61,10 +62,6 @@ class Plugin < Adhearsion::Plugin
before_record "Please speak after the beep. The prompt will be played back after.", desc: "Recording instructions"
after_record "Press 1 to save your new greeting, 2 to discard it, 9 to go back to the menu", desc: "Menu to use after recording"
no_personal_greeting "You do not currently have a personalized greeting.", desc: "What to play if there is no specific greeting"
recording {
max_duration 5_000, desc: "Maximum duration for recording in milliseconds"
start_beep true, desc: "Play a beep before recording"
}
}

desc "Set PIN configuration"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,33 @@
let(:recording_component) { flexmock 'Record' }
let(:file_path) { "/path/to/file" }

it "plays the appropriate sounds, records, plays back recording, and calls the recording menu" do
before do
should_play config.set_greeting.before_record
recording_component.should_receive("complete_event.recording.uri").and_return(file_path)
subject.should_receive(:record).once.with(config.set_greeting.recording.to_hash).and_return recording_component
recording_component.should_receive("complete_event.recording.uri").and_return file_path
subject.should_receive(:play_audio).with file_path
subject.should_receive(:menu).once.with(config.set_greeting.after_record,
{ timeout: config.menu_timeout,
tries: config.menu_tries }, Proc)
subject.should_receive(:menu).once.with config.set_greeting.after_record, {timeout: config.menu_timeout, tries: config.menu_tries}, Proc
end

after do
controller.record_greeting
config.use_mailbox_opts_for_recording = false
end

context "without mailbox settings" do
it "plays the appropriate sounds, records, plays back recording, and calls the recording menu" do
subject.should_receive(:record).once.with(config.recording.to_hash).and_return recording_component
end
end

context "with mailbox settings" do
let(:mailbox) { {id: 100, record_options: {final_timeout: 31}} }

before { config.use_mailbox_opts_for_recording = true }

it "records using the mailbox's record options" do
expected_options = {direction: :send, final_timeout: 31, interruptible: true, max_duration: 30, start_beep: true, stop_beep: false}
subject.should_receive(:record).once.with(expected_options).and_return recording_component
end
end
end

Expand Down

0 comments on commit 9441d14

Please sign in to comment.