ts3query 0.4.2 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/ts3query/ts3_connection.rb +19 -16
  2. metadata +1 -1
@@ -4,29 +4,31 @@ class TS3Connection
4
4
  def initialize(params)
5
5
  connect(params)
6
6
  end
7
-
7
+
8
8
  def disconnect
9
9
  @connection.close
10
10
  end
11
-
11
+
12
12
  def method_missing(meth, *args, &block)
13
13
  result = []
14
14
  options = ""
15
15
  params = ""
16
-
16
+
17
17
  if block
18
18
  query_options = QueryOptions.new
19
19
  yield query_options
20
-
20
+
21
21
  query_options.options.each do |opt|
22
22
  options += " -#{opt}"
23
23
  end
24
24
  end
25
25
 
26
- args.each do |param|
27
- params += " #{param.keys[0]}=#{param[param.keys[0]]}"
26
+ if args.first
27
+ args.first.each do |key, value|
28
+ params += " #{key}=#{value}"
29
+ end
28
30
  end
29
-
31
+
30
32
  @connection.cmd("String" => "#{meth}#{params}#{options}\r",
31
33
  "Match" => /error id=0 msg=ok\n/,
32
34
  "Timeout" => 3) { |data|
@@ -38,7 +40,7 @@ class TS3Connection
38
40
  current_data.delete("error")
39
41
  current_data.delete("id")
40
42
  current_data.delete("msg")
41
-
43
+
42
44
  result << current_data
43
45
  end
44
46
  }
@@ -46,10 +48,10 @@ class TS3Connection
46
48
  result.delete({})
47
49
  result
48
50
  end
49
-
51
+
50
52
  private
51
-
52
- def connect(params)
53
+
54
+ def connect(params)
53
55
  begin
54
56
  @connection = Net::Telnet::new("Host" => params[:address], "Port" => params[:port])
55
57
  @connection.waitfor("Match" => /TS3\n(.*)\n/,
@@ -57,10 +59,11 @@ class TS3Connection
57
59
  rescue
58
60
  raise ConnectionRefused, "server not available"
59
61
  end
60
-
62
+
61
63
  begin
62
- @connection.cmd("String" => "login client_login_name=#{params[:username]} client_login_password=#{params[:password]}\r",
63
- "Match" => /error id=0 msg=ok\n/)
64
+ @connection.cmd("String" => "login client_login_name=#{params[:username]} client_login_password=#{params[:password]}\r",
65
+ "Match" => /error id=0 msg=ok\n/,
66
+ "Timeout" => 3)
64
67
  rescue
65
68
  raise ConnectionRefused, "wrong user data"
66
69
  end
@@ -71,11 +74,11 @@ class QueryOptions
71
74
  def initialize
72
75
  @options = []
73
76
  end
74
-
77
+
75
78
  def method_missing(meth, *args, &block)
76
79
  options << meth.to_s
77
80
  end
78
-
81
+
79
82
  def options
80
83
  @options
81
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ts3query
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: '0.5'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: