adhearsion 1.2.6 → 2.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (236) hide show
  1. data/.gitignore +17 -10
  2. data/CHANGELOG.md +273 -0
  3. data/Gemfile +1 -1
  4. data/Guardfile +17 -0
  5. data/README.markdown +61 -9
  6. data/Rakefile +16 -48
  7. data/adhearsion.gemspec +21 -7
  8. data/bin/ahn +3 -1
  9. data/cucumber.yml +4 -0
  10. data/features/app_generator.feature +42 -0
  11. data/features/cli.feature +108 -0
  12. data/features/step_definitions/app_generator_steps.rb +6 -0
  13. data/features/step_definitions/cli_steps.rb +74 -0
  14. data/features/support/aruba_helper.rb +22 -0
  15. data/features/support/env.rb +37 -0
  16. data/features/support/utils.rb +8 -0
  17. data/lib/adhearsion.rb +85 -41
  18. data/lib/adhearsion/call.rb +176 -0
  19. data/lib/adhearsion/call_controller.rb +134 -0
  20. data/lib/adhearsion/call_controller/dial.rb +70 -0
  21. data/lib/adhearsion/call_controller/input.rb +173 -0
  22. data/lib/adhearsion/call_controller/menu.rb +124 -0
  23. data/lib/adhearsion/call_controller/output.rb +267 -0
  24. data/lib/adhearsion/call_controller/record.rb +42 -0
  25. data/lib/adhearsion/call_controller/utility.rb +60 -0
  26. data/lib/adhearsion/calls.rb +81 -0
  27. data/lib/adhearsion/cli.rb +1 -3
  28. data/lib/adhearsion/cli_commands.rb +142 -0
  29. data/lib/adhearsion/configuration.rb +149 -0
  30. data/lib/adhearsion/console.rb +19 -8
  31. data/lib/adhearsion/dialplan_controller.rb +9 -0
  32. data/lib/adhearsion/events.rb +84 -0
  33. data/lib/adhearsion/foundation/all.rb +0 -7
  34. data/lib/adhearsion/foundation/custom_daemonizer.rb +4 -6
  35. data/lib/adhearsion/foundation/exception_handler.rb +9 -0
  36. data/lib/adhearsion/foundation/object.rb +26 -8
  37. data/lib/adhearsion/foundation/synchronized_hash.rb +3 -6
  38. data/lib/adhearsion/foundation/thread_safety.rb +17 -1
  39. data/lib/adhearsion/generators/app/app_generator.rb +4 -13
  40. data/lib/adhearsion/generators/app/templates/Gemfile +10 -5
  41. data/lib/adhearsion/generators/app/templates/Procfile +1 -0
  42. data/lib/adhearsion/generators/app/templates/README.md +28 -0
  43. data/lib/adhearsion/generators/app/templates/config/adhearsion.rb +41 -0
  44. data/lib/adhearsion/generators/app/templates/{components/simon_game → lib}/simon_game.rb +6 -18
  45. data/lib/adhearsion/generators/app/templates/script/ahn +2 -2
  46. data/lib/adhearsion/initializer.rb +151 -293
  47. data/lib/adhearsion/initializer/logging.rb +33 -0
  48. data/lib/adhearsion/logging.rb +65 -69
  49. data/lib/adhearsion/menu_dsl.rb +15 -0
  50. data/lib/adhearsion/menu_dsl/calculated_match.rb +39 -0
  51. data/lib/adhearsion/menu_dsl/calculated_match_collection.rb +41 -0
  52. data/lib/adhearsion/menu_dsl/fixnum_match_calculator.rb +18 -0
  53. data/lib/adhearsion/menu_dsl/match_calculator.rb +36 -0
  54. data/lib/adhearsion/{voip/menu_state_machine/menu_class.rb → menu_dsl/menu.rb} +38 -40
  55. data/lib/adhearsion/menu_dsl/menu_builder.rb +69 -0
  56. data/lib/adhearsion/menu_dsl/range_match_calculator.rb +55 -0
  57. data/lib/adhearsion/menu_dsl/string_match_calculator.rb +21 -0
  58. data/lib/adhearsion/outbound_call.rb +64 -0
  59. data/lib/adhearsion/plugin.rb +319 -0
  60. data/lib/adhearsion/plugin/collection.rb +19 -0
  61. data/lib/adhearsion/plugin/initializer.rb +37 -0
  62. data/lib/adhearsion/plugin/methods_container.rb +6 -0
  63. data/lib/adhearsion/process.rb +94 -0
  64. data/lib/adhearsion/punchblock_plugin.rb +29 -0
  65. data/lib/adhearsion/punchblock_plugin/initializer.rb +137 -0
  66. data/lib/adhearsion/router.rb +30 -0
  67. data/lib/adhearsion/router/route.rb +42 -0
  68. data/lib/adhearsion/script_ahn_loader.rb +2 -2
  69. data/lib/adhearsion/tasks.rb +14 -9
  70. data/lib/adhearsion/tasks/configuration.rb +26 -0
  71. data/lib/adhearsion/tasks/plugins.rb +17 -0
  72. data/lib/adhearsion/version.rb +8 -14
  73. data/spec/adhearsion/call_controller/dial_spec.rb +138 -0
  74. data/spec/adhearsion/call_controller/input_spec.rb +278 -0
  75. data/spec/adhearsion/call_controller/menu_spec.rb +120 -0
  76. data/spec/adhearsion/call_controller/output_spec.rb +466 -0
  77. data/spec/adhearsion/call_controller/record_spec.rb +125 -0
  78. data/spec/adhearsion/call_controller_spec.rb +395 -0
  79. data/spec/adhearsion/call_spec.rb +438 -0
  80. data/spec/adhearsion/calls_spec.rb +47 -0
  81. data/spec/adhearsion/configuration_spec.rb +308 -0
  82. data/spec/adhearsion/dialplan_controller_spec.rb +26 -0
  83. data/spec/adhearsion/events_spec.rb +112 -0
  84. data/spec/adhearsion/initializer/logging_spec.rb +58 -0
  85. data/spec/adhearsion/initializer_spec.rb +209 -122
  86. data/spec/adhearsion/logging_spec.rb +58 -47
  87. data/spec/adhearsion/menu_dsl/calculated_match_collection_spec.rb +56 -0
  88. data/spec/adhearsion/menu_dsl/calculated_match_spec.rb +57 -0
  89. data/spec/adhearsion/menu_dsl/fixnum_match_calculator_spec.rb +33 -0
  90. data/spec/adhearsion/menu_dsl/match_calculator_spec.rb +13 -0
  91. data/spec/adhearsion/menu_dsl/menu_builder_spec.rb +118 -0
  92. data/spec/adhearsion/menu_dsl/menu_spec.rb +210 -0
  93. data/spec/adhearsion/menu_dsl/range_match_calculator_spec.rb +28 -0
  94. data/spec/adhearsion/menu_dsl/string_match_calculator_spec.rb +36 -0
  95. data/spec/adhearsion/menu_dsl_spec.rb +12 -0
  96. data/spec/adhearsion/outbound_call_spec.rb +174 -0
  97. data/spec/adhearsion/plugin_spec.rb +489 -0
  98. data/spec/adhearsion/process_spec.rb +34 -0
  99. data/spec/adhearsion/punchblock_plugin/initializer_spec.rb +294 -0
  100. data/spec/adhearsion/router/route_spec.rb +99 -0
  101. data/spec/adhearsion/router_spec.rb +106 -0
  102. data/spec/adhearsion_spec.rb +46 -0
  103. data/spec/spec_helper.rb +14 -14
  104. data/spec/support/call_controller_test_helpers.rb +48 -0
  105. data/spec/support/initializer_stubs.rb +8 -13
  106. data/spec/support/punchblock_mocks.rb +6 -0
  107. metadata +255 -253
  108. data/CHANGELOG +0 -174
  109. data/bin/ahnctl +0 -68
  110. data/bin/jahn +0 -43
  111. data/examples/asterisk_manager_interface/standalone.rb +0 -51
  112. data/lib/adhearsion/commands.rb +0 -302
  113. data/lib/adhearsion/component_manager.rb +0 -278
  114. data/lib/adhearsion/component_manager/component_tester.rb +0 -54
  115. data/lib/adhearsion/component_manager/spec_framework.rb +0 -18
  116. data/lib/adhearsion/events_support.rb +0 -65
  117. data/lib/adhearsion/foundation/blank_slate.rb +0 -3
  118. data/lib/adhearsion/foundation/event_socket.rb +0 -205
  119. data/lib/adhearsion/foundation/future_resource.rb +0 -36
  120. data/lib/adhearsion/foundation/metaprogramming.rb +0 -17
  121. data/lib/adhearsion/foundation/numeric.rb +0 -13
  122. data/lib/adhearsion/foundation/pseudo_guid.rb +0 -10
  123. data/lib/adhearsion/foundation/relationship_properties.rb +0 -42
  124. data/lib/adhearsion/foundation/string.rb +0 -26
  125. data/lib/adhearsion/generators/app/templates/.ahnrc +0 -34
  126. data/lib/adhearsion/generators/app/templates/README +0 -8
  127. data/lib/adhearsion/generators/app/templates/components/ami_remote/ami_remote.rb +0 -15
  128. data/lib/adhearsion/generators/app/templates/components/disabled/HOW_TO_ENABLE +0 -7
  129. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/README.markdown +0 -47
  130. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.rb +0 -34
  131. data/lib/adhearsion/generators/app/templates/components/disabled/stomp_gateway/stomp_gateway.yml +0 -12
  132. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/README.markdown +0 -3
  133. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +0 -11
  134. data/lib/adhearsion/generators/app/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  135. data/lib/adhearsion/generators/app/templates/config/startup.rb +0 -81
  136. data/lib/adhearsion/generators/app/templates/dialplan.rb +0 -3
  137. data/lib/adhearsion/generators/app/templates/events.rb +0 -33
  138. data/lib/adhearsion/host_definitions.rb +0 -67
  139. data/lib/adhearsion/initializer/asterisk.rb +0 -86
  140. data/lib/adhearsion/initializer/configuration.rb +0 -324
  141. data/lib/adhearsion/initializer/database.rb +0 -60
  142. data/lib/adhearsion/initializer/drb.rb +0 -31
  143. data/lib/adhearsion/initializer/freeswitch.rb +0 -22
  144. data/lib/adhearsion/initializer/ldap.rb +0 -57
  145. data/lib/adhearsion/initializer/rails.rb +0 -41
  146. data/lib/adhearsion/initializer/xmpp.rb +0 -42
  147. data/lib/adhearsion/tasks/components.rb +0 -32
  148. data/lib/adhearsion/tasks/database.rb +0 -5
  149. data/lib/adhearsion/tasks/deprecations.rb +0 -59
  150. data/lib/adhearsion/tasks/generating.rb +0 -20
  151. data/lib/adhearsion/tasks/lint.rb +0 -4
  152. data/lib/adhearsion/voip/asterisk.rb +0 -4
  153. data/lib/adhearsion/voip/asterisk/agi_server.rb +0 -121
  154. data/lib/adhearsion/voip/asterisk/commands.rb +0 -1966
  155. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +0 -140
  156. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +0 -102
  157. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +0 -250
  158. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +0 -240
  159. data/lib/adhearsion/voip/asterisk/config_manager.rb +0 -64
  160. data/lib/adhearsion/voip/asterisk/manager_interface.rb +0 -697
  161. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +0 -1681
  162. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +0 -341
  163. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +0 -78
  164. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +0 -87
  165. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +0 -80
  166. data/lib/adhearsion/voip/call.rb +0 -521
  167. data/lib/adhearsion/voip/call_routing.rb +0 -64
  168. data/lib/adhearsion/voip/commands.rb +0 -17
  169. data/lib/adhearsion/voip/constants.rb +0 -39
  170. data/lib/adhearsion/voip/conveniences.rb +0 -18
  171. data/lib/adhearsion/voip/dial_plan.rb +0 -252
  172. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +0 -151
  173. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +0 -37
  174. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +0 -27
  175. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +0 -124
  176. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +0 -69
  177. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +0 -16
  178. data/lib/adhearsion/voip/dsl/numerical_string.rb +0 -128
  179. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +0 -48
  180. data/lib/adhearsion/voip/freeswitch/event_handler.rb +0 -58
  181. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +0 -129
  182. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +0 -38
  183. data/lib/adhearsion/voip/freeswitch/oes_server.rb +0 -195
  184. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +0 -80
  185. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +0 -123
  186. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +0 -57
  187. data/lib/adhearsion/xmpp/connection.rb +0 -61
  188. data/lib/theatre.rb +0 -147
  189. data/lib/theatre/README.markdown +0 -64
  190. data/lib/theatre/callback_definition_loader.rb +0 -86
  191. data/lib/theatre/guid.rb +0 -23
  192. data/lib/theatre/invocation.rb +0 -131
  193. data/lib/theatre/namespace_manager.rb +0 -153
  194. data/lib/theatre/version.rb +0 -2
  195. data/spec/adhearsion/cli_spec.rb +0 -306
  196. data/spec/adhearsion/component_manager_spec.rb +0 -292
  197. data/spec/adhearsion/constants_spec.rb +0 -8
  198. data/spec/adhearsion/drb_spec.rb +0 -65
  199. data/spec/adhearsion/fixtures/dialplan.rb +0 -3
  200. data/spec/adhearsion/foundation/event_socket_spec.rb +0 -168
  201. data/spec/adhearsion/host_definitions_spec.rb +0 -79
  202. data/spec/adhearsion/initializer/configuration_spec.rb +0 -291
  203. data/spec/adhearsion/initializer/loading_spec.rb +0 -154
  204. data/spec/adhearsion/initializer/paths_spec.rb +0 -74
  205. data/spec/adhearsion/relationship_properties_spec.rb +0 -54
  206. data/spec/adhearsion/voip/asterisk/agi_server_spec.rb +0 -473
  207. data/spec/adhearsion/voip/asterisk/ami/ami_spec.rb +0 -550
  208. data/spec/adhearsion/voip/asterisk/ami/lexer/ami_fixtures.yml +0 -30
  209. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story +0 -291
  210. data/spec/adhearsion/voip/asterisk/ami/lexer/lexer_story.rb +0 -241
  211. data/spec/adhearsion/voip/asterisk/ami/lexer/story_helper.rb +0 -124
  212. data/spec/adhearsion/voip/asterisk/commands_spec.rb +0 -3241
  213. data/spec/adhearsion/voip/asterisk/config_file_generators/agents_spec.rb +0 -251
  214. data/spec/adhearsion/voip/asterisk/config_file_generators/queues_spec.rb +0 -323
  215. data/spec/adhearsion/voip/asterisk/config_file_generators/voicemail_spec.rb +0 -306
  216. data/spec/adhearsion/voip/asterisk/config_manager_spec.rb +0 -127
  217. data/spec/adhearsion/voip/asterisk/menu_command/calculated_match_spec.rb +0 -109
  218. data/spec/adhearsion/voip/asterisk/menu_command/matchers_spec.rb +0 -97
  219. data/spec/adhearsion/voip/call_routing_spec.rb +0 -125
  220. data/spec/adhearsion/voip/dialplan_manager_spec.rb +0 -468
  221. data/spec/adhearsion/voip/dsl/dialing_dsl_spec.rb +0 -270
  222. data/spec/adhearsion/voip/dsl/dispatcher_spec.rb +0 -82
  223. data/spec/adhearsion/voip/dsl/dispatcher_spec_helper.rb +0 -45
  224. data/spec/adhearsion/voip/dsl/parser_spec.rb +0 -69
  225. data/spec/adhearsion/voip/freeswitch/basic_connection_manager_spec.rb +0 -39
  226. data/spec/adhearsion/voip/freeswitch/inbound_connection_manager_spec.rb +0 -39
  227. data/spec/adhearsion/voip/freeswitch/oes_server_spec.rb +0 -9
  228. data/spec/adhearsion/voip/numerical_string_spec.rb +0 -61
  229. data/spec/adhearsion/voip/phone_number_spec.rb +0 -45
  230. data/spec/support/the_following_code.rb +0 -3
  231. data/spec/theatre/dsl_examples/simple_before_call.rb +0 -7
  232. data/spec/theatre/dsl_spec.rb +0 -69
  233. data/spec/theatre/invocation_spec.rb +0 -182
  234. data/spec/theatre/namespace_spec.rb +0 -125
  235. data/spec/theatre/spec_helper_spec.rb +0 -28
  236. data/spec/theatre/theatre_class_spec.rb +0 -148
