class Obzvonilka::Asterisk::Voice
Constants
- FILES_PATH
Path to voice files root
- FILE_PATH_TEMPLATE
- HEADINGS
- LOGS_PATH
Path to asterisk CDR logs
- LOG_FIELD_DST
DST field name from Master.csv. Use if real DST wroted in other field (i.e. userfield)
- PREV_FILE_CNT
Amount of old file, then will be checked
- TAIL_COMMAND
Public Class Methods
each_cdr_lines() { |x| ... }
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 47 def self.each_cdr_lines IO.popen(TAIL_COMMAND).each_line { |x| yield x } end
read_cdr_rows() { |parse_cdr_row(chomp)| ... }
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 41 def self.read_cdr_rows each_cdr_lines do |x| yield parse_cdr_row(x.chomp) end end
send_voice(row, file_name)
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 37 def self.send_voice(row, file_name) Obzvonilka::Api::Voice.new.put_voice row[LOG_FIELD_DST], row[:start], row[:end], file_name, row[:astid] end
send_voices()
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 27 def self.send_voices read_cdr_rows do |row| file_name = get_voice_file_name(row) if file_name puts file_name send_voice(row, file_name) end end end
Private Class Methods
check_file_exists(file_name)
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 57 def self.check_file_exists(file_name) Dir[file_name].first end
get_voice_file_name(row, template = FILE_PATH_TEMPLATE)
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 52 def self.get_voice_file_name(row, template = FILE_PATH_TEMPLATE) file_name = make_voice_file_mask(row, template) check_file_exists(file_name) end
make_voice_file_mask(row, template)
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 61 def self.make_voice_file_mask(row, template) process_template(row, template) # "#{FILES_PATH}/#{row[:start].gsub(/^(\d\d\d\d)-(\d\d)-(\d\d).*/, '\\1/\\2/\\3')}/*-#{row[:astid]}.*" end
parse_cdr_row(line)
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 66 def self.parse_cdr_row(line) Hash[HEADINGS.zip(CSV.parse(line).first)] end
process_template(row, template)
click to toggle source
@param [String] template @param [Hash] row @return [String]
# File lib/obzvonilka/asterisk/voice.rb, line 73 def self.process_template(row, template) template.gsub /(%(?:a.|.))/ do |m| case m when '%ai' row[:astid] when '%as' row[:src] when '%ad' row[LOG_FIELD_DST] else row_date(row).strftime(m) end end end
row_date(row)
click to toggle source
# File lib/obzvonilka/asterisk/voice.rb, line 88 def self.row_date(row) date_time = "#{row[:start]}+00:00" utc = DateTime.strptime(date_time, '%Y-%m-%d %H:%M:%S %Z') utc.new_offset(DateTime.now.offset) end