voicemail 0.2.0 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +44 -0
  3. data/README.md +57 -2
  4. data/lib/voicemail.rb +15 -8
  5. data/lib/voicemail/{application_controller.rb → call_controllers/application_controller.rb} +14 -1
  6. data/lib/voicemail/call_controllers/authentication_controller.rb +60 -0
  7. data/lib/voicemail/call_controllers/mailbox_controller.rb +46 -0
  8. data/lib/voicemail/{mailbox_main_menu_controller.rb → call_controllers/mailbox_main_menu_controller.rb} +9 -4
  9. data/lib/voicemail/call_controllers/mailbox_messages_controller.rb +48 -0
  10. data/lib/voicemail/{mailbox_play_message_controller.rb → call_controllers/mailbox_play_message_controller.rb} +26 -10
  11. data/lib/voicemail/call_controllers/mailbox_play_message_intro_controller.rb +72 -0
  12. data/lib/voicemail/{mailbox_set_greeting_controller.rb → call_controllers/mailbox_set_greeting_controller.rb} +2 -2
  13. data/lib/voicemail/{mailbox_set_pin_controller.rb → call_controllers/mailbox_set_pin_controller.rb} +0 -0
  14. data/lib/voicemail/call_controllers/voicemail_controller.rb +57 -0
  15. data/lib/voicemail/localization_loader.rb +28 -0
  16. data/lib/voicemail/matcher.rb +14 -0
  17. data/lib/voicemail/plugin.rb +40 -15
  18. data/lib/voicemail/storage_pstore.rb +49 -2
  19. data/lib/voicemail/version.rb +1 -1
  20. data/spec/voicemail/call_controllers/application_controller_spec.rb +31 -0
  21. data/spec/voicemail/call_controllers/authentication_controller_spec.rb +59 -0
  22. data/spec/voicemail/call_controllers/mailbox_controller_spec.rb +107 -0
  23. data/spec/voicemail/{mailbox_main_menu_controller_spec.rb → call_controllers/mailbox_main_menu_controller_spec.rb} +9 -2
  24. data/spec/voicemail/call_controllers/mailbox_messages_controller_spec.rb +110 -0
  25. data/spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb +97 -0
  26. data/spec/voicemail/call_controllers/mailbox_play_message_intro_controller_spec.rb +81 -0
  27. data/spec/voicemail/{mailbox_set_greeting_controller_spec.rb → call_controllers/mailbox_set_greeting_controller_spec.rb} +24 -6
  28. data/spec/voicemail/{mailbox_set_pin_controller_spec.rb → call_controllers/mailbox_set_pin_controller_spec.rb} +0 -0
  29. data/spec/voicemail/call_controllers/voicemail_controller_spec.rb +97 -0
  30. data/spec/voicemail/localization_loader_spec.rb +21 -0
  31. data/spec/voicemail/storage_pstore_spec.rb +64 -2
  32. data/templates/en.yml +67 -0
  33. data/voicemail.gemspec +2 -2
  34. metadata +42 -26
  35. data/lib/voicemail/mailbox_controller.rb +0 -56
  36. data/lib/voicemail/mailbox_messages_controller.rb +0 -55
  37. data/lib/voicemail/voicemail_controller.rb +0 -33
  38. data/spec/voicemail/mailbox_controller_spec.rb +0 -79
  39. data/spec/voicemail/mailbox_messages_controller_spec.rb +0 -71
  40. data/spec/voicemail/mailbox_play_message_controller_spec.rb +0 -70
  41. data/spec/voicemail/voicemail_controller_spec.rb +0 -76
@@ -0,0 +1,21 @@
1
+ require "spec_helper"
2
+
3
+ describe Voicemail::LocalizationLoader do
4
+
5
+ before { @old_config = Voicemail::Plugin.config.default_greeting }
6
+ after { Voicemail::Plugin.config.default_greeting = @old_config }
7
+
8
+ describe ".replace_config" do
9
+ let(:mock_hash) { {'en' => {'voicemail' => {'default_greeting' => 'foo'}}} }
10
+
11
+ before do
12
+ flexmock(YAML).should_receive(:load).and_return mock_hash
13
+ flexmock(I18n).should_receive(:t).and_return "bar"
14
+ end
15
+
16
+ it "changes the values to i18n" do
17
+ subject.replace_config
18
+ Voicemail::Plugin.config.default_greeting.should == "bar"
19
+ end
20
+ end
21
+ end
@@ -14,14 +14,20 @@ module Voicemail
14
14
 