@@ -1,140 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'config_generator')
2
-
3
- module Adhearsion
4
- module VoIP
5
- module Asterisk
6
- module ConfigFileGenerators
7
- class Agents < AsteriskConfigGenerator
8
-
9
- attr_accessor :general_section, :agent_section, :agent_definitions, :agent_section_special
10
- def initialize
11
- @general_section = {}
12
- @agent_section = {}
13
- @agent_section_special = {} # Uses => separator
14
- @agent_definitions = []
15
-
16
- super
17
- end
18
-
19
- def to_s
20
- AsteriskConfigGenerator.warning_message +
21
- general_section.inject("[general]") { |section,(key,value)| section + "\n#{key}=#{value}" } +
22
- agent_section.inject("\n[agents]") { |section,(key,value)| section + "\n#{key}=#{value}" } +
23
- agent_section_special.inject("") { |section,(key,value)| section + "\n#{key} => #{value}" } +
24
- agent_definitions.inject("\n") do |section,properties|
25
- section + "\nagent => #{properties[:id]},#{properties[:password]},#{properties[:name]}"
26
- end
27
- end
28
- alias conf to_s # Allows "agents.conf" if agents.kind_of?(Agents)
29
-
30
- def agent(id, properties)
31
- agent_definitions << {:id => id}.merge(properties)
32
- end
33
-
34
- # Group memberships for agents (may change in mid-file)
35
- # WHAT DOES GROUPING ACCOMPLISH?
36
- def groups(*args)
37
- agent_section[:group] = args.join(",")
38
- end
39
-
40
- # Define whether callbacklogins should be stored in astdb for
41
- # persistence. Persistent logins will be reloaded after
42
- # Asterisk restarts.
43
- def persistent_agents(yes_or_no)
44
- general_section[:persistentagents] = boolean_to_yes_no yes_or_no
45
- end
46
-
47
- # enable or disable a single extension from longing in as multiple
48
- # agents, defaults to enabled
49
- def allow_multiple_logins_per_extension(yes_or_no)
50
- general_section[:multiplelogin] = boolean_to_yes_no yes_or_no
51
- end
52
-
53
- # Define maxlogintries to allow agent to try max logins before
54
- # failed. Default to 3
55
- def max_login_tries(number_of_tries)
56
- agent_section[:maxlogintries] = number_of_tries
57
- end
58
-
59
- # Define autologoff times if appropriate. This is how long
60
- # the phone has to ring with no answer before the agent is
61
- # automatically logged off (in seconds)
62
- def log_off_after_duration(time_in_seconds)
63
- agent_section[:autologoff] = time_in_seconds
64
- end
65
-
66
- # Define autologoffunavail to have agents automatically logged
67
- # out when the extension that they are at returns a CHANUNAVAIL
68
- # status when a call is attempted to be sent there.
69
- # Default is "no".
70
- def log_off_if_unavailable(yes_or_no)
71
- agent_section[:autologoffunavail] = boolean_to_yes_no yes_or_no
72
- end
73
-
74
- # Define ackcall to require an acknowledgement by '#' when
75
- # an agent logs in using agentcallbacklogin. Default is "no".
76
- def require_hash_to_acknowledge(yes_or_no)
77
- agent_section[:ackcall] = boolean_to_yes_no yes_or_no
78
- end
79
-
80
- # Define endcall to allow an agent to hangup a call by '*'.
81
- # Default is "yes". Set this to "no" to ignore '*'.
82
- def allow_star_to_hangup(yes_or_no)
83
- agent_section[:endcall] = boolean_to_yes_no yes_or_no
84
- end
85
-
86
- # Define wrapuptime. This is the minimum amount of time when
87
- # after disconnecting before the caller can receive a new call
88
- # note this is in milliseconds.
89
- def time_between_calls(time_in_seconds)
90
- agent_section[:wrapuptime] = (time_in_seconds * 1000).to_i
91
- end
92
-
93
- # Define the default musiconhold for agents
94
- # musiconhold => music_class
95
- def hold_music_class(music_class)
96
- agent_section_special[:musiconhold] = music_class.to_s
97
- end
98
-
99
- # TODO: I'm not exactly sure what this even does....
100
-
101
- # Define the default good bye sound file for agents
102
- # default to vm-goodbye
103
- def play_on_agent_goodbye(sound_file_name)
104
- agent_section_special[:agentgoodbye] = sound_file_name
105
- end
106
-
107
- # Define updatecdr. This is whether or not to change the source
108
- # channel in the CDR record for this call to agent/agent_id so
109
- # that we know which agent generates the call
110
- def change_cdr_source(yes_or_no)
111
- agent_section[:updatecdr] = boolean_to_yes_no yes_or_no
112
- end
113
-
114
- # An optional custom beep sound file to play to always-connected agents.
115
- def play_for_waiting_keep_alive(sound_file)
116
- agent_section[:custom_beep] = sound_file
117
- end
118
-
119
- def record_agent_calls(yes_or_no)
120
- agent_section[:recordagentcalls] = boolean_to_yes_no yes_or_no
121
- end
122
-
123
- def recording_format(symbol)
124
- raise ArgumentError, "Unrecognized format #{symbol}" unless [:wav, :wav49, :gsm].include? symbol
125
- agent_section[:recordformat] = symbol
126
- end
127
-
128
- def recording_prefix(string)
129
- agent_section[:urlprefix] = string
130
- end
131
-
132
- def save_recordings_in(path_to_directory)
133
- agent_section[:savecallsin] = path_to_directory
134
- end
135
-
136
- end
137
- end
138
- end
139
- end
140
- end
@@ -1,102 +0,0 @@
1
- module Adhearsion
2
- module VoIP
3
- module Asterisk
4
- module ConfigFileGenerators
5
- class AsteriskConfigGenerator
6
-
7
- SECTION_TITLE = /(\[[\w_-]+\])/
8
-
9
- class << self
10
-
11
- # Converts a config file into a Hash of contexts mapping to two dimensional array of pairs
12
- def create_sanitary_hash_from(config_file_content)
13
- almost_sanitized = Hash[*config_file_content.
14
- split("\n"). # Split the lines into an Array
15
- grep(/^\s*[^;\s]/). # Grep lines that aren't commented out
16
- join("\n"). # Convert them into one String again
17
- split(SECTION_TITLE). # Separate them into sections
18
- map(&:strip). # Remove all whitespace
19
- reject(&:empty?). # Get rid of indices that were only whitespace
20
- # Lastly, separate the keys/value pairs for the Hash
21
- map { |token| token =~ /^#{SECTION_TITLE}$/ ? token : token.split(/\n+/).sort }
22
- ]
23
- end
24
-
25
- def warning_message
26
- %{;; THIS FILE WAS GENERATED BY ADHEARSION ON #{Time.now.ctime}!\n} +
27
- %{;; ANY CHANGES MADE BELOW WILL BE BLOWN AWAY WHEN THE FILE IS REGENERATED!\n\n}
28
- end
29
-
30
- end
31
-
32
- def initialize
33
- yield self if block_given?
34
- end
35
-
36
- def to_sanitary_hash
37
- self.class.create_sanitary_hash_from to_s
38
- end
39
-
40
- protected
41
-
42
- def boolean(options)
43
- cache = options.delete(:with) || properties
44
- options.each_pair do |key, value|
45
- cache[key] = boolean_to_yes_no value
46
- end
47
- end
48
-
49
- def string(options)
50
- cache = options.delete(:with) || properties
51
- options.each_pair do |key, value|
52
- cache[key] = value
53
- end
54
- end
55
-
56
- def int(options)
57
- cache = options.delete(:with) || properties
58
- options.each_pair do |property,number|
59
- number = number.to_i if (number.kind_of?(String) && number =~ /^\d+$/) || number.kind_of?(Numeric)
60
- raise ArgumentError, "#{number.inspect} must be an integer" unless number.kind_of?(Fixnum)
61
- cache[property] = number.to_i
62
- end
63
- end
64
-
65
- def one_of(criteria, options)
66
- cache = options.delete(:with) || properties
67
- options.each_pair do |key, value|
68
- search = !criteria.find { |criterion| criterion === value }.nil?
69
- unless search
70
- msg = "Didn't recognize #{value.inspect}! Must be one of " + criteria.map(&:inspect).to_sentence
71
- raise ArgumentError, msg
72
- end
73
- cache[key] = [true, false].include?(value) ? boolean_to_yes_no(value) : value
74
- end
75
- end
76
-
77
- def one_of_and_translate(criteria, options)
78
- cache = options.delete(:with) || properties
79
- options.each_pair do |key, value|
80
- search = criteria.keys.find { |criterion| criterion === value }
81
- unless search
82
- msg = "Didn't recognize #{value.inspect}! Must be one of " + criteria.keys.map(&:inspect).to_sentence
83
- raise ArgumentError, msg
84
- end
85
- cache[key] = criteria[value]
86
- end
87
- end
88
-
89
- private
90
-
91
- def boolean_to_yes_no(boolean)
92
- unless boolean.equal?(boolean) || boolean.equal?(boolean)
93
- raise "#{boolean.inspect} is not true/false!"
94
- end
95
- boolean ? 'yes' : 'no'
96
- end
97
-
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,250 +0,0 @@
1
- require File.join(File.dirname(__FILE__), 'config_generator')
2
-
3
- module Adhearsion
4
- module VoIP
5
- module Asterisk
6
- module ConfigFileGenerators
7
-
8
- # This will generate a queues.conf file. If there is no documentation on what a method
9
- # actually does, take a look at the documentation for its original key/value pair in
10
- # an unedited queues.conf file. WARNING! Don't get too embedded with these method names.
11
- # I'm still not satisfied. These settings will be greatly abstracted eventually.
12
- class Queues < AsteriskConfigGenerator
13
-
14
- DEFAULT_GENERAL_SECTION = {
15
- :autofill => "yes"
16
- }
17
-
18
- attr_reader :general_section, :queue_definitions, :properties
19
- def initialize
20
- @general_section = DEFAULT_GENERAL_SECTION.clone
21
- @properties = {}
22
- @queue_definitions = []
23
- super
24
- end
25
-
26
- def queue(name)
27
- new_queue = QueueDefinition.new name
28
- yield new_queue if block_given?
29
- queue_definitions << new_queue
30
- new_queue
31
- end
32
-
33
- def to_s
34
- AsteriskConfigGenerator.warning_message +
35
- general_section.inject("[general]") { |section,(key,value)| section + "\n#{key}=#{value}" } + "\n\n" +
36
- queue_definitions.map(&:to_s).join("\n\n")
37
- end
38
- alias conf to_s
39
-
40
- def persistent_members(yes_no)
41
- boolean :persistentmembers => yes_no, :with => general_section
42
- end
43
-
44
- def monitor_type(symbol)
45
- criteria = {:monitor => "Monitor", :mix_monitor => "MixMonitor"}
46
- one_of_and_translate criteria, 'monitor-type' => symbol, :with => general_section
47
- end
48
-
49
-
50
- class QueueDefinition < AsteriskConfigGenerator
51
-
52
- DEFAULT_QUEUE_PROPERTIES = {
53
- :autofill => 'yes',
54
- :eventwhencalled => 'vars',
55
- :eventmemberstatus => 'yes',
56
- :setinterfacevar => 'yes'
57
- }
58
-
59
- SUPPORTED_RING_STRATEGIES = [:ringall, :roundrobin, :leastrecent, :fewestcalls, :random, :rrmemory]
60
-
61
- DEFAULT_SOUND_FILES = {
62
- 'queue-youarenext' => 'queue-youarenext',
63
- 'queue-thereare' => 'queue-thereare',
64
- 'queue-callswaiting' => 'queue-callswaiting',
65
- 'queue-holdtime' => 'queue-holdtime',
66
- 'queue-minutes' => 'queue-minutes',
67
- 'queue-seconds' => 'queue-seconds',
68
- 'queue-thankyou' => 'queue-thankyou',
69
- 'queue-lessthan' => 'queue-less-than',
70
- 'queue-reporthold' => 'queue-reporthold',
71
- 'periodic-announce' => 'queue-periodic-announce'
72
- }
73
-
74
- SOUND_FILE_SYMBOL_INTERPRETATIONS = {
75
- :you_are_next => 'queue-youarenext',
76
- :there_are => 'queue-thereare',
77
- :calls_waiting => 'queue-callswaiting',
78
- :hold_time => 'queue-holdtime',
79
- :minutes => 'queue-minutes',
80
- :seconds => 'queue-seconds',
81
- :thank_you => 'queue-thankyou',
82
- :less_than => 'queue-lessthan',
83
- :report_hold => 'queue-reporthold',
84
- :periodic_announcement => 'periodic-announce'
85
- }
86
-
87
- attr_reader :members, :name, :properties
88
- def initialize(name)
89
- @name = name
90
- @members = []
91
- @properties = DEFAULT_QUEUE_PROPERTIES.clone
92
- @sound_files = DEFAULT_SOUND_FILES.clone
93
- end
94
-
95
- def to_s
96
- "[#{name}]\n" +
97
- properties.merge(@sound_files).map { |key, value| "#{key}=#{value}" }.sort.join("\n") + "\n\n" +
98
- members.map { |member| "member => #{member}" }.join("\n")
99
- end
100
-
101
- def music_class(moh_identifier)
102
- string :musicclass => moh_identifier
103
- end
104
-
105
- def play_on_connect(sound_file)
106
- string :announce => sound_file
107
- end
108
-
109
- def strategy(symbol)
110
- one_of SUPPORTED_RING_STRATEGIES, :strategy => symbol
111
- end
112
-
113
- def service_level(seconds)
114
- int :servicelevel => seconds
115
- end
116
-
117
- # A context may be specified, in which if the user types a SINGLE
118
- # digit extension while they are in the queue, they will be taken out
119
- # of the queue and sent to that extension in this context. This context
120
- # should obviously be a different context other than the one that
121
- # normally forwards to Adhearsion (though the context that handles
122
- # these digits should probably go out to Adhearsion too).
123
- def exit_to_context_on_digit_press(context_name)
124
- string :context => context_name
125
- end
126
-
127
- # Ex: ring_timeout 15.seconds
128
- def ring_timeout(seconds)
129
- int :timeout => seconds
130
- end
131
-
132
- # Ex: retry_after_waiting 5.seconds
133
- def retry_after_waiting(seconds)
134
- int :retry => seconds
135
- end
136
-
137
- # THIS IS UNSUPPORTED
138
- def weight(number)
139
- int :weight => number
140
- end
141
-
142
- # Ex: wrapup_time 1.minute
143
- def wrapup_time(seconds)
144
- int :wrapuptime => seconds
145
- end
146
-
147
-
148
- def autopause(yes_no)
149
- boolean :autopause => yes_no
150
- end
151
-
152
- def maximum_length(number)
153
- int :maxlen => number
154
- end
155
-
156
- def queue_status_announce_frequency(seconds)
157
- int "announce-frequency" => seconds
158
- end
159
-
160
- def periodically_announce(sound_file, options={})
161
- frequency = options.delete(:every) || 1.minute
162
-
163
- string 'periodic-announce' => sound_file
164
- int 'periodic-announce-frequency' => frequency
165
- end
166
-
167
- def announce_hold_time(seconds)
168
- one_of [true, false, :once], "announce-holdtime" => seconds
169
- end
170
-
171
- def announce_round_seconds(yes_no_or_once)
172
- int "announce-round-seconds" => yes_no_or_once
173
- end
174
-
175
- def monitor_format(symbol)
176
- one_of [:wav, :gsm, :wav49], 'monitor-format' => symbol
177
- end
178
-
179
- def monitor_type(symbol)
180
- criteria = {:monitor => "Monitor", :mix_monitor => "MixMonitor"}
181
- one_of_and_translate criteria, 'monitor-type' => symbol
182
- end
183
-
184
- # Ex: join_empty true
185
- # Ex: join_empty :strict
186
- def join_empty(yes_no_or_strict)
187
- one_of [true, false, :strict], :joinempty => yes_no_or_strict
188
- end
189
-
190
- def leave_when_empty(yes_no)
191
- boolean :leavewhenempty => yes_no
192
- end
193
-
194
- def report_hold_time(yes_no)
195
- boolean :reportholdtime => yes_no
196
- end
197
-
198
- def ring_in_use(yes_no)
199
- boolean :ringinuse => yes_no
200
- end
201
-
202
- # Number of seconds to wait when an agent is to be bridged with
203
- # a caller. Normally you'd want this to be zero.
204
- def delay_connection_by(seconds)
205
- int :memberdelay => seconds
206
- end
207
-
208
- def timeout_restart(yes_no)
209
- boolean :timeoutrestart => yes_no
210
- end
211
-
212
- # Give a Hash argument here to override the default sound files for this queue.
213
- #
214
- # Usage:
215
- #
216
- # queue.sound_files :you_are_next => 'queue-youarenext',
217
- # :there_are => 'queue-thereare',
218
- # :calls_waiting => 'queue-callswaiting',
219
- # :hold_time => 'queue-holdtime',
220
- # :minutes => 'queue-minutes',
221
- # :seconds => 'queue-seconds',
222
- # :thank_you => 'queue-thankyou',
223
- # :less_than => 'queue-less-than',
224
- # :report_hold => 'queue-reporthold',
225
- # :periodic_announcement => 'queue-periodic-announce'
226
- #
227
- # Note: the Hash values are the defaults. You only need to specify the ones you
228
- # wish to override.
229
- def sound_files(hash_of_files)
230
- hash_of_files.each_pair do |key, value|
231
- unless SOUND_FILE_SYMBOL_INTERPRETATIONS.has_key? key
232
- message = "Unrecogized sound file identifier #{key.inspect}. " +
233
- "Supported: " + SOUND_FILE_SYMBOL_INTERPRETATIONS.keys.map(&:inspect).to_sentence
234
- raise ArgumentError, message
235
- end
236
- @sound_files[SOUND_FILE_SYMBOL_INTERPRETATIONS[key]] = value
237
- end
238
- end
239
-
240
- def member(driver)
241
- members << (driver.kind_of?(String) && driver =~ %r'/' ? driver : "Agent/#{driver}")
242
- end
243
-
244
- end
245
-
246
- end
247
- end
248
- end
249
- end
250
- end