class Pabx::Response
Attributes
action_id[RW]
data[RW]
message[RW]
success[RW]
type[RW]
Public Class Methods
new(type,response)
click to toggle source
# File lib/pabx/response.rb, line 5 def initialize(type,response) self.type = type self.success = self._parse_successfull(response) self.action_id = self._parse_action_id(response) self.message = self._parse_message(response) self.data = self._parse_data(response) end
Protected Instance Methods
_convert_status(_data)
click to toggle source
# File lib/pabx/response.rb, line 73 def _convert_status(_data) _data[:hints].each do |hint| case hint["Status"] when "-1" hint["DescriptiveStatus"] = "Extension not found" when "0" hint["DescriptiveStatus"] = "Idle" when "1" hint["DescriptiveStatus"] = "In Use" when "2" hint["DescriptiveStatus"] = "Busy" when "4" hint["DescriptiveStatus"] = "Unavailable" when "8" hint["DescriptiveStatus"] = "Ringing" when "16" hint["DescriptiveStatus"] = "On Hold" end end _data end
_parse(response,field)
click to toggle source
# File lib/pabx/response.rb, line 27 def _parse(response,field) _value = nil response.each_line do |line| if line.start_with?(field) _value = line[line.rindex(":")+1..line.size].strip end end _value end
_parse_action_id(response)
click to toggle source
# File lib/pabx/response.rb, line 19 def _parse_action_id(response) _action_id = self._parse(response,"ActionID:") end
_parse_data(response)
click to toggle source
# File lib/pabx/response.rb, line 37 def _parse_data(response) case self.type when "CoreShowChannels" self._parse_data_core_show_channels(response) when "ParkedCalls" self._parse_data_parked_calls(response) when "Originate" self._parse_originate(response) when "MeetMeList" self._parse_meet_me_list(response) when "ExtensionState" self._parse_extension_state(response) end end
_parse_data_core_show_channels(response)
click to toggle source
# File lib/pabx/response.rb, line 64 def _parse_data_core_show_channels(response) self._parse_objects(response,:channels,"Event: CoreShowChannel","Event: CoreShowChannelsComplete") end
_parse_data_parked_calls(response)
click to toggle source
# File lib/pabx/response.rb, line 60 def _parse_data_parked_calls(response) self._parse_objects(response,:calls,"Event: ParkedCall") end
_parse_extension_state(response)
click to toggle source
# File lib/pabx/response.rb, line 68 def _parse_extension_state(response) _data = self._parse_objects(response,:hints,"Response:") self._convert_status(_data) end
_parse_meet_me_list(response)
click to toggle source
# File lib/pabx/response.rb, line 52 def _parse_meet_me_list(response) self._parse_objects(response,:rooms,"Event: MeetmeList") end
_parse_message(response)
click to toggle source
# File lib/pabx/response.rb, line 23 def _parse_message(response) _message = self._parse(response,"Message:") end
_parse_objects(response,symbol_name,search_for,stop_with=nil)
click to toggle source
# File lib/pabx/response.rb, line 95 def _parse_objects(response,symbol_name,search_for,stop_with=nil) _data = { symbol_name => [] } parsing = false object = nil response.each_line do |line| if line.strip.empty? or (!stop_with.nil? and line.start_with?(stop_with)) parsing = false elsif line.start_with?(search_for) _data[symbol_name] << object unless object.nil? object = {} parsing = true elsif parsing object[line.split(':')[0].strip]=line.split(':')[1].strip unless line.split(':')[1].nil? end end _data[symbol_name] << object unless object.nil? _data end
_parse_originate(response)
click to toggle source
# File lib/pabx/response.rb, line 56 def _parse_originate(response) self._parse_objects(response,:dial,"Event: Dial") end
_parse_successfull(response)
click to toggle source
# File lib/pabx/response.rb, line 15 def _parse_successfull(response) response.include?("Response: Success") end