lib/adhearsion/voip/asterisk/manager_interface.rb in adhearsion-0.8.6 vs lib/adhearsion/voip/asterisk/manager_interface.rb in adhearsion-1.0.0
- old
+ new
@@ -36,11 +36,11 @@
RETRY_SLEEP = 5
class << self
def connect(*args)
- returning new(*args) do |connection|
+ new(*args).tap do |connection|
connection.connect!
end
end
def replies_with_action_id?(name, headers={})
@@ -107,11 +107,10 @@
#
# @param [Hash] options Available options are :host, :port, :username, :password, and :events
#
def initialize(options={})
options = parse_options options
-
@host = options[:host]
@username = options[:username]
@password = options[:password]
@port = options[:port]
@events = options[:events]
@@ -306,11 +305,11 @@
# @param [Hash] headers Other key/value pairs to send in this action. Note: don't provide an ActionID
# @raise [ManagerInterfaceError] When Asterisk can't execute this action, it sends back an Error which is converted into an ManagerInterfaceError object and raised. Access ManagerInterfaceError#message for the reported message from Asterisk.
# @return [ManagerInterfaceResponse, ImmediateResponse] Contains the response from Asterisk and all headers
#
def send_action_synchronously(*args)
- returning send_action_asynchronously(*args).response do |response|
+ send_action_asynchronously(*args).response.tap do |response|
raise response if response.kind_of?(ManagerInterfaceError)
end
end
alias send_action send_action_synchronously
@@ -323,11 +322,11 @@
####### #######
# ping sends an action to the Asterisk Manager Interface that returns a pong
# more details here: http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+Ping
def ping
- deprecation_warning
+ #deprecation_warning
send_action "Ping"
true
end
def deprecation_warning
@@ -359,14 +358,17 @@
# originate { :channel => 'SIP/1000@sipnetworks.com',
# :context => 'my_context',
# :exten => 's',
# :priority => '1' }
def originate(options={})
- deprecation_warning
+ #deprecation_warning
options = options.clone
options[:callerid] = options.delete :caller_id if options.has_key? :caller_id
options[:exten] = options.delete :extension if options.has_key? :extension
+ if options[:variables] && options[:variables].kind_of?(Hash)
+ options[:variable] = options[:variables].map {|pair| pair.join('=')}.join(@coreSettings["ArgumentDelimiter"])
+ end
send_action "Originate", options
end
# An introduction connects two endpoints together. The first argument is
# the first person the PBX will call. When she's picked up, Asterisk will
@@ -378,45 +380,44 @@
# technology.
#
# TODO: Provide an example when this works.
#
def introduce(caller, callee, opts={})
- deprecation_warning
+ #deprecation_warning
dial_args = callee
dial_args += "|#{opts[:options]}" if opts[:options]
call_and_exec caller, "Dial", :args => dial_args, :caller_id => opts[:caller_id]
end
# hangup terminates a call accepts a channel as the argument
# full details here: http://www.voip-info.org/wiki/index.php?page=Asterisk+Manager+API+Action+Hangup
def hangup(channel)
- deprecation_warning
+ #deprecation_warning
send_action "Hangup", :channel => channel
end
# call_and_exec allows you to make a call to a channel and then execute an Astersik application
# on that call
def call_and_exec(channel, app, opts={})
- deprecation_warning
+ #deprecation_warning
args = { :channel => channel, :application => app }
args[:caller_id] = opts[:caller_id] if opts[:caller_id]
args[:data] = opts[:args] if opts[:args]
+ args[:variables] = opts[:variables] if opts[:variables]
originate args
end
# call_into_context is syntactic sugar for the Asterisk originate command that allows you to
- # lanuch a call into a particular context. For example:
+ # launch a call into a particular context. For example:
#
# call_into_context('SIP/1000@sipnetworks.com', 'my_context', { :variables => { :session_guid => new_guid }})
def call_into_context(channel, context, options={})
- deprecation_warning
+ #deprecation_warning
args = {:channel => channel, :context => context}
args[:priority] = options[:priority] || 1
args[:exten] = options[:extension] if options[:extension]
args[:caller_id] = options[:caller_id] if options[:caller_id]
- if options[:variables] && options[:variables].kind_of?(Hash)
- args[:variable] = options[:variables].map {|pair| pair.join('=')}.join(@coreSettings["ArgumentDelimiter"])
- end
+ args[:variables] = options[:variables] if options[:variables]
originate args
end
####### #######
########### ###########