15
15
  let(:config) { Voicemail::Plugin.config }
16
16
 
17
+ let(:message_1) { {id: :foo} }
18
+ let(:message_2) { {id: :bar} }
19
+ let(:message_3) { {id: :biz} }
20
+
17
21
  subject :storage do
18
22
  basedir = File.expand_path("../../../tmp/", __FILE__)
19
23
  pstore_path = File.join(basedir, 'voicemail.pstore')
20
24
  File.unlink(pstore_path) if File.exists?(pstore_path)
21
25
  config.storage.pstore_location = pstore_path
22
26
  StoragePstore.new.tap do |storage|
23
- storage.store.transaction do
24
- storage.store[:mailboxes][100] = mailbox
27
+ storage.store.transaction do |store|
28
+ store[:recordings][100] = [message_1]
29
+ store[:archived][100] = [message_2, message_3]
30
+ store[:mailboxes][100] = mailbox
25
31
  end
26
32
  flexmock storage
27
33
  end
@@ -41,5 +47,61 @@ module Voicemail
41
47
  end
42
48
  end
43
49
 
50
+ describe "#save_recording" do
51
+ let(:recording_object) { flexmock 'recording_object', uri: "file://somewav.wav" }
52
+
53
+ it "saves the recording" do
54
+ storage.save_recording(100, "foo", recording_object)
55
+ storage.store.transaction do |store|
56
+ store[:recordings][100].last[:uri].should == "file://somewav.wav"
57
+ store[:recordings][100].last[:from].should == "foo"
58
+ store[:recordings][100].last[:id].should_not be_nil
59
+ end
60
+ end
61
+ end
62
+
63
+ describe "#count_new_messages" do
64
+ it "returns the new message count" do
65
+ storage.count_new_messages(100).should == 1
66
+ end
67
+ end
68
+
69
+ describe "#count_saved_messages" do
70
+ it "returns the saved message count" do
71
+ storage.count_saved_messages(100).should == 2
72
+ end
73
+ end
74
+
75
+ describe "#next_new_message" do
76
+ it "returns the next new messaged" do
77
+ storage.next_new_message(100).should == {id: :foo}
78
+ end
79
+ end
80
+
81
+ describe "#next_saved_message" do
82
+ it "returns the next saved messaged" do
83
+ storage.next_saved_message(100).should == {id: :bar}
84
+ end
85
+ end
86
+
87
+ describe "#archive_message" do
88
+ it "archives the message" do
89
+ storage.archive_message 100, :foo
90
+ storage.store.transaction do |store|
91
+ store[:recordings][100].should == []
92
+ store[:archived][100].should == [message_2, message_3, message_1]
93
+ end
94
+ end
95
+ end
96
+
97
+ describe "#unarchive_message" do
98
+ it "unarchives the message" do
99
+ storage.unarchive_message 100, :bar
100
+ storage.store.transaction do |store|
101
+ store[:recordings][100].should == [message_1, message_2]
102
+ store[:archived][100].should == [message_3]
103
+ end
104
+ end
105
+ end
44
106
  end
45
107
  end
