Class: FSR::Cmd::Originate
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#fs_socket ⇒ Object
readonly
Returns the value of attribute fs_socket.
-
#target ⇒ Object
Returns the value of attribute target.
-
#target_options ⇒ Object
readonly
Returns the value of attribute target_options.
Instance Method Summary collapse
-
#initialize(fs_socket = nil, args = {}) ⇒ Originate
constructor
A new instance of Originate.
-
#raw ⇒ Object
This method builds the API command to send to the freeswitch event socket.
-
#run(api_method = :bgapi) ⇒ Object
Send the command to the event socket, using bgapi by default.
Constructor Details
#initialize(fs_socket = nil, args = {}) ⇒ Originate
Returns a new instance of Originate.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/fsr/cmd/originate.rb', line 8 def initialize(fs_socket = nil, args = {}) # These are options that will precede the target address @target_options = args[:target_options] || {:ignore_early_media => true} raise "#{@target_options} must be a hash" unless @target_options.kind_of?(Hash) @fs_socket = fs_socket # This socket must support say and << @target = args[:target] # The target address to call # The origination endpoint (can be an extension (use a string) or application) @endpoint = args[:endpoint] || args[:application] @target_options[:origination_caller_id_number] ||= args[:caller_id_number] || FSR::DEFAULT_CALLER_ID_NUMBER @target_options[:origination_caller_id_name] ||= args[:caller_id_name] || FSR::DEFAULT_CALLER_ID_NAME @target_options[:originate_timeout] ||= args[:timeout] || @target_options[:timeout] || 30 @target_options[:ignore_early_media] ||= true end |
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/fsr/cmd/originate.rb', line 5 def endpoint @endpoint end |
#fs_socket ⇒ Object (readonly)
Returns the value of attribute fs_socket.
6 7 8 |
# File 'lib/fsr/cmd/originate.rb', line 6 def fs_socket @fs_socket end |
#target ⇒ Object
Returns the value of attribute target.
5 6 7 |
# File 'lib/fsr/cmd/originate.rb', line 5 def target @target end |
#target_options ⇒ Object (readonly)
Returns the value of attribute target_options.
6 7 8 |
# File 'lib/fsr/cmd/originate.rb', line 6 def @target_options end |
Instance Method Details
#raw ⇒ Object
This method builds the API command to send to the freeswitch event socket
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/fsr/cmd/originate.rb', line 32 def raw target_opts = @target_options.keys.sort { |a,b| a.to_s <=> b.to_s }.map { |k| "%s=%s" % [k, @target_options[k]] }.join(",") if @endpoint.kind_of?(String) orig_command = "originate {#{target_opts}}#{@target} #{@endpoint}" elsif @endpoint.kind_of?(FSR::App::Application) orig_command = "originate {#{target_opts}}#{@target} '&#{@endpoint.raw}'" else raise "Invalid endpoint" end end |
#run(api_method = :bgapi) ⇒ Object
Send the command to the event socket, using bgapi by default.
25 26 27 28 29 |
# File 'lib/fsr/cmd/originate.rb', line 25 def run(api_method = :bgapi) orig_command = "%s %s" % [api_method, raw] Log.debug "saying #{orig_command}" @fs_socket.say(orig_command) end |