Class: FSR::Cmd::Originate
Constant Summary
Constants inherited from Command
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 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/fsr/cmd/originate.rb', line 8 def initialize(fs_socket = nil, args = {}) # Using an argument hash may not be the the best way to go here, but as long as we're doing # so we'll type check it raise(ArgumentError, "args (Passed: <<<#{args}>>>) must be a hash") unless args.kind_of?(Hash) # These are options that will precede the target address if args[:target_options] raise(ArgumentError, "args[:target_options] (Passed: <<<#{args[:target_options]}>>>) must be a hash") unless args[:target_options].kind_of?(Hash) else args[:target_options] = {} end @target_options = (args[:target_options]) do |o| o[:origination_caller_id_number] = args[:caller_id_number] if args[:caller_id_number] o[:origination_caller_id_name] = args[:caller_id_name] if args[:caller_id_name] if o[:timeout] o[:originate_timeout] = o.delete(:timeout) elsif args[:timeout] o[:originate_timeout] = args[:timeout] end o end raise(ArgumentError, "Origination timeout (#{@target_options[:originate_timeout]}) must be a positive integer") unless @target_options[:originate_timeout].to_i > 0 @fs_socket = fs_socket # This socket must support say and << @target = args[:target] # The target address to call raise(ArgumentError, "Cannot originate without a :target set") unless @target.to_s.size > 0 # The origination endpoint (can be an extension (use a string) or application) @endpoint = args[:endpoint] || args[:application] raise(ArgumentError, "Cannot originate without an :endpoint set") unless @endpoint.to_s.size > 0 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
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fsr/cmd/originate.rb', line 48 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.
41 42 43 44 45 |
# File 'lib/fsr/cmd/originate.rb', line 41 def run(api_method = :bgapi) orig_command = "%s %s" % [api_method, raw] Log.debug "saying #{orig_command}" @fs_socket.say(orig_command) end |