@@ -0,0 +1,67 @@
1
+ en:
2
+ time:
3
+ am: am
4
+ pm: pm
5
+ formats:
6
+ default: '%A, %B %d at %-l:%M %p'
7
+ numbers:
8
+ '1': "one "
9
+ '2': "two "
10
+ '3': "three "
11
+ '4': "four "
12
+ '5': "five "
13
+ '6': "six "
14
+ '7': "seven "
15
+ '8': "eight "
16
+ '9': "nine "
17
+ '0': "zero "
18
+
19
+ voicemail:
20
+ default_greeting: "You have reached voicemail"
21
+ mailbox_not_found: "Mailbox not found"
22
+
23
+ mailbox:
24
+ greeting_message: "Welcome to the mailbox system."
25
+ please_enter_pin: "Please enter your PIN."
26
+ pin_wrong: "The PIN you entered does not match. Please try again."
27
+ could_not_auth: "We are sorry, the system could not authenticate you"
28
+ number_before: "You have "
29
+ number_after: " new messages"
30
+ number_after_saved: " saved messages"
31
+ x_new_messages:
32
+ one: "You have one new message. "
33
+ other: "You have %{count} new messages. "
34
+ x_saved_messages:
35
+ one: "You have one saved message. "
36
+ other: "You have %{count} saved messages. "
37
+ menu_greeting: "Press 1 to listen to new messages, 2 to change your greeting, 3 to change your PIN"
38
+ menu_timeout_message: "Please enter a digit for the menu"
39
+ menu_invalid_message: "Please enter valid input"
40
+ menu_failure_message: "Sorry, unable to understand your input."
41
+
42
+ after_record: "Press 1 to save your voicemail. Press 2 to rerecord."
43
+
44
+ set_greeting:
45
+ prompt: "Press 1 to listen to your current greeting, 2 to record a new greeting, 9 to return to the main menu"
46
+ before_record: "Please speak after the beep. The prompt will be played back after."
47
+ after_record: "Press 1 to save your new greeting, 2 to discard it, 9 to go back to the menu"
48
+ no_personal_greeting: "You do not currently have a personalized greeting."
49
+
50
+ set_pin:
51
+ menu: "Press 1 to change your current PIN, or 9 to go back to the main menu"
52
+ prompt: "Enter your new PIN of at least four digits followed by the pound sign"
53
+ repeat_prompt: "Please enter your new PIN again, followed by the pound sign"
54
+ pin_error: "Please enter at least four digits followed by the pound sign."
55
+ match_error: "The two entered PINs don't match, please try again."
56
+ change_ok: "Your PIN has been successfully changed"
57
+
58
+ messages:
59
+ menu_new: "Press 1 to archive the message and go to the next, press 5 to delete the message and go to the next, press 7 to hear the message again, press 9 for the main menu"
60
+ menu_saved: "Press 1 to unarchive the message and go to the next, press 5 to delete the message and go to the next, press 7 to hear the message again, press 9 for the main menu"
61
+ no_new_messages: "There are no new messages"
62
+ no_saved_messages: "There are no saved messages"
63
+ message_received_on: "Message received on "
64
+ from: " from "
65
+ message_received_on_x: "Message received on %{received_on}. "
66
+ message_received_from_x: "Message received from %{from}. "
67
+
@@ -5,8 +5,8 @@ require "voicemail/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "voicemail"
7
7
  s.version = Voicemail::VERSION
8
- s.authors = ["Luca Pradovera"]
9
- s.email = ["lpradovera@mojolingo.com"]
8
+ s.authors = ["Luca Pradovera", "Justin Aiken"]
9
+ s.email = ["lpradovera@mojolingo.com", "jaiken@mojolingo.com"]
10
10
  s.license = 'MIT'
11
11
  s.homepage = "http://github.com/adhearsion/voicemail"
12
12
  s.summary = %q{Voicemail for Adhearsion}
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: voicemail
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Pradovera
8
+ - Justin Aiken
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-08-30 00:00:00.000000000 Z
12
+ date: 2013-10-24 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: adhearsion
@@ -111,41 +112,52 @@ dependencies:
111
112
  description: A simple, extensible voicemail implementation
112
113
  email:
113
114
  - lpradovera@mojolingo.com
115
+ - jaiken@mojolingo.com
114
116
  executables: []
115
117
  extensions: []
116
118
  extra_rdoc_files: []
117
119
  files:
118
120
  - .gitignore
119
121
  - .rspec
122
+ - CHANGELOG.md
120
123
  - Gemfile
121
124
  - Guardfile
122
125
  - LICENSE
123
126
  - README.md
124
127
  - Rakefile
125
128
  - lib/voicemail.rb
126
- - lib/voicemail/application_controller.rb
127
- - lib/voicemail/mailbox_controller.rb
128
- - lib/voicemail/mailbox_main_menu_controller.rb
129
- - lib/voicemail/mailbox_messages_controller.rb
130
- - lib/voicemail/mailbox_play_message_controller.rb
131
- - lib/voicemail/mailbox_set_greeting_controller.rb
132
- - lib/voicemail/mailbox_set_pin_controller.rb
129
+ - lib/voicemail/call_controllers/application_controller.rb
130
+ - lib/voicemail/call_controllers/authentication_controller.rb
131
+ - lib/voicemail/call_controllers/mailbox_controller.rb
132
+ - lib/voicemail/call_controllers/mailbox_main_menu_controller.rb
133
+ - lib/voicemail/call_controllers/mailbox_messages_controller.rb
134
+ - lib/voicemail/call_controllers/mailbox_play_message_controller.rb
135
+ - lib/voicemail/call_controllers/mailbox_play_message_intro_controller.rb
136
+ - lib/voicemail/call_controllers/mailbox_set_greeting_controller.rb
137
+ - lib/voicemail/call_controllers/mailbox_set_pin_controller.rb
138
+ - lib/voicemail/call_controllers/voicemail_controller.rb
139
+ - lib/voicemail/localization_loader.rb
140
+ - lib/voicemail/matcher.rb
133
141
  - lib/voicemail/plugin.rb
