ts3query 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "rspec", "~> 2.10.0"
5
+ gem "rdoc", "~> 3.12"
6
+ gem "cucumber", "~> 1.2.0"
7
+ gem "jeweler", "~> 1.8.3"
8
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 TnT Web Solutions GbR
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,47 @@
1
+ = TS3Query
2
+
3
+ == Install
4
+
5
+ In <b>Rails 3</b>, add this to your Gemfile and run the +bundle+ command.
6
+
7
+ gem "ts3query"
8
+
9
+ == Getting Started
10
+
11
+ === Connecting to a Teamspeak 3 Server
12
+
13
+ @query = TS3Query.connect :address => "your-address.com" # default => 127.0.0.1
14
+ :port => 1234 # default => 10011
15
+ :username => "myqueryuser" # default => serveradmin
16
+ :password => "myquerypassword"
17
+
18
+ This will raise an +ConnectionRefused+ error, if the server does not response or the data are wrong.
19
+
20
+ === Executing query commands
21
+
22
+ This retuns a result hash with all server informations.
23
+
24
+ result = @query.version()
25
+
26
+ This will return a hash with the serverlist. (Options -uid and -short)
27
+
28
+ result = @query.serverlist do |opt|
29
+ opt.uid
30
+ opt.short
31
+ end
32
+
33
+ == Contributing to TS3Query
34
+
35
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
36
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
37
+ * Fork the project.
38
+ * Start a feature/bugfix branch.
39
+ * Commit and push until you are happy with your contribution.
40
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
41
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
42
+
43
+ == Copyright
44
+
45
+ Copyright (c) 2012 TnT Web Solutions GbR. See LICENSE.txt for
46
+ further details.
47
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "TS3Query"
18
+ gem.homepage = "http://github.com/tbraun89/TS3Query"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{TODO: one-line summary of your gem}
21
+ gem.description = %Q{TODO: longer description of your gem}
22
+ gem.email = "tbraun@stud.hs-heilbronn.de"
23
+ gem.authors = ["Torsten Braun"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ require 'cucumber/rake/task'
40
+ Cucumber::Rake::Task.new(:features)
41
+
42
+ task :default => :spec
43
+
44
+ require 'rdoc/task'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "TS3Query #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
@@ -0,0 +1,19 @@
1
+ Feature: Connect with a teamspeak server
2
+ In order to connect to the server
3
+ As an application
4
+ I want to establish a connection and check the server version
5
+
6
+ Scenario: Establish a connection
7
+ Given I have the server address 127.0.0.1 and the query port 10011
8
+ When I enter the username serveradmin with the password 0L8awVFD
9
+ Then I should get a connection with valid response
10
+
11
+ Scenario: Try to establish a connection with wrong server data
12
+ Given I have the server address 127.0.0.1 and the query port 11100
13
+ When I enter the username serveradmin with the password 0L8awVFD
14
+ Then I should get a connection refused error: server not available
15
+
16
+ Scenario: Try to establish a connection with wrong user data
17
+ Given I have the server address 127.0.0.1 and the query port 10011
18
+ When I enter the username serveradmin with the password 903jsdp
19
+ Then I should get a connection refused error: wrong user data
@@ -0,0 +1,14 @@
1
+ Feature: Run a query command
2
+ In order to run a command
3
+ As an application
4
+ I want to use a method after connection to the server
5
+
6
+ Scenario: Run 'version' command
7
+ Given I am connected to the default server with the password 0L8awVFD
8
+ When I run the command version
9
+ Then I should get a hash with version=3.0.5 build=1335156372 platform=Linux id=0 msg=ok
10
+
11
+ Scenario: Run 'serverlist' command with options
12
+ Given I am connected to the default server with the password 0L8awVFD
13
+ When I run the command serverlist with the options -uid -short
14
+ Then I should get a hash with virtualserver_id=1 virtualserver_port=9987 virtualserver_status=online id=0 msg=ok
@@ -0,0 +1,30 @@
1
+ Given /^I have the server address (.+) and the query port (.+)$/ do |address, port|
2
+ @address = address
3
+ @port = port
4
+ end
5
+
6
+ When /^I enter the username (.+) with the password (.+)$/ do |username, password|
7
+ @username = username
8
+ @password = password
9
+ end
10
+
11
+ Then /^I should get a connection with valid response$/ do
12
+ expect {
13
+ @query = TS3Query.connect :address => @address,
14
+ :port => @port,
15
+ :username => @username,
16
+ :password => @password
17
+
18
+ @query.should be_kind_of(TS3Connection)
19
+ @query.disconnect
20
+ }.should_not raise_error
21
+ end
22
+
23
+ Then /^I should get a connection refused error: (.+)$/ do |error_msg|
24
+ expect {
25
+ @query = TS3Query.connect :address => @address,
26
+ :port => @port,
27
+ :username => @username,
28
+ :password => @password
29
+ }.should raise_error(ConnectionRefused) { |error| error.message.should == error_msg }
30
+ end
@@ -0,0 +1,26 @@
1
+ Given /^I am connected to the default server with the password (.+)$/ do |password|
2
+ @query = TS3Query.connect :password => password
3
+ end
4
+
5
+ When /^I run the command version$/ do
6
+ @result = @query.version()
7
+ end
8
+
9
+ When /^I run the command serverlist with the options (.+)$/ do |options|
10
+ options = options.split(" ")
11
+ @result = @query.serverlist do |opt|
12
+ options.each do |current|
13
+ current[0] = ""
14
+ opt.send(current)
15
+ end
16
+ end
17
+ end
18
+
19
+ Then /^I should get a hash with (.+)$/ do |data|
20
+ hash = {}
21
+ data.split(" ").each do |entity|
22
+ hash[entity.split("=")[0]] = entity.split("=")[1]
23
+ end
24
+
25
+ @result.should eq(hash)
26
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler'
2
+ begin
3
+ Bundler.setup(:default, :development)
4
+ rescue Bundler::BundlerError => e
5
+ $stderr.puts e.message
6
+ $stderr.puts "Run `bundle install` to install missing gems"
7
+ exit e.status_code
8
+ end
9
+
10
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
11
+ require 'TS3Query'
12
+
13
+ require 'rspec/expectations'
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ts3query'
data/lib/TS3Query.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'ts3query/ts3_connection'
2
+
3
+ module TS3Query
4
+
5
+ def self.connect(params = {})
6
+ params = {
7
+ :address => "127.0.0.1",
8
+ :port => "10011",
9
+ :username => "serveradmin"
10
+ }.merge(params)
11
+
12
+ TS3Connection.new params
13
+ end
14
+
15
+ end
@@ -0,0 +1,69 @@
1
+ require 'net/telnet'
2
+
3
+ class TS3Connection
4
+ def initialize(params)
5
+ connect(params)
6
+ end
7
+
8
+ def disconnect
9
+ @connection.close
10
+ end
11
+
12
+ def method_missing(meth, *args, &block)
13
+ result = {}
14
+ options = ""
15
+
16
+ if block
17
+ query_options = QueryOptions.new
18
+ yield query_options
19
+
20
+ query_options.options.each do |opt|
21
+ options += " -#{opt}"
22
+ end
23
+ end
24
+
25
+ @connection.cmd("String" => "#{meth}#{options}\r",
26
+ "Match" => /error id=0 msg=ok\n/) { |data|
27
+ data.split(" ").each do |entity|
28
+ result[entity.split("=")[0]] = entity.split("=")[1]
29
+ end
30
+ result.delete("error")
31
+ }
32
+ result
33
+ end
34
+
35
+ private
36
+
37
+ def connect(params)
38
+ begin
39
+ @connection = Net::Telnet::new("Host" => params[:address], "Port" => params[:port])
40
+ @connection.waitfor(/TS3\n(.*)\n/)
41
+ rescue
42
+ raise ConnectionRefused, "server not available"
43
+ end
44
+
45
+ begin
46
+ @connection.cmd("String" => "login client_login_name=#{params[:username]} client_login_password=#{params[:password]}\r",
47
+ "Match" => /error id=0 msg=ok\n/)
48
+ rescue
49
+ raise ConnectionRefused, "wrong user data"
50
+ end
51
+ end
52
+ end
53
+
54
+ class QueryOptions
55
+ def initialize
56
+ @options = []
57
+ end
58
+
59
+ def method_missing(meth, *args, &block)
60
+ options << meth.to_s
61
+ end
62
+
63
+ def options
64
+ @options
65
+ end
66
+ end
67
+
68
+ class ConnectionRefused < StandardError
69
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ts3query
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - TnT Web Solutions
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Simple TS3 Query Library to connect to the query port of a teamspeak
15
+ 3 server.
16
+ email: support@tnt-web-solutions.de
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/ts3query/ts3_connection.rb
22
+ - lib/TS3Query.rb
23
+ - features/run_command.feature
24
+ - features/support/env.rb
25
+ - features/step_definitions/run_command_steps.rb
26
+ - features/step_definitions/connection_steps.rb
27
+ - features/connect_to_server.feature
28
+ - README.rdoc
29
+ - Rakefile
30
+ - Gemfile
31
+ - LICENSE.txt
32
+ - init.rb
33
+ homepage: https://github.com/tntwebsolutions/ts3query
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.22
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: Simple TS3 Query Library.
57
+ test_files: []