adhearsion-cw 1.0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/CHANGELOG +109 -0
  2. data/EVENTS +11 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +456 -0
  5. data/Rakefile +134 -0
  6. data/adhearsion.gemspec +174 -0
  7. data/app_generators/ahn/USAGE +5 -0
  8. data/app_generators/ahn/ahn_generator.rb +97 -0
  9. data/app_generators/ahn/templates/.ahnrc +34 -0
  10. data/app_generators/ahn/templates/Gemfile +7 -0
  11. data/app_generators/ahn/templates/README +8 -0
  12. data/app_generators/ahn/templates/Rakefile +27 -0
  13. data/app_generators/ahn/templates/components/ami_remote/ami_remote.rb +15 -0
  14. data/app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE +7 -0
  15. data/app_generators/ahn/templates/components/disabled/restful_rpc/README.markdown +11 -0
  16. data/app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb +48 -0
  17. data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.rb +91 -0
  18. data/app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.yml +34 -0
  19. data/app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb +251 -0
  20. data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb +104 -0
  21. data/app_generators/ahn/templates/components/disabled/sandbox/sandbox.yml +2 -0
  22. data/app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown +47 -0
  23. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb +34 -0
  24. data/app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.yml +12 -0
  25. data/app_generators/ahn/templates/components/disabled/xmpp_gateway/README.markdown +3 -0
  26. data/app_generators/ahn/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb +11 -0
  27. data/app_generators/ahn/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml +0 -0
  28. data/app_generators/ahn/templates/components/simon_game/simon_game.rb +56 -0
  29. data/app_generators/ahn/templates/config/startup.rb +74 -0
  30. data/app_generators/ahn/templates/dialplan.rb +3 -0
  31. data/app_generators/ahn/templates/events.rb +32 -0
  32. data/bin/ahn +29 -0
  33. data/bin/ahnctl +68 -0
  34. data/bin/jahn +43 -0
  35. data/examples/asterisk_manager_interface/standalone.rb +51 -0
  36. data/lib/adhearsion/cli.rb +296 -0
  37. data/lib/adhearsion/component_manager/component_tester.rb +53 -0
  38. data/lib/adhearsion/component_manager/spec_framework.rb +18 -0
  39. data/lib/adhearsion/component_manager.rb +272 -0
  40. data/lib/adhearsion/events_support.rb +84 -0
  41. data/lib/adhearsion/foundation/all.rb +15 -0
  42. data/lib/adhearsion/foundation/blank_slate.rb +3 -0
  43. data/lib/adhearsion/foundation/custom_daemonizer.rb +45 -0
  44. data/lib/adhearsion/foundation/event_socket.rb +205 -0
  45. data/lib/adhearsion/foundation/future_resource.rb +36 -0
  46. data/lib/adhearsion/foundation/metaprogramming.rb +17 -0
  47. data/lib/adhearsion/foundation/numeric.rb +13 -0
  48. data/lib/adhearsion/foundation/pseudo_guid.rb +10 -0
  49. data/lib/adhearsion/foundation/relationship_properties.rb +42 -0
  50. data/lib/adhearsion/foundation/string.rb +26 -0
  51. data/lib/adhearsion/foundation/synchronized_hash.rb +96 -0
  52. data/lib/adhearsion/foundation/thread_safety.rb +7 -0
  53. data/lib/adhearsion/host_definitions.rb +67 -0
  54. data/lib/adhearsion/initializer/asterisk.rb +87 -0
  55. data/lib/adhearsion/initializer/configuration.rb +321 -0
  56. data/lib/adhearsion/initializer/database.rb +60 -0
  57. data/lib/adhearsion/initializer/drb.rb +31 -0
  58. data/lib/adhearsion/initializer/freeswitch.rb +22 -0
  59. data/lib/adhearsion/initializer/ldap.rb +57 -0
  60. data/lib/adhearsion/initializer/rails.rb +41 -0
  61. data/lib/adhearsion/initializer/xmpp.rb +42 -0
  62. data/lib/adhearsion/initializer.rb +394 -0
  63. data/lib/adhearsion/logging.rb +92 -0
  64. data/lib/adhearsion/tasks/components.rb +32 -0
  65. data/lib/adhearsion/tasks/database.rb +5 -0
  66. data/lib/adhearsion/tasks/deprecations.rb +59 -0
  67. data/lib/adhearsion/tasks/generating.rb +20 -0
  68. data/lib/adhearsion/tasks/lint.rb +4 -0
  69. data/lib/adhearsion/tasks/testing.rb +37 -0
  70. data/lib/adhearsion/tasks.rb +17 -0
  71. data/lib/adhearsion/version.rb +35 -0
  72. data/lib/adhearsion/voip/asterisk/agi_server.rb +115 -0
  73. data/lib/adhearsion/voip/asterisk/commands.rb +1581 -0
  74. data/lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb +140 -0
  75. data/lib/adhearsion/voip/asterisk/config_generators/config_generator.rb +102 -0
  76. data/lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb +250 -0
  77. data/lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb +240 -0
  78. data/lib/adhearsion/voip/asterisk/config_manager.rb +71 -0
  79. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb +1681 -0
  80. data/lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb +341 -0
  81. data/lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb +78 -0
  82. data/lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl +87 -0
  83. data/lib/adhearsion/voip/asterisk/manager_interface.rb +705 -0
  84. data/lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb +80 -0
  85. data/lib/adhearsion/voip/asterisk/super_manager.rb +19 -0
  86. data/lib/adhearsion/voip/asterisk.rb +4 -0
  87. data/lib/adhearsion/voip/call.rb +498 -0
  88. data/lib/adhearsion/voip/call_routing.rb +64 -0
  89. data/lib/adhearsion/voip/commands.rb +9 -0
  90. data/lib/adhearsion/voip/constants.rb +39 -0
  91. data/lib/adhearsion/voip/conveniences.rb +18 -0
  92. data/lib/adhearsion/voip/dial_plan.rb +250 -0
  93. data/lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb +37 -0
  94. data/lib/adhearsion/voip/dsl/dialing_dsl.rb +151 -0
  95. data/lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb +27 -0
  96. data/lib/adhearsion/voip/dsl/dialplan/dispatcher.rb +124 -0
  97. data/lib/adhearsion/voip/dsl/dialplan/parser.rb +69 -0
  98. data/lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb +16 -0
  99. data/lib/adhearsion/voip/dsl/numerical_string.rb +128 -0
  100. data/lib/adhearsion/voip/freeswitch/basic_connection_manager.rb +48 -0
  101. data/lib/adhearsion/voip/freeswitch/event_handler.rb +58 -0
  102. data/lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb +129 -0
  103. data/lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb +38 -0
  104. data/lib/adhearsion/voip/freeswitch/oes_server.rb +195 -0
  105. data/lib/adhearsion/voip/menu_state_machine/calculated_match.rb +80 -0
  106. data/lib/adhearsion/voip/menu_state_machine/matchers.rb +123 -0
  107. data/lib/adhearsion/voip/menu_state_machine/menu_builder.rb +57 -0
  108. data/lib/adhearsion/voip/menu_state_machine/menu_class.rb +149 -0
  109. data/lib/adhearsion/xmpp/connection.rb +61 -0
  110. data/lib/adhearsion.rb +46 -0
  111. data/lib/theatre/README.markdown +64 -0
  112. data/lib/theatre/callback_definition_loader.rb +84 -0
  113. data/lib/theatre/guid.rb +23 -0
  114. data/lib/theatre/invocation.rb +121 -0
  115. data/lib/theatre/namespace_manager.rb +153 -0
  116. data/lib/theatre/version.rb +2 -0
  117. data/lib/theatre.rb +151 -0
  118. metadata +323 -0