134
142
  - lib/voicemail/storage.rb
135
143
  - lib/voicemail/storage_pstore.rb
136
144
  - lib/voicemail/version.rb
137
- - lib/voicemail/voicemail_controller.rb
138
145
  - spec/spec_helper.rb
139
146
  - spec/support/voicemail_controller_spec_helper.rb
140
- - spec/voicemail/mailbox_controller_spec.rb
141
- - spec/voicemail/mailbox_main_menu_controller_spec.rb
142
- - spec/voicemail/mailbox_messages_controller_spec.rb
143
- - spec/voicemail/mailbox_play_message_controller_spec.rb
144
- - spec/voicemail/mailbox_set_greeting_controller_spec.rb
145
- - spec/voicemail/mailbox_set_pin_controller_spec.rb
147
+ - spec/voicemail/call_controllers/application_controller_spec.rb
148
+ - spec/voicemail/call_controllers/authentication_controller_spec.rb
149
+ - spec/voicemail/call_controllers/mailbox_controller_spec.rb
150
+ - spec/voicemail/call_controllers/mailbox_main_menu_controller_spec.rb
151
+ - spec/voicemail/call_controllers/mailbox_messages_controller_spec.rb
152
+ - spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb
153
+ - spec/voicemail/call_controllers/mailbox_play_message_intro_controller_spec.rb
154
+ - spec/voicemail/call_controllers/mailbox_set_greeting_controller_spec.rb
155
+ - spec/voicemail/call_controllers/mailbox_set_pin_controller_spec.rb
156
+ - spec/voicemail/call_controllers/voicemail_controller_spec.rb
157
+ - spec/voicemail/localization_loader_spec.rb
146
158
  - spec/voicemail/storage_pstore_spec.rb
147
159
  - spec/voicemail/storage_spec.rb
148
- - spec/voicemail/voicemail_controller_spec.rb
160
+ - templates/en.yml
149
161
  - tmp/.gitignore
150
162
  - voicemail.gemspec
151
163
  homepage: http://github.com/adhearsion/voicemail
@@ -163,9 +175,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
163
175
  version: '0'
164
176
  required_rubygems_version: !ruby/object:Gem::Requirement
165
177
  requirements:
166
- - - '>='
178
+ - - '>'
167
179
  - !ruby/object:Gem::Version
168
- version: '0'
180
+ version: 1.3.1
169
181
  requirements: []
170
182
  rubyforge_project: voicemail
171
183
  rubygems_version: 2.0.0
@@ -175,13 +187,17 @@ summary: Voicemail for Adhearsion
175
187
  test_files:
176
188
  - spec/spec_helper.rb
177
189
  - spec/support/voicemail_controller_spec_helper.rb
178
- - spec/voicemail/mailbox_controller_spec.rb
179
- - spec/voicemail/mailbox_main_menu_controller_spec.rb
180
- - spec/voicemail/mailbox_messages_controller_spec.rb
181
- - spec/voicemail/mailbox_play_message_controller_spec.rb
182
- - spec/voicemail/mailbox_set_greeting_controller_spec.rb
183
- - spec/voicemail/mailbox_set_pin_controller_spec.rb
190
+ - spec/voicemail/call_controllers/application_controller_spec.rb
191
+ - spec/voicemail/call_controllers/authentication_controller_spec.rb
192
+ - spec/voicemail/call_controllers/mailbox_controller_spec.rb
193
+ - spec/voicemail/call_controllers/mailbox_main_menu_controller_spec.rb
194
+ - spec/voicemail/call_controllers/mailbox_messages_controller_spec.rb
195
+ - spec/voicemail/call_controllers/mailbox_play_message_controller_spec.rb
196
+ - spec/voicemail/call_controllers/mailbox_play_message_intro_controller_spec.rb
197
+ - spec/voicemail/call_controllers/mailbox_set_greeting_controller_spec.rb
198
+ - spec/voicemail/call_controllers/mailbox_set_pin_controller_spec.rb
199
+ - spec/voicemail/call_controllers/voicemail_controller_spec.rb
200
+ - spec/voicemail/localization_loader_spec.rb
184
201
  - spec/voicemail/storage_pstore_spec.rb
