kagerator 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +16 -0
- data/lib/kagerator/request.rb +2 -1
- data/lib/kagerator/version.rb +1 -1
- data/lib/kagerator.rb +29 -3
- metadata +1 -1
data/README.md
CHANGED
@@ -7,9 +7,25 @@ Consumes the KAG API.
|
|
7
7
|
<pre>
|
8
8
|
require 'kagerator'
|
9
9
|
|
10
|
+
# player info
|
10
11
|
player = Kagerator.player("splittingred")
|
11
12
|
puts player[:playerInfo][:status]
|
12
13
|
|
14
|
+
# server info
|
13
15
|
server = Kagerator.server("74.91.114.49",50301)
|
14
16
|
puts server[:serverStatus][:description]
|
17
|
+
|
18
|
+
# server list
|
19
|
+
servers = Kagerator.servers({:empty => 0,:full => 0})
|
20
|
+
servers[:serverList].each do |server|
|
21
|
+
puts server[:serverName]+'<br />'
|
22
|
+
end
|
15
23
|
</pre>
|
24
|
+
|
25
|
+
## Info
|
26
|
+
|
27
|
+
Written by Shaun McCormick
|
28
|
+
|
29
|
+
Uses RestClient, SymbolTable and JSON gems, with RSpec for testing
|
30
|
+
|
31
|
+
Released under the GPLv2 or later License: http://www.gnu.org/licenses/gpl-2.0.html
|
data/lib/kagerator/request.rb
CHANGED
@@ -3,6 +3,7 @@ require File.dirname(__FILE__)+'/response'
|
|
3
3
|
|
4
4
|
module Kagerator
|
5
5
|
include RestClient
|
6
|
+
API_URL = 'https://api.kag2d.com/'
|
6
7
|
|
7
8
|
class Request
|
8
9
|
def self.execute(args, &block)
|
@@ -21,7 +22,7 @@ module Kagerator
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def execute &block
|
24
|
-
response = ::RestClient.send(@method,
|
25
|
+
response = ::RestClient.send(@method,API_URL+@url)
|
25
26
|
if block_given?
|
26
27
|
block.call(response, self, & block)
|
27
28
|
end
|
data/lib/kagerator/version.rb
CHANGED
data/lib/kagerator.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/kagerator/request'
|
2
|
-
|
2
|
+
##
|
3
|
+
# The main Kagerator class for consumption
|
4
|
+
#
|
3
5
|
module Kagerator
|
6
|
+
##
|
7
|
+
# Get a player information
|
8
|
+
#
|
9
|
+
# @param [String] name The username of the player
|
10
|
+
# @param [Boolean] load_avatar Whether or not to add the avatar to the data loaded. Makes another HTTP request to the API
|
11
|
+
# @return [SymbolTable] A hash of the player data
|
12
|
+
#
|
4
13
|
def self.player(name,load_avatar = true)
|
5
14
|
player = Kagerator::Request.execute({
|
6
15
|
:url => "player/#{name}/status",
|
@@ -24,15 +33,32 @@ module Kagerator
|
|
24
33
|
end
|
25
34
|
|
26
35
|
##
|
27
|
-
#
|
36
|
+
# Get a list of servers, filtered by any arguments
|
37
|
+
#
|
38
|
+
# @param [Hash] args A hash of arguments to filter with
|
39
|
+
# @return [SymbolTable] An array of hashes of results
|
40
|
+
#
|
28
41
|
def self.servers(args = {})
|
42
|
+
qs = ''
|
43
|
+
if args.class == Hash or args.class == SymbolTable
|
44
|
+
args.each do |k,v|
|
45
|
+
qs += '/'+k.to_s+'/'+v.to_s
|
46
|
+
end
|
47
|
+
end
|
29
48
|
servers = Kagerator::Request.execute({
|
30
|
-
:url => "servers/connectable/1",
|
49
|
+
:url => "servers/connectable/1"+qs,
|
31
50
|
:method => :get
|
32
51
|
})
|
33
52
|
servers.from_json
|
34
53
|
end
|
35
54
|
|
55
|
+
##
|
56
|
+
# Get information about a specific server
|
57
|
+
#
|
58
|
+
# @param [String] ip The IP address of the server, in ipv4 or ipv6 format
|
59
|
+
# @param [String|Integer] port The port of the server
|
60
|
+
# @return [SymbolTable] A hash of the server variables
|
61
|
+
#
|
36
62
|
def self.server(ip,port = 50301)
|
37
63
|
server = Kagerator::Request.execute({
|
38
64
|
:url => "server/ip/#{ip}/port/#{port}/status",
|