kagerator 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # Kagerator
2
+
3
+ Consumes the KAG API.
4
+
5
+ ## Usage
6
+
7
+ <pre>
8
+ require 'kagerator'
9
+
10
+ player = Kagerator.player("splittingred")
11
+ puts player[:playerInfo][:status]
12
+
13
+ server = Kagerator.server("74.91.114.49",50301)
14
+ puts server[:serverStatus][:description]
15
+ </pre>
@@ -0,0 +1,31 @@
1
+ require 'rest-client'
2
+ require File.dirname(__FILE__)+'/response'
3
+
4
+ module Kagerator
5
+ include RestClient
6
+
7
+ class Request
8
+ def self.execute(args, &block)
9
+ new(args).execute(&block)
10
+ end
11
+
12
+ def initialize args
13
+ @method = args[:method] or raise ArgumentError, "must pass :method"
14
+ @headers = args[:headers] || {}
15
+ if args[:url]
16
+ @url = args[:url]
17
+ else
18
+ raise ArgumentError, "must pass :url"
19
+ end
20
+ @args = args
21
+ end
22
+
23
+ def execute &block
24
+ response = ::RestClient.send(@method,'https://api.kag2d.com/'+@url)
25
+ if block_given?
26
+ block.call(response, self, & block)
27
+ end
28
+ Kagerator::Response.new(response)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ require 'json'
2
+ require 'symboltable'
3
+
4
+ module Kagerator
5
+ class Response
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def from_json
12
+ SymbolTable.new(::JSON.parse(@response))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,4 @@
1
+ module Kagerator
2
+ VERSION = '1.0.0'
3
+ def self.version; VERSION; end
4
+ end
data/lib/kagerator.rb ADDED
@@ -0,0 +1,43 @@
1
+ require File.dirname(__FILE__) + '/kagerator/request'
2
+
3
+ module Kagerator
4
+ def self.player(name,load_avatar = true)
5
+ player = Kagerator::Request.execute({
6
+ :url => "player/#{name}/status",
7
+ :method => :get
8
+ })
9
+ if player
10
+ player = player.from_json
11
+ if load_avatar
12
+ avatar = Kagerator::Request.execute({
13
+ :url => "player/#{name}/avatar",
14
+ :method => :get
15
+ })
16
+ if avatar
17
+ player[:avatar] = avatar.from_json
18
+ end
19
+ end
20
+ player
21
+ else
22
+ false
23
+ end
24
+ end
25
+
26
+ ##
27
+ # @TODO: filtering with args
28
+ def self.servers(args = {})
29
+ servers = Kagerator::Request.execute({
30
+ :url => "servers/connectable/1",
31
+ :method => :get
32
+ })
33
+ servers.from_json
34
+ end
35
+
36
+ def self.server(ip,port = 50301)
37
+ server = Kagerator::Request.execute({
38
+ :url => "server/ip/#{ip}/port/#{port}/status",
39
+ :method => :get
40
+ })
41
+ server.from_json
42
+ end
43
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kagerator
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Shaun McCormick
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.6.7
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.6.7
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ version_requirements: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '='
35
+ - !ruby/object:Gem::Version
36
+ version: 1.7.6
37
+ none: false
38
+ requirement: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - '='
41
+ - !ruby/object:Gem::Version
42
+ version: 1.7.6
43
+ none: false
44
+ prerelease: false
45
+ type: :runtime
46
+ - !ruby/object:Gem::Dependency
47
+ name: symboltable
48
+ version_requirements: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '='
51
+ - !ruby/object:Gem::Version
52
+ version: 1.0.2
53
+ none: false
54
+ requirement: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - '='
57
+ - !ruby/object:Gem::Version
58
+ version: 1.0.2
59
+ none: false
60
+ prerelease: false
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ name: jruby-openssl
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.7
69
+ none: false
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '='
73
+ - !ruby/object:Gem::Version
74
+ version: 0.7.7
75
+ none: false
76
+ prerelease: false
77
+ type: :runtime
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ none: false
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ! '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ none: false
92
+ prerelease: false
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ name: rspec
96
+ version_requirements: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ none: false
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ none: false
108
+ prerelease: false
109
+ type: :development
110
+ - !ruby/object:Gem::Dependency
111
+ name: guard-rspec
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ none: false
118
+ requirement: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ none: false
124
+ prerelease: false
125
+ type: :development
126
+ description: Easy, quick consumption and reading of the King Arthur's Gold Public API
127
+ email:
128
+ - splittingred@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - README.md
134
+ - lib/kagerator.rb
135
+ - lib/kagerator/request.rb
136
+ - lib/kagerator/response.rb
137
+ - lib/kagerator/version.rb
138
+ homepage: https://github.com/splittingred/kagerator
139
+ licenses:
140
+ - GPLv2
141
+ post_install_message:
142
+ rdoc_options: []
143
+ require_paths:
144
+ - lib
145
+ required_ruby_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: 1.9.2
150
+ none: false
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ! '>='
154
+ - !ruby/object:Gem::Version
155
+ version: 1.3.6
156
+ none: false
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 1.8.25
160
+ signing_key:
161
+ specification_version: 3
162
+ summary: Easy consumption of the KAG API
163
+ test_files: []
164
+ has_rdoc:
165
+ ...