Class: FSR::Cmd::Originate
Constant Summary
Constants inherited from Command
Instance Attribute Summary (collapse)
-
- (Object) endpoint
Returns the value of attribute endpoint.
-
- (Object) fs_socket
readonly
Returns the value of attribute fs_socket.
-
- (Object) target
Returns the value of attribute target.
-
- (Object) target_options
readonly
Returns the value of attribute target_options.
Instance Method Summary (collapse)
-
- (Originate) initialize(fs_socket = nil, args = {})
constructor
A new instance of Originate.
-
- (Object) raw
This method builds the API command to send to the freeswitch event socket.
-
- (Object) run(api_method = :bgapi)
Send the command to the event socket, using bgapi by default.
Methods inherited from Command
Constructor Details
- (Originate) initialize(fs_socket = nil, args = {})
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 = (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 [: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
- (Object) endpoint
Returns the value of attribute endpoint
5 6 7 |
# File 'lib/fsr/cmd/originate.rb', line 5 def endpoint @endpoint end |
- (Object) fs_socket (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 |
- (Object) target
Returns the value of attribute target
5 6 7 |
# File 'lib/fsr/cmd/originate.rb', line 5 def target @target end |
- (Object) target_options (readonly)
Returns the value of attribute target_options
6 7 8 |
# File 'lib/fsr/cmd/originate.rb', line 6 def end |
Instance Method Details
- (Object) raw
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 = .keys.sort { |a,b| a.to_s <=> b.to_s }.map { |k| "%s=%s" % [k, [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 |
- (Object) run(api_method = :bgapi)
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 |