Class: TS3Query::TS3Connection
- Inherits:
-
Object
- Object
- TS3Query::TS3Connection
- Defined in:
- lib/ts3query/ts3_connection.rb
Direct Known Subclasses
Instance Method Summary collapse
- #disconnect ⇒ Object
-
#initialize(params) ⇒ TS3Connection
constructor
A new instance of TS3Connection.
- #method_missing(meth, *args, &block) ⇒ Object
Constructor Details
#initialize(params) ⇒ TS3Connection
Returns a new instance of TS3Connection.
9 10 11 |
# File 'lib/ts3query/ts3_connection.rb', line 9 def initialize(params) connect(params) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ts3query/ts3_connection.rb', line 17 def method_missing(meth, *args, &block) buffer = StringIO.new result = [] = '' params = '' if block = QueryOptions.new yield ..each do |opt| += " -#{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 |
Instance Method Details
#disconnect ⇒ Object
13 14 15 |
# File 'lib/ts3query/ts3_connection.rb', line 13 def disconnect @connection.close end |