185
202
  - spec/voicemail/storage_spec.rb
186
- - spec/voicemail/voicemail_controller_spec.rb
187
203
  has_rdoc:
@@ -1,56 +0,0 @@
1
- module Voicemail
2
- class MailboxController < ApplicationController
3
- def run
4
- if mailbox
5
- play_greeting
6
- fail_auth unless authenticate
7
- play_number_of_messages
8
- main_menu
9
- else
10
- mailbox_not_found
11
- end
12
- end
13
-
14
- def authenticate
15
- current_tries = 0
16
- auth_ok = false
17
- while current_tries < config.mailbox.pin_tries
18
- input = ask config.mailbox.please_enter_pin, terminator: "#", timeout: config.prompt_timeout
19
- logger.info input.to_s
20
- logger.info mailbox[:pin].to_s
21
- auth_ok = true if input.to_s == mailbox[:pin].to_s
22
- break if auth_ok
23
- play config.mailbox.pin_wrong
24
- current_tries += 1
25
- end
26
- auth_ok
27
- end
28
-
29
- def play_number_of_messages
30
- number = storage.count_new_messages(mailbox[:id])
31
- if number > 0
32
- play config.mailbox.number_before
33
- play_numeric number
34
- play config.mailbox.number_after
35
- else
36
- play config.messages.no_new_messages
37
- end
38
- end
39
-
40
- private
41
-
42
- def play_greeting
43
- play config.mailbox.greeting_message
44
- end
45
-
46
- def mailbox_not_found
47
- play config.mailbox_not_found
48
- hangup
49
- end
50
-
51
- def fail_auth
52
- play config.mailbox.could_not_auth
53
- hangup
54
- end
55
- end
56
- end
@@ -1,55 +0,0 @@
1
- module Voicemail
2
- class MailboxMessagesController < ApplicationController
3
- def run
4
- message_loop
5
- end
6
-
7
- def message_loop
8
- number = storage.count_new_messages(mailbox[:id])
9
- if number > 0
10
- next_message
11
- else
12
- bail_out
13
- end
14
- end
15
-
16
- def next_message
17
- current_message = storage.next_new_message(mailbox[:id])
18
- handle_message current_message
19
- message_loop
20
- end
21
-
22
- def handle_message(message)
23
- invoke MailboxPlayMessageController, message: message, mailbox: mailbox[:id]
24
- end
25
-
26
- private
27
-
28
- def bail_out
29
- play config.messages.no_new_messages
30
- main_menu
31
- end
32
-
33
- def section_menu
34
- menu config.mailbox.menu_greeting,
35
- timeout: config.menu_timeout, tries: config.menu_tries do
36
- match(1) { listen_to_messages }
37
- match(2) { set_greeting }
38
- match(3) { set_pin }
39
-
40
- timeout do
41
- play config.mailbox.menu_timeout_message
42
- end
43
-
44
- invalid do
45
- play config.mailbox.menu_invalid_message
46
- end
47
-
48
- failure do
49
- play config.mailbox.menu_failure_message
50
- hangup
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,33 +0,0 @@
1
- module Voicemail
2
- class VoicemailController < ApplicationController
3
- def run
4
- answer unless config.force_183
5
- if mailbox
6
- answer if config.force_183
7
- play_greeting
8
- handle_recording
9
- else
10
- mailbox_not_found
11
- end
12
- end
13
-
14
- def play_greeting
15
- play mailbox[:greeting_message] || config.default_greeting
16
- end
17
-
18
- def handle_recording
19
- @from = call.from
20
- record_comp = record config.recording.to_hash.merge(interruptible: true, direction: :recv)
21
- save_recording record_comp.complete_event.recording.uri
22
- end
23
-
24
- def mailbox_not_found
25
- play config.mailbox_not_found
26
- hangup
27
- end
28
-
29
- def save_recording(uri)
30
- storage.save_recording mailbox[:id], @from, uri
31
- end
32
- end
33
- end