Module: Kagerator
- Includes:
- RestClient
- Defined in:
- lib/kagerator.rb,
lib/kagerator/request.rb,
lib/kagerator/version.rb,
lib/kagerator/response.rb
Overview
The main Kagerator class for consumption
Defined Under Namespace
Constant Summary collapse
- API_URL =
'https://api.kag2d.com/'
- VERSION =
'1.0.4'
Class Method Summary collapse
-
.authenticate(username, password) ⇒ Boolean
Attempt to authenticate to the server using your KAG account username/password.
-
.player(name, load_avatar = true) ⇒ SymbolTable
Get a player information.
-
.server(ip, port = 50301) ⇒ SymbolTable
Get information about a specific server.
-
.servers(args = {}) ⇒ SymbolTable
Get a list of servers, filtered by any arguments.
- .version ⇒ Object
Class Method Details
.authenticate(username, password) ⇒ Boolean
Attempt to authenticate to the server using your KAG account username/password
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/kagerator.rb', line 78 def self.authenticate(username,password) begin resp = Kagerator::Request.execute({ :url => "player/#{username}/token/new", :method => :get, :headers => { :Authorization => "Basic "+Base64.encode64("#{username}:#{password}") } }) if resp token = resp.from_json token = token[:playerToken] resp = Kagerator::Request.execute({ :url => "player/#{username}/token/#{token}", :method => :get, :headers => { :Authorization => "Basic "+Base64.encode64("#{username}:#{password}") } }) if resp resp = resp.from_json if resp[:playerTokenStatus] true end else false end else false end rescue false end end |
.player(name, load_avatar = true) ⇒ SymbolTable
Get a player information
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kagerator.rb', line 14 def self.player(name,load_avatar = true) player = Kagerator::Request.execute({ :url => "player/#{name}/status", :method => :get }) if player player = player.from_json if load_avatar avatar = Kagerator::Request.execute({ :url => "player/#{name}/avatar", :method => :get }) if avatar player[:avatar] = avatar.from_json end end player else false end end |
.server(ip, port = 50301) ⇒ SymbolTable
Get information about a specific server
63 64 65 66 67 68 69 |
# File 'lib/kagerator.rb', line 63 def self.server(ip,port = 50301) server = Kagerator::Request.execute({ :url => "server/ip/#{ip}/port/#{port}/status", :method => :get }) server.from_json end |
.servers(args = {}) ⇒ SymbolTable
Get a list of servers, filtered by any arguments
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/kagerator.rb', line 42 def self.servers(args = {}) qs = '' if args.class == Hash or args.class == SymbolTable args.each do |k,v| qs += '/'+k.to_s+'/'+v.to_s end end servers = Kagerator::Request.execute({ :url => "servers/connectable/1"+qs, :method => :get }) servers.from_json end |
.version ⇒ Object
3 |
# File 'lib/kagerator/version.rb', line 3 def self.version; VERSION; end |