data/Rakefile ADDED
@@ -0,0 +1,134 @@
1
+ # -*- ruby -*-
2
+ ENV['RUBY_FLAGS'] = "-I#{%w(lib ext bin test).join(File::PATH_SEPARATOR)}"
3
+
4
+ require 'rubygems'
5
+ require 'bundler'
6
+ Bundler::GemHelper.install_tasks
7
+ require 'rake/testtask'
8
+ require 'date'
9
+
10
+ begin
11
+ gem 'rspec', '>= 2.3.0'
12
+ require 'rspec/core/rake_task'
13
+ rescue LoadError
14
+ abort "You must install RSpec: sudo gem install rspec"
15
+ end
16
+
17
+ begin
18
+ require 'yard'
19
+ YARD::Rake::YardocTask.new do |t|
20
+ t.files = ['lib/**/*.rb'] + %w[README.markdown TODO.markdown LICENSE]
21
+ end
22
+ rescue LoadError
23
+ STDERR.puts "\nCould not require() YARD! Install with 'gem install yard' to get the 'yardoc' task\n\n"
24
+ end
25
+
26
+ require 'adhearsion/version'
27
+
28
+ AHN_TESTS = ['spec/**/test_*.rb']
29
+ #AHN_TESTS = ['spec/test_ahn_command.rb']
30
+ GEMSPEC = eval File.read("adhearsion.gemspec")
31
+ RAGEL_FILES = %w[lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb]
32
+ THEATRE_TESTS = 'theatre-spec/**/*_spec.rb'
33
+
34
+ begin
35
+ require 'rcov/rcovtask'
36
+ Rcov::RcovTask.new do |t|
37
+ t.test_files = Dir[*AHN_TESTS]
38
+ t.output_dir = 'coverage'
39
+ t.verbose = true
40
+ t.rcov_opts.concat %w[--sort coverage --sort-reverse -x gems -x /var --no-validator-links]
41
+ end
42
+ rescue LoadError
43
+ STDERR.puts "Could not load rcov tasks -- rcov does not appear to be installed. Continuing anyway."
44
+ end
45
+
46
+ task :gem => :build
47
+
48
+ # YARD::Rake::YardocTask.new do |t|
49
+ # t.files = ['lib/**/*.rb'] # optional
50
+ # # t.options = ['--any', '--extra', '--opts'] # optional
51
+ # end
52
+
53
+ #Rake::TestTask.new('spec') do |t|
54
+ # t.libs << File.dirname(__FILE__)
55
+ # t.verbose = true
56
+ # t.pattern = AHN_TESTS
57
+ #end
58
+
59
+ RSpec::Core::RakeTask.new(:spec) do |t|
60
+ t.pattern = AHN_TESTS
61
+ end
62
+
63
+ task :default => :spec
64
+
65
+ desc "Check Ragel version"
66
+ task :check_ragel_version do
67
+ ragel_version_match = `ragel --version`.match(/(\d)\.(\d)+/)
68
+ abort "Could not get Ragel version! Is it installed? You must have at least version 6.3" unless ragel_version_match
69
+ big, small = ragel_version_match.captures.map { |n| n.to_i }
70
+ if big < 6 || (big == 6 && small < 3)
71
+ abort "Please upgrade Ragel! You're on version #{ragel_version_match[0]} and must be on 6.3 or later"
72
+ end
73
+ if (big == 6 && small < 7)
74
+ puts "WARNING: A change to Ruby since 1.9 affects the Ragel generated code."
75
+ puts "WARNING: You MUST be using Ragel version 6.7 or have patched it using"
76
+ puts "WARNING: the patch found at:"
77
+ puts "WARNING: http://www.mail-archive.com/ragel-users@complang.org/msg00440.html"
78
+ end
79
+ end
80
+
81
+ desc "Used to regenerate the AMI source code files. Note: requires Ragel 6.3 or later be installed on your system"
82
+ task :ragel => :check_ragel_version do
83
+ RAGEL_FILES.each do |ragel_file|
84
+ ruby_file = ragel_file.sub(".rl.rb", ".rb")
85
+ puts `ragel -n -R #{ragel_file} -o #{ruby_file} 2>&1`
86
+ raise "Failed generating code from Ragel file #{ragel_file}" if $?.to_i.nonzero?
87
+ end
88
+ end
89
+
90
+ desc "Generates a GraphVis document showing the Ragel state machine"
91
+ task :visualize_ragel => :check_ragel_version do
92
+ RAGEL_FILES.each do |ragel_file|
93
+ base_name = File.basename ragel_file, ".rl.rb"
94
+ puts "ragel -V #{ragel_file} -o #{base_name}.dot 2>&1"
95
+ puts `ragel -V #{ragel_file} -o #{base_name}.dot 2>&1`
96
+ raise "Failed generating code from Ragel file #{ragel_file}" if $?.to_i.nonzero?
97
+ end
98
+ end
99
+
100
+ desc "Run all RSpecs for Theatre"
101
+ RSpec::Core::RakeTask.new(:theatre_specs) do |t|
102
+ t.pattern = FileList[THEATRE_TESTS]
103
+ end
104
+
105
+ desc "Compares Adhearsion's files with those listed in adhearsion.gemspec"
106
+ task :check_gemspec_files do
107
+ files_from_gemspec = ADHEARSION_FILES
108
+ files_from_filesystem = Dir.glob(File.dirname(__FILE__) + "/**/*").map do |filename|
109
+ filename[0...Dir.pwd.length] == Dir.pwd ? filename[(Dir.pwd.length+1)..-1] : filename
110
+ end
111
+ files_from_filesystem.reject! { |f| File.directory? f }
112
+
113
+ puts
114
+ puts 'Pipe this command to "grep -v \'spec/\' | grep -v test" to ignore test files'
115
+ puts
116
+ puts '##########################################'
117
+ puts '## Files on filesystem not in the gemspec:'
118
+ puts '##########################################'
119
+ puts((files_from_filesystem - files_from_gemspec).map { |f| " " + f })
120
+
121
+ puts '##########################################'
122
+ puts '## Files in gemspec not in the filesystem:'
123
+ puts '##########################################'
124
+ puts((files_from_gemspec - files_from_filesystem).map { |f| " " + f })
125
+ end
126
+
127
+ desc "Test that the .gemspec file executes"
128
+ task :debug_gem do
129
+ require 'rubygems/specification'
130
+ gemspec = File.read('adhearsion.gemspec')
131
+ spec = nil
132
+ Thread.new { spec = eval("$SAFE = 3\n#{gemspec}") }.join
133
+ puts "SUCCESS: Gemspec runs at the $SAFE level 3."
134
+ end
@@ -0,0 +1,174 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "adhearsion/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "adhearsion-cw"
7
+ s.version = Adhearsion::VERSION::STRING
8
+
9
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
10
+ s.authors = ["Dawid Pogorzelski"]
11
+
12
+ s.date = Date.today.to_s
13
+ s.description = "Adhearsion-cw is an open-source telephony development framework. This is a fork from the original Adhearsion project http://adhearsion.com"
14
+ s.email = "dawid.pogorzelski@mybushido.com"
15
+ s.executables = ["ahn", "ahnctl", "jahn"]
16
+
17
+ s.files = %w{
18
+ adhearsion.gemspec
19
+ app_generators/ahn/ahn_generator.rb
20
+ app_generators/ahn/templates/.ahnrc
21
+ app_generators/ahn/templates/components/ami_remote/ami_remote.rb
22
+ app_generators/ahn/templates/components/disabled/HOW_TO_ENABLE
23
+ app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.yml
24
+ app_generators/ahn/templates/components/disabled/stomp_gateway/README.markdown
25
+ app_generators/ahn/templates/components/disabled/stomp_gateway/stomp_gateway.rb
26
+ app_generators/ahn/templates/components/disabled/sandbox/sandbox.rb
27
+ app_generators/ahn/templates/components/disabled/sandbox/sandbox.yml
28
+ app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.yml
29
+ app_generators/ahn/templates/components/disabled/restful_rpc/example-client.rb
30
+ app_generators/ahn/templates/components/disabled/restful_rpc/README.markdown
31
+ app_generators/ahn/templates/components/disabled/restful_rpc/restful_rpc.rb
32
+ app_generators/ahn/templates/components/disabled/restful_rpc/spec/restful_rpc_spec.rb
33
+ app_generators/ahn/templates/components/disabled/xmpp_gateway/xmpp_gateway.rb
34
+ app_generators/ahn/templates/components/disabled/xmpp_gateway/xmpp_gateway.yml
35
+ app_generators/ahn/templates/components/disabled/xmpp_gateway/README.markdown
36
+ app_generators/ahn/templates/components/simon_game/simon_game.rb
37
+ app_generators/ahn/templates/config/startup.rb
38
+ app_generators/ahn/templates/dialplan.rb
39
+ app_generators/ahn/templates/events.rb
40
+ app_generators/ahn/templates/Rakefile
41
+ app_generators/ahn/templates/Gemfile
42
+ app_generators/ahn/templates/README
43
+ app_generators/ahn/USAGE
44
+ bin/ahn
45
+ bin/ahnctl
46
+ bin/jahn
47
+ CHANGELOG
48
+ EVENTS
49
+ examples/asterisk_manager_interface/standalone.rb
50
+ lib/adhearsion.rb
51
+ lib/adhearsion/cli.rb
52
+ lib/adhearsion/component_manager.rb
53
+ lib/adhearsion/component_manager/component_tester.rb
54
+ lib/adhearsion/component_manager/spec_framework.rb
55
+ lib/adhearsion/events_support.rb
56
+ lib/adhearsion/foundation/all.rb
57
+ lib/adhearsion/foundation/blank_slate.rb
58
+ lib/adhearsion/foundation/custom_daemonizer.rb
59
+ lib/adhearsion/foundation/event_socket.rb
60
+ lib/adhearsion/foundation/future_resource.rb
61
+ lib/adhearsion/foundation/metaprogramming.rb
62
+ lib/adhearsion/foundation/numeric.rb
63
+ lib/adhearsion/foundation/pseudo_guid.rb
64
+ lib/adhearsion/foundation/relationship_properties.rb
65
+ lib/adhearsion/foundation/string.rb
66
+ lib/adhearsion/foundation/synchronized_hash.rb
67
+ lib/adhearsion/foundation/thread_safety.rb
68
+ lib/adhearsion/host_definitions.rb
69
+ lib/adhearsion/initializer.rb
70
+ lib/adhearsion/initializer/asterisk.rb
71
+ lib/adhearsion/initializer/configuration.rb
72
+ lib/adhearsion/initializer/database.rb
73
+ lib/adhearsion/initializer/ldap.rb
74
+ lib/adhearsion/initializer/drb.rb
75
+ lib/adhearsion/initializer/freeswitch.rb
76
+ lib/adhearsion/initializer/rails.rb
77
+ lib/adhearsion/initializer/xmpp.rb
78
+ lib/adhearsion/logging.rb
79
+ lib/adhearsion/tasks.rb
80
+ lib/adhearsion/tasks/components.rb
81
+ lib/adhearsion/tasks/database.rb
82
+ lib/adhearsion/tasks/deprecations.rb
83
+ lib/adhearsion/tasks/generating.rb
84
+ lib/adhearsion/tasks/lint.rb
85
+ lib/adhearsion/tasks/testing.rb
86
+ lib/adhearsion/version.rb
87
+ lib/adhearsion/voip/asterisk.rb
88
+ lib/adhearsion/voip/asterisk/agi_server.rb
89
+ lib/adhearsion/voip/asterisk/commands.rb
90
+ lib/adhearsion/voip/asterisk/config_generators/agents.conf.rb
91
+ lib/adhearsion/voip/asterisk/config_generators/config_generator.rb
92
+ lib/adhearsion/voip/asterisk/config_generators/queues.conf.rb
93
+ lib/adhearsion/voip/asterisk/config_generators/voicemail.conf.rb
94
+ lib/adhearsion/voip/asterisk/config_manager.rb
95
+ lib/adhearsion/voip/asterisk/manager_interface.rb
96
+ lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rb
97
+ lib/adhearsion/voip/asterisk/manager_interface/ami_lexer.rl.rb
98
+ lib/adhearsion/voip/asterisk/manager_interface/ami_messages.rb
99
+ lib/adhearsion/voip/asterisk/manager_interface/ami_protocol_lexer_machine.rl
100
+ lib/adhearsion/voip/asterisk/special_dial_plan_managers.rb
101
+ lib/adhearsion/voip/asterisk/super_manager.rb
102
+ lib/adhearsion/voip/call.rb
103
+ lib/adhearsion/voip/call_routing.rb
104
+ lib/adhearsion/voip/commands.rb
105
+ lib/adhearsion/voip/constants.rb
106
+ lib/adhearsion/voip/conveniences.rb
107
+ lib/adhearsion/voip/dial_plan.rb
108
+ lib/adhearsion/voip/dsl/dialing_dsl.rb
109
+ lib/adhearsion/voip/dsl/dialing_dsl/dialing_dsl_monkey_patches.rb
110
+ lib/adhearsion/voip/dsl/dialplan/control_passing_exception.rb
111
+ lib/adhearsion/voip/dsl/dialplan/dispatcher.rb
112
+ lib/adhearsion/voip/dsl/dialplan/parser.rb
113
+ lib/adhearsion/voip/dsl/dialplan/thread_mixin.rb
114
+ lib/adhearsion/voip/dsl/numerical_string.rb
115
+ lib/adhearsion/voip/freeswitch/basic_connection_manager.rb
116
+ lib/adhearsion/voip/freeswitch/event_handler.rb
117
+ lib/adhearsion/voip/freeswitch/freeswitch_dialplan_command_factory.rb
118
+ lib/adhearsion/voip/freeswitch/inbound_connection_manager.rb
119
+ lib/adhearsion/voip/freeswitch/oes_server.rb
120
+ lib/adhearsion/voip/menu_state_machine/calculated_match.rb
121
+ lib/adhearsion/voip/menu_state_machine/matchers.rb
122
+ lib/adhearsion/voip/menu_state_machine/menu_builder.rb
123
+ lib/adhearsion/voip/menu_state_machine/menu_class.rb
124
+ lib/adhearsion/xmpp/connection.rb
125
+ lib/theatre.rb
126
+ lib/theatre/callback_definition_loader.rb
127
+ lib/theatre/guid.rb
128
+ lib/theatre/invocation.rb
129
+ lib/theatre/namespace_manager.rb
130
+ lib/theatre/README.markdown
131
+ lib/theatre/version.rb
132
+ LICENSE
133
+ Rakefile
134
+ Gemfile
135
+ }
136
+
137
+ s.has_rdoc = true
138
+ s.homepage = "https://github.com/dawid999/adhearsion-cw"
139
+ s.require_paths = ["lib"]
140
+ s.rubyforge_project = "adhearsion"
141
+ s.rubygems_version = "1.2.0"
142
+ s.summary = "Adhearsion-cw, open-source telephony development framework. This is a fork from the original Adhearsion project http://adhearsion.com"
143
+
144
+ if s.respond_to? :specification_version then
145
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
146
+ s.specification_version = 2
147
+
148
+ if current_version >= 3 then
149
+ # Runtime dependencies
150
+ s.add_runtime_dependency("bundler", [">= 1.0.10"])
151
+ s.add_runtime_dependency("log4r", [">= 1.0.5"])
152
+ s.add_runtime_dependency("activesupport", [">= 2.1.0"])
153
+ # i18n is only strictly a dependency for ActiveSupport >= 3.0.0
154
+ # Since it doesn't conflict with <3.0.0 we'll require it to be
155
+ # on the safe side.
156
+ s.add_runtime_dependency("i18n")
157
+ s.add_runtime_dependency("rubigen", [">= 1.5.6"])
158
+
159
+ # Development dependencies
160
+ s.add_development_dependency('rubigen', [">= 1.5.6"])
161
+ s.add_development_dependency('rspec', [">= 2.4.0"])
162
+ s.add_development_dependency('flexmock')
163
+ s.add_development_dependency('activerecord')
164
+ else
165
+ s.add_dependency("bundler", [">= 1.0.10"])
166
+ s.add_dependency("log4r", [">= 1.0.5"])
167
+ s.add_dependency("activesupport", [">= 2.1.0"])
168
+ end
169
+ else
170
+ s.add_dependency("bundler", [">= 1.0.10"])
171
+ s.add_dependency("log4r", [">= 1.0.5"])
172
+ s.add_dependency("activesupport", [">= 2.1.0"])
173
+ end
174
+ end
@@ -0,0 +1,5 @@
1
+ Description:
2
+
3
+
4
+ Usage:
5
+
@@ -0,0 +1,97 @@
1
+ class AhnGenerator < RubiGen::Base
2
+
3
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
4
+ Config::CONFIG['ruby_install_name'])
5
+
6
+ default_options :author => nil
7
+
8
+ attr_reader :name, :component
9
+
10
+ def initialize(runtime_args, runtime_options = {})
11
+ super
12
+ usage if args.empty?
13
+ @destination_root = File.expand_path(args.shift)
14
+ @name = base_name
15
+ @component = 'simon_game'
16
+ extract_options
17
+ end
18
+
19
+ def manifest
20
+ record do |m|
21
+ # Ensure appropriate folder(s) exists
22
+ m.directory ''
23
+ BASEDIRS.each { |path| m.directory path }
24
+
25
+ m.file *[".ahnrc"]*2
26
+
27
+ m.file *["components/simon_game/simon_game.rb"]*2
28
+ m.file *["components/ami_remote/ami_remote.rb"]*2
29
+
30
+ m.file *["components/disabled/xmpp_gateway/xmpp_gateway.rb"]*2
31
+ m.file *["components/disabled/xmpp_gateway/xmpp_gateway.yml"]*2
32
+ m.file *["components/disabled/xmpp_gateway/README.markdown"]*2
33
+
34
+ m.file *["components/disabled/stomp_gateway/stomp_gateway.rb"]*2
35
+ m.file *["components/disabled/stomp_gateway/stomp_gateway.yml"]*2
36
+ m.file *["components/disabled/stomp_gateway/README.markdown"]*2
37
+
38
+ m.file *["components/disabled/restful_rpc/restful_rpc.rb"]*2
39
+ m.file *["components/disabled/restful_rpc/restful_rpc.yml"]*2
40
+ m.file *["components/disabled/restful_rpc/README.markdown"]*2
41
+ m.file *["components/disabled/restful_rpc/example-client.rb"]*2
42
+ m.file *["components/disabled/restful_rpc/spec/restful_rpc_spec.rb"]*2
43
+
44
+ m.file *["components/disabled/sandbox/sandbox.yml"]*2
45
+ m.file *["components/disabled/sandbox/sandbox.rb"]*2
46
+
47
+ m.file *["config/startup.rb"]*2
48
+ m.file *["dialplan.rb"]*2
49
+ m.file *["events.rb"]*2
50
+ m.file *["README"]*2
51
+ m.file *["Rakefile"]*2
52
+ m.file *["Gemfile"]*2
53
+
54
+ # m.dependency "install_rubigen_scripts", [destination_root, 'ahn', 'adhearsion', 'test_spec'],
55
+ # :shebang => options[:shebang], :collision => :force
56
+ end
57
+ end
58
+
59
+ protected
60
+ def banner
61
+ <<-EOS
62
+ Creates a ...
63
+
64
+ USAGE: #{spec.name} name"
65
+ EOS
66
+ end
67
+
68
+ def add_options!(opts)
69
+ opts.separator ''
70
+ opts.separator 'Options:'
71
+ # For each option below, place the default
72
+ # at the top of the file next to "default_options"
73
+ # opts.on("-a", "--author=\"Your Name\"", String,
74
+ # "Some comment about this option",
75
+ # "Default: none") { |options[:author]| }
76
+ opts.on("-v", "--version", "Show the #{File.basename($0)} version number and quit.")
77
+ end
78
+
79
+ def extract_options
80
+ # for each option, extract it into a local variable (and create an "attr_reader :author" at the top)
81
+ # Templates can access these value via the attr_reader-generated methods, but not the
82
+ # raw instance variable value.
83
+ # @author = options[:author]
84
+ end
85
+
86
+ # Installation skeleton. Intermediate directories are automatically
87
+ # created so don't sweat their absence here.
88
+ BASEDIRS = %w(
89
+ components/simon_game
90
+ components/disabled/stomp_gateway
91
+ components/disabled/xmpp_gateway
92
+ components/disabled/sandbox
93
+ components/ami_remote
94
+ components/disabled/restful_rpc/spec
95
+ config
96
+ )
97
+ end
@@ -0,0 +1,34 @@
1
+ # Adhearsion Runtime Configuration.
2
+
3
+ # You can use the "gems" section to force Adhearsion to load a particular version of a gem.
4
+ # This is useful when a component require()s a gem, but you don't want it to use the latest one installed on the system.
5
+ # For example, if a component require()s activerecord, sucking in the latest on the system, and then you enable a Rails app
6
+ # which wants a particular version of activerecord, RubyGems will raise an error saying "you cannot activate two versions of
7
+ # the same gem". Note: specifying the version, source and require names is optional, but you must include a : after the gem name to make it a YAML key/value pair (with a nil value).
8
+ gems:
9
+ # twitter:
10
+ # hpricot:
11
+ # rack:
12
+ # # require() one library when initializing:
13
+ # require: rack
14
+ # memcache-client:
15
+ # version >= 1.5.2
16
+ # require:
17
+ # # require() an Array of libraries when initializing:
18
+ # - memcache
19
+ # - memcache_util
20
+ # activerecord:
21
+ # version: >= 2.1.0
22
+ # aasm:
23
+ # source: http://gems.github.com
24
+
25
+ paths:
26
+
27
+ # All paths are relative to this file's directory
28
+ init: config/startup.rb
29
+
30
+ dialplan: dialplan.rb
31
+
32
+ events: events.rb
33
+
34
+ models: models/*.rb
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "rake"
4
+ gem "rubigen", ">= 1.0.6"
5
+ gem "log4r", ">= 1.0.5"
6
+ gem "activesupport", ">= 2.1.0"
7
+ gem "adhearsion", ">= 1.0.1"
@@ -0,0 +1,8 @@
1
+ Start your new app with "ahn start /path/to/your/app"
2
+
3
+ If you wish to use Adhearsion to control Asterisk's dialplan,
4
+ change the contexts you wish to be affected in your
5
+ /etc/asterisk/extensions.conf file to the following:
6
+
7
+ [your_context_name]
8
+ exten => _X.,1,AGI(agi://1.2.3.4) ; This IP here
@@ -0,0 +1,27 @@
1
+ # This file is for the "rake" tool which automates project-related tasks. If you need to automate things, you can create
2
+ # a new Rake task here. See http://rake.rubyforge.org for more info.
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ Bundler.setup
6
+ Bundler.require
7
+
8
+ begin
9
+ require 'adhearsion/tasks'
10
+ rescue LoadError
11
+ STDERR.puts "\nCannot load Adhearsion! Not all Rake tasks will be loaded!\n\n"
12
+ end
13
+
14
+ desc "Writes a .gitignore file that ignores certain SCM annoyances such as log files"
15
+ task :gitignore do
16
+ ignore_file = "#{Dir.pwd}/.gitignore"
17
+ if File.exists? ignore_file
18
+ STDERR.puts "File #{ignore_file} already exists!"
19
+ else
20
+ File.open ignore_file, 'w' do |file|
21
+ # Add other files to the Array below
22
+ %w[ log ].each do |pattern|
23
+ file.puts pattern
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ methods_for :rpc do
2
+
3
+ # Simply create proxy methods for the high-level AMI methods
4
+
5
+ [:send_action, :introduce, :originate, :call_into_context, :call_and_exec, :ping].each do |method_name|
6
+ define_method(method_name) do |*args|
7
+ if VoIP::Asterisk.manager_interface
8
+ VoIP::Asterisk.manager_interface.send(method_name, *args)
9
+ else
10
+ ahn_log.ami_remote.error "AMI has not been enabled in startup.rb!"
11
+ end
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,7 @@
1
+ Type "ahn enable component COMPONENT_NAME_FROM_DISABLED_FOLDER
2
+
3
+ For example:
4
+
5
+ ~/Desktop $ ahn create myapp
6
+ ~/Desktop $ cd myapp
7
+ ~/Desktop/myapp $ ahn enable component stomp_gateway
@@ -0,0 +1,11 @@
1
+ Adhearsion RESTful RPC Component
2
+ ================================
3
+
4
+ This is a component for people want to integrate their telephony systems with non-Ruby systems. When enabled, this component
5
+ will start up a HTTP server within the Adhearsion process and accept POST requests to invoke Ruby methods shared in the
6
+ `methods_for(:rpc)` context.
7
+
8
+ Protocol Notes
9
+ --------------
10
+
11
+ When POSTing your data to.
@@ -0,0 +1,48 @@
1
+ require 'rubygems'
2
+ require 'rest_client'
3
+ require 'json'
4
+
5
+ # You must have the "rest-client" and "json" gems installed for this file to work.
6
+
7
+ class RESTfulAdhearsion
8
+
9
+ DEFAULT_OPTIONS = {
10
+ # Note: :user and :password are non-existent by default
11
+ :host => "localhost",
12
+ :port => "5000",
13
+ :path_nesting => "/"
14
+ }
15
+
16
+ def initialize(options={})
17
+ @options = DEFAULT_OPTIONS.merge options
18
+
19
+ @path_nesting = @options.delete :path_nesting
20
+ @host = @options.delete :host
21
+ @port = @options.delete :port
22
+
23
+ @url_beginning = "http://#{@host}:#{@port}#{@path_nesting}"
24
+ end
25
+
26
+ def method_missing(method_name, *args)
27
+ JSON.parse RestClient::Resource.new(@url_beginning + method_name.to_s, @options).post(args.to_json)
28
+ end
29
+
30
+ end
31
+
32
+ Adhearsion = RESTfulAdhearsion.new :host => "localhost", :port => 5000, :user => "jicksta", :password => "roflcopterz"
33
+
34
+ # ### Sample component code. Try doing "ahn create component testing123" and pasting this code in.
35
+ #
36
+ # methods_for :rpc do
37
+ # def i_like_hashes(options={})
38
+ # options.has_key?(:foo)
39
+ # end
40
+ # def i_like_arrays(*args)
41
+ # args.reverse
42
+ # end
43
+ # end
44
+
45
+ # Note: everything returned will be wrapped in an Array
46
+
47
+ p Adhearsion.i_like_hashes(:foo => "bar")
48
+ p Adhearsion.i_like_arrays(1,2,3,4,5)
@@ -0,0 +1,91 @@
1
+ begin
2
+ require 'rack'
3
+ require 'json'
4
+ rescue LoadError
5
+ abort "ERROR: restful_rpc requires the 'rack' and 'json' gems"
6
+ end
7
+
8
+ # Don't you love regular expressions? Matches only 0-255 octets. Recognizes "*" as an octet wildcard.
9
+ VALID_IP_ADDRESS = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|\*)$/
10
+
11
+ def ip_allowed?(ip)
12
+ raise ArgumentError, "#{ip.inspect} is not a valid IP address!" unless ip.kind_of?(String) && ip =~ VALID_IP_ADDRESS
13
+
14
+ octets = ip.split "."
15
+
16
+ case COMPONENTS.restful_rpc["access"]
17
+ when "everyone"
18
+ true
19
+ when "whitelist"
20
+ whitelist = COMPONENTS.restful_rpc["whitelist"]
21
+ !! whitelist.find do |pattern|
22
+ pattern_octets = pattern.split "."
23
+ # Traverse both arrays in parallel
24
+ octets.zip(pattern_octets).map do |octet, octet_pattern|
25
+ octet_pattern == "*" ? true : (octet == octet_pattern)
26
+ end == [true, true, true, true]
27
+ end
28
+ when "blacklist"
29
+ blacklist = COMPONENTS.restful_rpc["blacklist"]
30
+ ! blacklist.find do |pattern|
31
+ pattern_octets = pattern.split "."
32
+ # Traverse both arrays in parallel
33
+ octets.zip(pattern_octets).map do |octet, octet_pattern|
34
+ octet_pattern == "*" ? true : (octet == octet_pattern)
35
+ end == [true, true, true, true]
36
+ end
37
+ else
38
+ raise Adhearsion::Components::ConfigurationError, 'Unrecognized "access" configuration value!'
39
+ end
40
+ end
41
+
42
+ RESTFUL_API_HANDLER = lambda do |env|
43
+ json = env["rack.input"].read
44
+
45
+ # Return "Bad Request" HTTP error if the client forgot
46
+ return [400, {}, "You must POST a valid JSON object!"] if json.blank?
47
+
48
+ json = JSON.parse json
49
+
50
+ nesting = COMPONENTS.restful_rpc["path_nesting"]
51
+ path = env["PATH_INFO"]
52
+
53
+ return [404, {}, "This resource does not respond to #{path.inspect}"] unless path[0...nesting.size] == nesting
54
+
55
+ path = path[nesting.size..-1]
56
+
57
+ return [404, {"Content-Type" => "application/json"}, "You cannot nest method names!"] if path.include?("/")
58
+
59
+ rpc_object = Adhearsion::Components.component_manager.extend_object_with(Object.new, :rpc)
60
+
61
+ # TODO: set the content-type and other HTTP headers
62
+ response_object = rpc_object.send(path, *json)
63
+ [200, {"Content-Type" => "application/json"}, response_object.to_json]
64
+
65
+ end
66
+
67
+ initialization do
68
+ config = COMPONENTS.restful_rpc
69
+
70
+ api = RESTFUL_API_HANDLER
71
+
72
+ port = config["port"] || 5000
73
+ authentication = config["authentication"]
74
+ show_exceptions = config["show_exceptions"]
75
+ handler = Rack::Handler.const_get(config["handler"] || "Mongrel")
76
+
77
+ if authentication
78
+ api = Rack::Auth::Basic.new(api) do |username, password|
79
+ authentication[username] == password
80
+ end
81
+ api.realm = "Adhearsion API"
82
+ end
83
+
84
+ if show_exceptions
85
+ api = Rack::ShowStatus.new(Rack::ShowExceptions.new(api))
86
+ end
87
+
88
+ Thread.new do
89
+ handler.run api, :Port => port
90
+ end
91
+ end