Class: FSR::Cmd::Enum

Inherits:
Command show all
Defined in:
lib/fsr/cmd/enum.rb

Constant Summary

Constants inherited from Command

Command::DEFAULT_OPTIONS

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fs_socket = nil, phone_number = nil) ⇒ Enum

Returns a new instance of Enum.



7
8
9
10
# File 'lib/fsr/cmd/enum.rb', line 7

def initialize(fs_socket = nil, phone_number = nil)
  @fs_socket = fs_socket # FSR::CommandSocket obj
  @ph_nbr = phone_number # phone number to look up, up to 15 digits
end

Instance Attribute Details

#ph_nbrObject (readonly)

Returns the value of attribute ph_nbr.



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

def ph_nbr
  @ph_nbr
end

Instance Method Details

#parse(response) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/fsr/cmd/enum.rb', line 25

def parse(response)
  body = response["body"]
  offered_routes,supported_routes = body.match(/Offered\ Routes:(.*?)Supported\ Routes:(.*?)/mx)[1 .. 2]
  order, pref, service, route = offered_routes.match(/==+\n(.*)/m)[1].split
  unless body == "No Match!"
    require "fsr/model/enum"
    return FSR::Model::Enum.new(offered_routes, supported_routes, order, pref, service, route)
  end
  nil
end

#rawObject

This method builds the API command to send to the freeswitch event socket



21
22
23
# File 'lib/fsr/cmd/enum.rb', line 21

def raw
  orig_command = "enum #{ph_nbr}"
end

#run(api_method = :api) ⇒ Object

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



13
14
15
16
17
18
# File 'lib/fsr/cmd/enum.rb', line 13

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