jicksta-adhearsion 0.7.999 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +3 -0
- data/adhearsion.gemspec +3 -1
- data/app_generators/ahn/ahn_generator.rb +6 -6
- data/app_generators/ahn/templates/config/startup.rb +1 -4
- data/app_generators/ahn/templates/events.rb +1 -1
- data/lib/adhearsion/component_manager/component_tester.rb +55 -0
- data/lib/adhearsion/version.rb +3 -3
- metadata +3 -1
- data/app_generators/ahn/templates/components/restful_rpc/README.markdown +0 -11
- data/app_generators/ahn/templates/components/restful_rpc/config.yml +0 -34
- data/app_generators/ahn/templates/components/restful_rpc/example-client.rb +0 -48
- data/app_generators/ahn/templates/components/restful_rpc/restful_rpc.rb +0 -87
data/CHANGELOG
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
0.8.0 rev 2
|
2
|
+
- Added a few non-critical files to the .gemspec. They were ignored
|
3
|
+
|
1
4
|
Notes from before 0.8.0:
|
2
5
|
- (NOTE: This is obviously not a comprehensive list of pre-0.8.0 work. 0.8.0 was a complete rewrite of the previous version)
|
3
6
|
- Adding a deprecation warning about Fixnum#digit and Fixnum#digits
|
data/adhearsion.gemspec
CHANGED
@@ -11,6 +11,7 @@ ADHEARSION_FILES = %w{
|
|
11
11
|
app_generators/ahn/templates/components/restful_rpc/example-client.rb
|
12
12
|
app_generators/ahn/templates/components/restful_rpc/README.markdown
|
13
13
|
app_generators/ahn/templates/components/restful_rpc/restful_rpc.rb
|
14
|
+
app_generators/ahn/templates/components/restful_rpc/spec/restful_rpc_spec.rb
|
14
15
|
app_generators/ahn/templates/components/simon_game/simon_game.rb
|
15
16
|
app_generators/ahn/templates/config/startup.rb
|
16
17
|
app_generators/ahn/templates/dialplan.rb
|
@@ -27,6 +28,7 @@ ADHEARSION_FILES = %w{
|
|
27
28
|
lib/adhearsion.rb
|
28
29
|
lib/adhearsion/cli.rb
|
29
30
|
lib/adhearsion/component_manager.rb
|
31
|
+
lib/adhearsion/component_manager/component_tester.rb
|
30
32
|
lib/adhearsion/component_manager/spec_framework.rb
|
31
33
|
lib/adhearsion/events_support.rb
|
32
34
|
lib/adhearsion/foundation/all.rb
|
@@ -109,7 +111,7 @@ ADHEARSION_FILES = %w{
|
|
109
111
|
|
110
112
|
Gem::Specification.new do |s|
|
111
113
|
s.name = "adhearsion"
|
112
|
-
s.version = "0.
|
114
|
+
s.version = "0.8.0"
|
113
115
|
|
114
116
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
115
117
|
s.authors = ["Jay Phillips"]
|
@@ -31,11 +31,11 @@ class AhnGenerator < RubiGen::Base
|
|
31
31
|
m.file *["components/disabled/stomp_gateway/config.yml"]*2
|
32
32
|
m.file *["components/disabled/stomp_gateway/README.markdown"]*2
|
33
33
|
|
34
|
-
m.file *["components/restful_rpc/restful_rpc.rb"]*2
|
35
|
-
m.file *["components/restful_rpc/config.yml"]*2
|
36
|
-
m.file *["components/restful_rpc/README.markdown"]*2
|
37
|
-
m.file *["components/restful_rpc/example-client.rb"]*2
|
38
|
-
m.file *["components/restful_rpc/spec/restful_rpc_spec.rb"]*2
|
34
|
+
m.file *["components/disabled/restful_rpc/restful_rpc.rb"]*2
|
35
|
+
m.file *["components/disabled/restful_rpc/config.yml"]*2
|
36
|
+
m.file *["components/disabled/restful_rpc/README.markdown"]*2
|
37
|
+
m.file *["components/disabled/restful_rpc/example-client.rb"]*2
|
38
|
+
m.file *["components/disabled/restful_rpc/spec/restful_rpc_spec.rb"]*2
|
39
39
|
|
40
40
|
m.file *["config/startup.rb"]*2
|
41
41
|
m.file *["dialplan.rb"]*2
|
@@ -81,7 +81,7 @@ EOS
|
|
81
81
|
components/simon_game
|
82
82
|
components/disabled/stomp_gateway
|
83
83
|
components/ami_remote
|
84
|
-
components/restful_rpc/spec
|
84
|
+
components/disabled/restful_rpc/spec
|
85
85
|
config
|
86
86
|
)
|
87
87
|
end
|
@@ -28,9 +28,6 @@ Adhearsion::Configuration.configure do |config|
|
|
28
28
|
config.enable_asterisk
|
29
29
|
# config.asterisk.enable_ami :host => "127.0.0.1", :username => "admin", :password => "password", :events => true
|
30
30
|
|
31
|
-
# To change the host IP or port on which the AGI server listens, use this:
|
32
|
-
# config.enable_asterisk :listening_port => 4574, :listening_host => "127.0.0.1"
|
33
|
-
|
34
31
|
# config.enable_drb
|
35
32
|
|
36
33
|
# Streamlined Rails integration! The first argument should be a relative or absolute path to
|
@@ -50,4 +47,4 @@ Adhearsion::Configuration.configure do |config|
|
|
50
47
|
# :host => 'db.example.org'
|
51
48
|
end
|
52
49
|
|
53
|
-
Adhearsion::Initializer.start_from_init_file(__FILE__, File.dirname(__FILE__) + "/..")
|
50
|
+
Adhearsion::Initializer.start_from_init_file(__FILE__, File.dirname(__FILE__) + "/..")
|
@@ -12,7 +12,7 @@
|
|
12
12
|
# Asterisk Manager Interface example:
|
13
13
|
#
|
14
14
|
# events.asterisk.manager_interface.each do |event|
|
15
|
-
#
|
15
|
+
# ahn_log.events event.inspect
|
16
16
|
# end
|
17
17
|
#
|
18
18
|
# This assumes you gave :events => true to the config.asterisk.enable_ami method in config/startup.rb
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module ComponentTester
|
2
|
+
|
3
|
+
class << self
|
4
|
+
|
5
|
+
##
|
6
|
+
#
|
7
|
+
#
|
8
|
+
# @return [Module] an anonymous module which includes the ComponentTester module.
|
9
|
+
#
|
10
|
+
def new(component_name, component_directory)
|
11
|
+
component_directory = File.expand_path component_directory
|
12
|
+
main_file = component_directory + "/#{component_name}/#{component_name}.rb"
|
13
|
+
|
14
|
+
component_manager = Adhearsion::Components::ComponentManager.new(component_directory)
|
15
|
+
component_module = Adhearsion::Components::ComponentManager::ComponentDefinitionContainer.load_file main_file
|
16
|
+
|
17
|
+
Module.new do
|
18
|
+
|
19
|
+
extend ComponentTester
|
20
|
+
|
21
|
+
(class << self; self; end).send(:define_method, :component_manager) { component_manager }
|
22
|
+
(class << self; self; end).send(:define_method, :component_name) { component_name }
|
23
|
+
(class << self; self; end).send(:define_method, :component_module) { component_module }
|
24
|
+
(class << self; self; end).send(:define_method, :component_directory) { component_directory }
|
25
|
+
|
26
|
+
|
27
|
+
define_method(:component_manager) { component_manager }
|
28
|
+
define_method(:component_name) { component_name }
|
29
|
+
define_method(:component_module) { component_module }
|
30
|
+
define_method(:component_directory) { component_directory }
|
31
|
+
|
32
|
+
def self.const_missing(name)
|
33
|
+
component_module.const_get name
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def helper_method(name)
|
41
|
+
Object.new.extend(component_module).method(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def config
|
45
|
+
component_manager.configuration_for_component_named component_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def initialize!
|
49
|
+
metadata = component_module.metaclass.send(:instance_variable_get, :@metadata)
|
50
|
+
if metadata && metadata[:initialization_block].kind_of?(Proc)
|
51
|
+
metadata[:initialization_block].call
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
data/lib/adhearsion/version.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Adhearsion #:nodoc:
|
2
2
|
module VERSION #:nodoc:
|
3
|
-
MAJOR = 0
|
4
|
-
MINOR =
|
5
|
-
TINY =
|
3
|
+
MAJOR = 0 unless defined? MAJOR
|
4
|
+
MINOR = 8 unless defined? MINOR
|
5
|
+
TINY = 0 unless defined? TINY
|
6
6
|
|
7
7
|
STRING = [MAJOR, MINOR, TINY].join('.') unless defined? STRING
|
8
8
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jicksta-adhearsion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jay Phillips
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- app_generators/ahn/templates/components/restful_rpc/example-client.rb
|
54
54
|
- app_generators/ahn/templates/components/restful_rpc/README.markdown
|
55
55
|
- app_generators/ahn/templates/components/restful_rpc/restful_rpc.rb
|
56
|
+
- app_generators/ahn/templates/components/restful_rpc/spec/restful_rpc_spec.rb
|
56
57
|
- app_generators/ahn/templates/components/simon_game/simon_game.rb
|
57
58
|
- app_generators/ahn/templates/config/startup.rb
|
58
59
|
- app_generators/ahn/templates/dialplan.rb
|
@@ -69,6 +70,7 @@ files:
|
|
69
70
|
- lib/adhearsion.rb
|
70
71
|
- lib/adhearsion/cli.rb
|
71
72
|
- lib/adhearsion/component_manager.rb
|
73
|
+
- lib/adhearsion/component_manager/component_tester.rb
|
72
74
|
- lib/adhearsion/component_manager/spec_framework.rb
|
73
75
|
- lib/adhearsion/events_support.rb
|
74
76
|
- lib/adhearsion/foundation/all.rb
|
@@ -1,11 +0,0 @@
|
|
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.
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Use path_nesting to specify an arbitrarily nested. Could be used for additional security or in HTTP reverse proxy server.
|
2
|
-
path_nesting: /
|
3
|
-
|
4
|
-
port: 5000
|
5
|
-
|
6
|
-
# The "handler" option here can be any valid Rack::Handler constant name.
|
7
|
-
# Other options: WEBrick, EventedMongrel.
|
8
|
-
# If you don't know the differences between these, "Mongrel" is definitely a good choice.
|
9
|
-
handler: Mongrel
|
10
|
-
|
11
|
-
# In a production system, you should make this "false" since
|
12
|
-
show_exceptions: true
|
13
|
-
|
14
|
-
# The "authentication" config option can either be "false" or key/value pairs representing allowed usernames and passwords.
|
15
|
-
|
16
|
-
#authentication: false
|
17
|
-
authentication:
|
18
|
-
jicksta: roflcopterz
|
19
|
-
foo: bar6213671682
|
20
|
-
|
21
|
-
access: everyone # When allowing "everyone" access, no IPs are blocked.
|
22
|
-
#access: whitelist # When using a whitelist, the "whitelist" data below will be used.
|
23
|
-
#access: blacklist # When using a blacklist, the "blacklist" data below will be used.
|
24
|
-
|
25
|
-
# This is a list of IPs which are exclusively allowed to call this web service.
|
26
|
-
# Note: whitelists are far more secure than blacklists.
|
27
|
-
whitelist:
|
28
|
-
- 127.0.0.1
|
29
|
-
- 192.168.*.*
|
30
|
-
|
31
|
-
# This is a list of the IPs which are explicitly NOT allowed to call this web service. This will only be used if "access" is
|
32
|
-
# set to "blacklist" above.
|
33
|
-
blacklist:
|
34
|
-
- 100.200.100.200
|
@@ -1,48 +0,0 @@
|
|
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)
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require 'rack'
|
2
|
-
require 'json'
|
3
|
-
|
4
|
-
# Don't you love regular expressions? Matches only 0-255 octets. Recognizes "*" as an octet wildcard.
|
5
|
-
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]?|\*)$/
|
6
|
-
|
7
|
-
def ip_allowed?(ip)
|
8
|
-
raise ArgumentError, "#{ip.inspect} is not a valid IP address!" unless ip.kind_of?(String) && ip =~ VALID_IP_ADDRESS
|
9
|
-
|
10
|
-
octets = ip.split "."
|
11
|
-
|
12
|
-
case COMPONENTS.restful_rpc["access"]
|
13
|
-
when "everyone"
|
14
|
-
true
|
15
|
-
when "whitelist"
|
16
|
-
whitelist = COMPONENTS.restful_rpc["whitelist"]
|
17
|
-
!! whitelist.find do |pattern|
|
18
|
-
pattern_octets = pattern.split "."
|
19
|
-
# Traverse both arrays in parallel
|
20
|
-
octets.zip(pattern_octets).map do |octet, octet_pattern|
|
21
|
-
octet_pattern == "*" ? true : (octet == octet_pattern)
|
22
|
-
end == [true, true, true, true]
|
23
|
-
end
|
24
|
-
when "blacklist"
|
25
|
-
blacklist = COMPONENTS.restful_rpc["blacklist"]
|
26
|
-
! blacklist.find do |pattern|
|
27
|
-
pattern_octets = pattern.split "."
|
28
|
-
# Traverse both arrays in parallel
|
29
|
-
octets.zip(pattern_octets).map do |octet, octet_pattern|
|
30
|
-
octet_pattern == "*" ? true : (octet == octet_pattern)
|
31
|
-
end == [true, true, true, true]
|
32
|
-
end
|
33
|
-
else
|
34
|
-
raise Adhearsion::Components::ConfigurationError, 'Unrecognized "access" configuration value!'
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
RESTFUL_API_HANDLER = lambda do |env|
|
39
|
-
json = env["rack.input"].read
|
40
|
-
|
41
|
-
# Return "Bad Request" HTTP error if the client forgot
|
42
|
-
return [400, {}, "You must POST a valid JSON object!"] if json.blank?
|
43
|
-
|
44
|
-
json = JSON.parse json
|
45
|
-
|
46
|
-
nesting = COMPONENTS.restful_rpc["path_nesting"]
|
47
|
-
path = env["PATH_INFO"]
|
48
|
-
|
49
|
-
return [404, {}, "This resource does not respond to #{path.inspect}"] unless path[0...nesting.size] == nesting
|
50
|
-
|
51
|
-
path = path[nesting.size..-1]
|
52
|
-
|
53
|
-
return [404, {"Content-Type" => "application/json"}, "You cannot nest method names!"] if path.include?("/")
|
54
|
-
|
55
|
-
rpc_object = Adhearsion::Components.component_manager.extend_object_with(Object.new, :rpc)
|
56
|
-
|
57
|
-
# TODO: set the content-type and other HTTP headers
|
58
|
-
response_object = Array rpc_object.send(path, *json)
|
59
|
-
[200, {"Content-Type" => "application/json"}, response_object.to_json]
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
initialization do
|
64
|
-
config = COMPONENTS.restful_rpc
|
65
|
-
|
66
|
-
api = RESTFUL_API_HANDLER
|
67
|
-
|
68
|
-
port = config["port"] || 5000
|
69
|
-
authentication = config["authentication"]
|
70
|
-
show_exceptions = config["show_exceptions"]
|
71
|
-
handler = Rack::Handler.const_get(config["handler"] || "Mongrel")
|
72
|
-
|
73
|
-
if authentication
|
74
|
-
api = Rack::Auth::Basic.new(api) do |username, password|
|
75
|
-
authentication[username] == password
|
76
|
-
end
|
77
|
-
api.realm = "Adhearsion API"
|
78
|
-
end
|
79
|
-
|
80
|
-
if show_exceptions
|
81
|
-
api = Rack::ShowStatus.new(Rack::ShowExceptions.new(api))
|
82
|
-
end
|
83
|
-
|
84
|
-
Thread.new do
|
85
|
-
handler.run api, :Port => port
|
86
|
-
end
|
87
|
-
end
|