class TS3Query::TS3Connection
Public Class Methods
new(params)
click to toggle source
# File lib/ts3query/ts3_connection.rb, line 9 def initialize(params) connect(params) end
Public Instance Methods
disconnect()
click to toggle source
# File lib/ts3query/ts3_connection.rb, line 13 def disconnect @connection.close end
method_missing(meth, *args) { |query_options| ... }
click to toggle source
# File lib/ts3query/ts3_connection.rb, line 17 def method_missing(meth, *args, &block) buffer = StringIO.new result = [] options = '' params = '' if block query_options = QueryOptions.new yield query_options query_options.options.each do |opt| options += " -#{opt}" end end if args.first args.first.each do |key, value| params += " #{key}=#{value.is_a?(String) ? Escaping.encode(value) : value}" end end @connection.cmd('String' => "#{meth}#{params}#{options}\r", 'Match' => /error id=0 msg=ok\n/, 'Timeout' => 3) do |data| buffer << data end data = buffer.string data.force_encoding 'UTF-8' data.split('|').each do |current| current_data = {} current.split(' ').each do |entity| key, value = entity.split '=' current_data[key] = value.is_a?(String) ? Escaping.decode(value) : nil end current_data.delete('error') current_data.delete('id') current_data.delete('msg') result << current_data end result << {'id' => '0', 'msg' => 'ok'} result.delete({}) result end