Class: FSR::Cmd::Conference

Inherits:
Command
  • Object
show all
Defined in:
lib/fsr/cmd/conference.rb

Constant Summary

Constants inherited from Command

FSR::Cmd::Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_socket = nil, args = {}) ⇒ Conference

Returns a new instance of Conference.

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/fsr/cmd/conference.rb', line 6

def initialize(fs_socket = nil, args = {})
  raise(ArgumentError, "args (Passed: <<<#{args}>>>) must be a hash") unless args.kind_of?(Hash)
  @conference_name, @pin, @profile, @flags = args.values_at(:conference_name, :pin, :profile, :flags)
  @action, @target, @target_options = args.values_at(:action, :target, :target_options)
  @digits = args[:digits]
  @fs_socket = fs_socket
  raise(ArgumentError, "Cannot use conference without :conference_name") unless conference_name
  case @action
    when :dial
      raise(ArgumentError, "Cannot dial without :target") unless target
      if @target_options
        raise(ArgumentError, ":target_options must be a hash") unless target_options.kind_of?(Hash)
      end
    when :dtmf
      raise(ArgumentError, "Cannot send dtmf without :target") unless target
      raise(ArgumentError, "Cannot send dtmf without :digits") unless digits
    when :kick
      raise(ArgumentError, "Cannot kick without :target") unless target
    else
      # go with flow, mate
  end
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def action
  @action
end

#conference_nameObject (readonly)

Returns the value of attribute conference_name.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def conference_name
  @conference_name
end

#digitsObject (readonly)

Returns the value of attribute digits.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def digits
  @digits
end

#flagsObject (readonly)

Returns the value of attribute flags.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def flags
  @flags
end

#fs_socketObject (readonly)

Returns the value of attribute fs_socket.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def fs_socket
  @fs_socket
end

#pinObject (readonly)

Returns the value of attribute pin.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def pin
  @pin
end

#profileObject (readonly)

Returns the value of attribute profile.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def profile
  @profile
end

#targetObject (readonly)

Returns the value of attribute target.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def target
  @target
end

#target_optionsObject (readonly)

Returns the value of attribute target_options.



5
6
7
# File 'lib/fsr/cmd/conference.rb', line 5

def target_options
  @target_options
end

Instance Method Details

#argumentsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fsr/cmd/conference.rb', line 36

def arguments
  target_options = @target_options.keys.sort { |a,b| a.to_s <=> b.to_s }.map { |k| "%s=%s" % [k, @target_options[k]] }.join(",") if @target_options
  conference_name << "@#{profile}" if profile
  conference_name << "+#{pin}" if pin
  conference_name << "+#{flags}" if flags
  args = [conference_name]
  args << action if action

  if target
    @target = "{#{target_options}}#{target}" if target_options
    args << target
  end

  args << digits if action == :dtmf
  args.compact
end

#rawObject



53
54
55
# File 'lib/fsr/cmd/conference.rb', line 53

def raw
  ["conference", *arguments].join(" ")
end

#run(api_method = :bgapi) ⇒ Object

Send the command to the event socket, using bgapi by default.



30
31
32
33
34
# File 'lib/fsr/cmd/conference.rb', line 30

def run(api_method = :bgapi)
  conf_command = "%s %s" % [api_method, raw]
  Log.debug "saying #{conf_command}"
  @fs_socket.say(conf_command)
end