honstats 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,120 @@
1
+ Returns an object which contains all the player statistics avaialable for
2
+ the user specified. You must specify a username rather than an account ID
3
+ for this to function correctly.
4
+
5
+ === Examples
6
+
7
+ This will return all the player statistics for the player named "Limi"
8
+
9
+ require 'honstats'
10
+ honstats = HonStats::API.new
11
+ char = honstats.get_character("Limi")
12
+ char.class.to_s
13
+ => HonStats::Classes::Character
14
+
15
+ If you were to call <tt>to_s</tt> or <tt>to_i</tt> to the <tt>char</tt> variable
16
+ you would get the character account name and account id respectively.
17
+
18
+ From there you can access inidividual statistics by sections...
19
+
20
+ char.account.inspect
21
+ char.building.inspect
22
+ char.creep.inspect
23
+ char.hero.inspect
24
+ char.gamestats.inspect
25
+ char.lastmatch.inspect
26
+ char.neutral.inspect
27
+
28
+ ...or by querying them directly...
29
+
30
+ char.hero.kills
31
+ => 304
32
+ char.creep.kills
33
+ => 5329
34
+
35
+ Each individual section holds different statistics...
36
+
37
+ Account
38
+ :id Account ID number
39
+ :name Account name
40
+ :created_at Account creation date
41
+ :last_login Account last login date
42
+ :last_activity Account last activity date
43
+
44
+ Building
45
+ :damage Damage done to buildings
46
+ :xp XP gained from raizing buildings (currently 0)
47
+ :raized Number of buildings raized
48
+ :gold Gold earned from buildings raized
49
+
50
+ Clan
51
+ :id Clan ID number
52
+ :name Clan name
53
+ :tag Clan tag
54
+ :rank Clan rank
55
+ :icon Clan logo?
56
+
57
+ Creep
58
+ :kills Number of creep kills
59
+ :damage Damage done to creep
60
+ :xp XP gained from killing creeps
61
+ :gold Gold earned from killing creeps
62
+ :denies Number of denied creeps
63
+ :denied_xp XP denied due to denied creeps
64
+ :kills_per_minute Number of creep kills per minute
65
+ :xp_per_minute Amount of XP earned per minute from creep kills
66
+ :denies_per_minute Number of denied creep kills per minute
67
+ :denied_xp_per_minute Amount of XP denied per minute from creep denies
68
+
69
+ Hero
70
+ :kills Number of hero kills
71
+ :damage Damage done to enemy heroes
72
+ :xp XP gained from killing heroes
73
+ :gold Gold earned from killing heroes
74
+ :assists Number of hero kills assisted in
75
+ :deaths Number of hero deaths
76
+ :gold_lost Amount of gold lost due to hero deaths
77
+ :seconds_dead Number of seconds spent dead
78
+ :buybacks Number of hero buybacks
79
+ :kills_per_minute Number of hero kills per minute
80
+ :xp_per_minute XP gained per minute from hero kills
81
+ :time_dead_percentage Percentage of the time spent dead
82
+ :assists_per_minute Number of hero kill assists per minute
83
+ :kill_death_ratio Hero kill to death ratio
84
+
85
+ GameStats
86
+ :wins Number of games won
87
+ :losses Number of games lost
88
+ :win_percentage Percentage of games won
89
+ :disconnects Number of game disconnects
90
+ :time_played Time played in seconds
91
+ :level Account Level
92
+ :gold_earned Gold earned overall
93
+ :gold_spent Gold spent overall
94
+ :xp_earned XP earned overall
95
+ :actions_made Number of actions made
96
+ :average_score ?? - Unknown
97
+ :xp_earned_per_minute XP earned per minute
98
+ :gold_earned_per_minute Gold earned per minute
99
+ :actions_per_minute Number of actions per minute
100
+ :average_game_length_in_seconds Average Number of seconds per game
101
+ :played Number of games played
102
+ :average_kills_per_game Average number of hero kills per game
103
+ :average_deaths_per_game Average number of hero deaths per game
104
+ :average_assists_per_game Average number of hero assists per game
105
+ :disconnect_percentage Percentage of number of games disconnected
106
+ :average_xp_earned_per_game Average amount of XP earned per game
107
+ :average_creep_kills_per_game Average number of creep kills per game
108
+ :average_creep_denies_per_game Average number of creep denies per game
109
+
110
+ Last_Match
111
+ :id Game ID of the last match
112
+ :date Date of the last match played
113
+
114
+ Neutral
115
+ :kills Number of neutral creep kills
116
+ :damage Damage done to neutral creeps
117
+ :xp XP earned from neutral creep kills
118
+ :gold Gold earned from neutral creep kills
119
+ :kills_per_minute Number of neutral creep kills per minute
120
+ :xp_per_minute XP earned per minute from neutral creep kills
data/lib/honstats.rb ADDED
@@ -0,0 +1,241 @@
1
+ #
2
+ # honstats - Heroes of Newerth Statistics Ruby Library
3
+ # Written by Lloyd Pick
4
+ # http://gibhub.com/lloydpick
5
+ # May not be used for commercial applications without prior concent
6
+ #
7
+
8
+ # usual requirements
9
+ require 'rubygems'
10
+ require 'activesupport'
11
+ require 'net/http'
12
+ require 'uri'
13
+ require 'fileutils'
14
+
15
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
16
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
17
+
18
+ require 'honstats/character.rb'
19
+ require 'honstats/server.rb'
20
+ require 'honstats/game.rb'
21
+ require 'honstats/clan.rb'
22
+ require 'honstats/ban.rb'
23
+ require 'honstats/ignore.rb'
24
+
25
+ module HonStats
26
+ class API
27
+ VERSION = '0.0.1'
28
+
29
+ @@stats_url_base = "masterserver.hon.s2games.com/"
30
+ @@requester_file = "client_requester.php"
31
+
32
+ @@search_types = {
33
+ :character => 'character'
34
+ }
35
+
36
+ cattr_accessor :stats_base_url, :requester_file
37
+ attr_accessor :character_name, :cookie
38
+
39
+ # Constructor
40
+ # Accepts an optional hash of parameters to create defaults for all API requests
41
+ # * options (Hash) - Hash used to set default values for all API requests
42
+ def initialize(options = {})
43
+ @character_name = options[:character_name]
44
+ @debug = options[:debug] || false
45
+ end
46
+
47
+ # As more API's are created, we might need a place to search for items/guilds/players etc
48
+ # but for now, it's just for players
49
+ def search(string, options = {})
50
+
51
+ if (string.is_a?(Hash))
52
+ options = string
53
+ else
54
+ options.merge!(:search => string)
55
+ end
56
+
57
+ options = merge_defaults(options)
58
+
59
+ if options[:search].nil? || options[:search].empty?
60
+ raise "no search string"
61
+ end
62
+
63
+ if !@@search_types.has_value?(options[:type])
64
+ raise "invalid search type"
65
+ end
66
+
67
+ results = []
68
+
69
+ case options[:type]
70
+ when @@search_types[:character]
71
+ url = self.base_url + @@requester_file
72
+ character_names = Net::HTTP.post_form(URI.parse(url), {"f"=>"autocompleteNicks", "nickname"=>"#{options[:search]}"})
73
+ character_names = character_names.body.split('"')
74
+ character_names.each_index do |d|
75
+ if character_names[d].include?(";")
76
+ character_names.delete_at(d)
77
+ end
78
+ end
79
+ character_names.delete_at(0)
80
+
81
+ character_names.each do |character|
82
+ sheet = self.get_character(character)
83
+ if sheet.account.id > 0
84
+ results << self.get_character(character)
85
+ end
86
+ end
87
+ end
88
+
89
+ return results
90
+
91
+ end
92
+
93
+
94
+ def search_characters(name, options = {})
95
+ if (name.is_a?(Hash))
96
+ options = name
97
+ else
98
+ options.merge!(:search => name)
99
+ end
100
+
101
+ options.merge!(:type => @@search_types[:character])
102
+ return search(options)
103
+ end
104
+
105
+
106
+ def get_character(name = @character_name, options = {})
107
+ if (name.is_a?(Hash))
108
+ options = name
109
+ else
110
+ options.merge!(:character_name => name)
111
+ options = {:character_name => @character_name}.merge(options) if (!@character_name.nil?)
112
+ end
113
+
114
+ options = merge_defaults(options)
115
+
116
+ if options[:character_name].nil? || options[:character_name] == ""
117
+ raise "characer name not specified"
118
+ end
119
+
120
+ if options[:character_name].is_a?(String)
121
+ url = self.base_url + @@requester_file
122
+ character_account_id = Net::HTTP.post_form(URI.parse(url), {"f"=>"nick2id", "nickname[0]"=>"#{options[:character_name]}"})
123
+ character_account_id = character_account_id.body
124
+ elsif options[:character_name].is_a?(Integer)
125
+ character_account_id = options[:character_name]
126
+ end
127
+ return HonStats::Classes::Character.new(character_account_id, self)
128
+ end
129
+
130
+ def get_servers(options = { :gametype => 90 })
131
+ options = merge_defaults(options)
132
+ options[:type] = HonStats::Classes::Server
133
+ return server_browser(options)
134
+ end
135
+
136
+ def get_games(options = { :gametype => 10 })
137
+ options = merge_defaults(options)
138
+ options[:type] = HonStats::Classes::Game
139
+ return server_browser(options)
140
+ end
141
+
142
+ def get_active_games(options = { :gametype => 32 })
143
+ options = merge_defaults(options)
144
+ options[:type] = HonStats::Classes::Game
145
+ return server_browser(options)
146
+ end
147
+
148
+ def server_browser(options = {})
149
+ options = merge_defaults(options)
150
+ if @cookie
151
+ url = self.base_url + @@requester_file
152
+ data = Net::HTTP.post_form(URI.parse(url), {"f"=>"server_list", "gametype"=>"#{options[:gametype]}", "cookie"=>@cookie})
153
+ data = data.body.split('s:9:"server_id";s:')
154
+ data.delete_at(0)
155
+ data.map! {|d| 's:9:"server_id";s:' + d }
156
+ output = []
157
+ data.each do |d|
158
+ output << options[:type].new(d)
159
+ end
160
+ output
161
+ else
162
+ raise "unable to access server browser data without an auth cookie, use login() first"
163
+ end
164
+ end
165
+
166
+ def get_clan(options = {})
167
+ options = merge_defaults(options)
168
+ url = self.base_url + @@requester_file
169
+ data = Net::HTTP.post_form(URI.parse(url), {"f"=>"clan_list", "clan_id"=>"#{options[:clan_id]}"})
170
+ data = data.body.split(';a:6:{s:10:"account_id";s:')
171
+ data.delete_at(0)
172
+ data.map! {|d| 's:10:"account_id";s:' + d }
173
+ return HonStats::Classes::Clan.new(data)
174
+ end
175
+
176
+ def get_banlist(options = {})
177
+ options = merge_defaults(options)
178
+ url = self.base_url + @@requester_file
179
+ data = Net::HTTP.post_form(URI.parse(url), {"f"=>"banned_list", "account_id[0]"=>"#{options[:account_id]}"})
180
+ data = data.body.split(';a:3:{s:10:"account_id";s:')
181
+ data.delete_at(0)
182
+ data.map! {|d| 's:10:"account_id";s:' + d }
183
+ return HonStats::Classes::Banlist::Banlist.new(data)
184
+ end
185
+
186
+ def get_ignorelist(options = {})
187
+ options = merge_defaults(options)
188
+ url = self.base_url + @@requester_file
189
+ data = Net::HTTP.post_form(URI.parse(url), {"f"=>"ignored_list", "account_id[0]"=>"#{options[:account_id]}"})
190
+ data = data.body.split(';a:3:{s:10:"account_id";s:')
191
+ data.delete_at(0)
192
+ data.map! {|d| 's:10:"account_id";s:' + d }
193
+ return HonStats::Classes::Ignorelist::Ignorelist.new(data)
194
+ end
195
+
196
+ def login(username, password)
197
+ url = self.base_url + @@requester_file
198
+ data = Net::HTTP.post_form(URI.parse(url), {"f"=>"auth", "login"=>"#{username}", "password"=>"#{password}"})
199
+
200
+ @cookie = HonStats::API.get_data("cookie", data.body).to_s
201
+ end
202
+
203
+ def base_url(options = {})
204
+ str = ""
205
+
206
+ if (options[:secure] == true)
207
+ str += 'https://'
208
+ else
209
+ str += 'http://'
210
+ end
211
+
212
+ str += @@stats_url_base
213
+
214
+ return str
215
+ end
216
+
217
+ # Used to fetch the data from the messy JSON type string sent back from the
218
+ # server, might be a better/faster/cleaner way of doing this
219
+ def self.get_data(attribute, data)
220
+ data = data.split("\"#{attribute}\"")
221
+ if data[1]
222
+ data = data[1].split(";")
223
+ data = data[1].split("\"")
224
+ data[1]
225
+ end
226
+ end
227
+
228
+ protected
229
+
230
+ # Merge the defaults specified in the constructor with those supplied,
231
+ # overriding any defaults with those supplied
232
+ def merge_defaults(options = {})
233
+ defaults = {}
234
+ defaults[:debug] = @debug if @debug
235
+
236
+ # overwrite defaults with any given options
237
+ defaults.merge!(options)
238
+ end
239
+
240
+ end
241
+ end
@@ -0,0 +1,37 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ module HonStats
5
+ module Classes
6
+ module Banlist
7
+ class Banlist
8
+ attr_reader :id, :bans
9
+ alias_method :to_i, :id
10
+
11
+ def initialize(data)
12
+ if bans[0]
13
+ bans = []
14
+ data.each do |ban|
15
+ bans << Ban.new(ban)
16
+ end
17
+ @bans = bans
18
+ @id = HonStats::API.get_data("account_id", bans[0]).to_i
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ class Ban
25
+ attr_reader :account_id, :banned_id, :nickname, :reason, :banned_at
26
+
27
+ def initialize(data)
28
+ @account_id = HonStats::API.get_data("account_id", data).to_i
29
+ @banned_id = HonStats::API.get_data("banned_id", data).to_i
30
+ @nickname = HonStats::API.get_data("nickname", data).to_s
31
+ # @reason = HonStats::API.get_data("reason", data).to_s
32
+ # @banned_at = Time.parse(HonStats::API.get_data("ban_date", data).to_s)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,225 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ module HonStats
5
+ module Classes
6
+ class Character
7
+ attr_reader :account_id, :character_name, :account, :building, :clan,
8
+ :creep, :gamestats, :hero, :last_match, :neutral
9
+
10
+ alias_method :to_s, :character_name
11
+ alias_method :to_i, :account_id
12
+
13
+ def initialize(data, api = nil)
14
+ @api = api
15
+
16
+ if data.is_a?(String)
17
+ output = data.split(";")
18
+
19
+ split = output[3].split("\"")
20
+ @account_id = split[1].to_i
21
+
22
+ elsif data.is_a?(Integer)
23
+ @account_id = data
24
+ end
25
+
26
+ url = base + @api.requester_file
27
+ data = Net::HTTP.post_form(URI.parse(url), {"f"=>"get_all_stats", "account_id[0]"=>"#{@account_id}"})
28
+ if data.class.to_s == "Net::HTTPOK"
29
+ data = data.body
30
+ @account_id = HonStats::API.get_data("account_id", data).to_i
31
+ @character_name = HonStats::API.get_data("nickname", data).to_s
32
+ @account = Account.new(data)
33
+ @building = Building.new(data)
34
+ @clan = SimpleClan.new(data)
35
+ @creep = Creep.new(data)
36
+ @hero = Hero.new(data)
37
+ @gamestats = GameStats.new(data, @hero, @creep)
38
+ @last_match = LastMatch.new(data)
39
+ @neutral = Neutral.new(data)
40
+ end
41
+ end
42
+
43
+ protected
44
+
45
+ # Return the base_url of the API if available, otherwise send back the default
46
+ def base
47
+ if @api
48
+ return @api.base_url
49
+ else
50
+ return 'http://masterserver.hon.s2games.com/'
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ # Consilidated Account stats
57
+ class Account
58
+ attr_reader :id, :name, :created_at, :last_login, :last_activity
59
+
60
+ def initialize(data)
61
+ @id = HonStats::API.get_data("account_id", data).to_i
62
+ @name = HonStats::API.get_data("nickname", data).to_s
63
+ @created_at = Time.parse(HonStats::API.get_data("create_date", data).to_s)
64
+ @last_login = Time.parse(HonStats::API.get_data("last_login", data).to_s)
65
+ @last_activity = Time.parse(HonStats::API.get_data("last_activity", data).to_s)
66
+ end
67
+ end
68
+
69
+ # Consilidated game stats
70
+ class GameStats
71
+ attr_reader :wins, :losses, :win_percentage, :disconnects, :time_played,
72
+ :level, :gold_earned, :gold_spent, :xp_earned, :actions_made,
73
+ :average_score, :xp_earned_per_minute, :gold_earned_per_minute,
74
+ :actions_per_minute, :average_game_length_in_seconds, :played,
75
+ :average_kills_per_game, :average_deaths_per_game,
76
+ :average_assists_per_game, :disconnect_percentage,
77
+ :average_xp_earned_per_game, :average_creep_kills_per_game,
78
+ :average_creep_denies_per_game, :concedes, :concede_votes,
79
+ :kicked, :pub_skill
80
+
81
+ def initialize(data, hero_stats, creep_stats)
82
+ @wins = HonStats::API.get_data("acc_wins", data).to_i
83
+ @losses = HonStats::API.get_data("acc_losses", data).to_i
84
+ @disconnects = HonStats::API.get_data("acc_discos", data).to_i
85
+ @played = @wins + @losses
86
+ @disconnect_percentage = "%.02f" % ((@disconnects.to_f / @played) * 100)
87
+ @win_percentage = "%.02f" % ((@wins.to_f / @played) * 100)
88
+ @time_played = HonStats::API.get_data("acc_secs", data).to_i
89
+ @level = HonStats::API.get_data("level", data).to_i
90
+ @gold_earned = HonStats::API.get_data("acc_gold", data).to_i
91
+ @gold_spent = HonStats::API.get_data("acc_gold_spent", data).to_i
92
+ @xp_earned = HonStats::API.get_data("acc_exp", data).to_i
93
+ @actions_made = HonStats::API.get_data("acc_actions", data).to_i
94
+ @average_score = HonStats::API.get_data("acc_avg_score", data).to_f
95
+ @concedes = HonStats::API.get_data("acc_concedes", data).to_i
96
+ @concede_votes = HonStats::API.get_data("acc_concedevotes", data).to_i
97
+ @kicked = HonStats::API.get_data("acc_kicked", data).to_i
98
+ @pub_skill = HonStats::API.get_data("acc_pub_skill", data).to_i
99
+
100
+ if @time_played > 0
101
+ minutes_played = @time_played / 60
102
+ @xp_earned_per_minute = "%.02f" % (@xp_earned.to_f / minutes_played.to_f)
103
+ @gold_earned_per_minute = "%.02f" % (@gold_earned.to_f / minutes_played.to_f)
104
+ @actions_per_minute = "%.02f" % (@actions_made.to_f / minutes_played.to_f)
105
+
106
+ @average_game_length_in_seconds = (@time_played.to_f / @played).to_i
107
+
108
+ @average_kills_per_game = "%.02f" % (hero_stats.kills.to_f / @played)
109
+ @average_deaths_per_game = "%.02f" % (hero_stats.deaths.to_f / @played)
110
+ @average_assists_per_game = "%.02f" % (hero_stats.assists.to_f / @played)
111
+
112
+ @average_xp_earned_per_game = "%.02f" % (@xp_earned.to_f / @played)
113
+
114
+ @average_creep_kills_per_game = "%.02f" % (creep_stats.kills.to_f / @played)
115
+ @average_creep_denies_per_game = "%.02f" % (creep_stats.denies.to_f / @played)
116
+ end
117
+ end
118
+ end
119
+
120
+ # Consilidated clan info
121
+ class SimpleClan
122
+ attr_reader :id, :name, :tag, :rank, :icon
123
+
124
+ def initialize(data)
125
+ @id = HonStats::API.get_data("clan_id", data).to_i
126
+ @name = HonStats::API.get_data("name", data).to_s
127
+ @tag = HonStats::API.get_data("tag", data).to_s
128
+ @rank = HonStats::API.get_data("rank", data).to_s
129
+ @icon = HonStats::API.get_data("file_name", data).to_s
130
+ end
131
+ end
132
+
133
+ # Consilidated creep stats
134
+ class Creep
135
+ attr_reader :kills, :damage, :xp, :gold, :denies, :denied_xp, :kills_per_minute,
136
+ :xp_per_minute, :denies_per_minute, :denied_xp_per_minute
137
+
138
+ def initialize(data)
139
+ @kills = HonStats::API.get_data("acc_teamcreepkills", data).to_i
140
+ @damage = HonStats::API.get_data("acc_teamcreepdmg", data).to_i
141
+ @xp = HonStats::API.get_data("acc_teamcreepexp", data).to_i
142
+ @gold = HonStats::API.get_data("acc_teamcreepgold", data).to_i
143
+ @denies = HonStats::API.get_data("acc_denies", data).to_i
144
+ @denied_xp = HonStats::API.get_data("acc_exp_denied", data).to_i
145
+
146
+ minutes_played = HonStats::API.get_data("acc_secs", data).to_i / 60
147
+ @kills_per_minute = "%.02f" % (@kills.to_f / minutes_played.to_f)
148
+ @xp_per_minute = "%.02f" % (@xp.to_f / minutes_played.to_f)
149
+ @denies_per_minute = "%.02f" % (@denies.to_f / minutes_played.to_f)
150
+ @denied_xp_per_minute = "%.02f" % (@denied_xp.to_f / minutes_played.to_f)
151
+ end
152
+ end
153
+
154
+ # Consilidated neutral creep stats
155
+ class Neutral
156
+ attr_reader :kills, :damage, :xp, :gold, :kills_per_minute, :xp_per_minute
157
+
158
+ def initialize(data)
159
+ @kills = HonStats::API.get_data("acc_neutralcreepkills", data).to_i
160
+ @damage = HonStats::API.get_data("acc_neutralcreepdmg", data).to_i
161
+ @xp = HonStats::API.get_data("acc_neutralcreepexp", data).to_i
162
+ @gold = HonStats::API.get_data("acc_neutralcreepgold", data).to_i
163
+
164
+ minutes_played = HonStats::API.get_data("acc_secs", data).to_i / 60
165
+ @kills_per_minute = "%.02f" % (@kills.to_f / minutes_played.to_f)
166
+ @xp_per_minute = "%.02f" % (@xp.to_f / minutes_played.to_f)
167
+ end
168
+ end
169
+
170
+ # Consilidated hero stats
171
+ class Hero
172
+ attr_reader :kills, :damage, :xp, :gold, :assists, :deaths, :gold_lost,
173
+ :seconds_dead, :buybacks, :kills_per_minute, :xp_per_minute,
174
+ :time_dead_percentage, :assists_per_minute, :kill_death_ratio,
175
+ :consumables, :wards
176
+
177
+ def initialize(data)
178
+ @kills = HonStats::API.get_data("acc_herokills", data).to_i
179
+ @damage = HonStats::API.get_data("acc_herodmg", data).to_i
180
+ @xp = HonStats::API.get_data("acc_heroexp", data).to_i
181
+ @gold = HonStats::API.get_data("acc_herokillsgold", data).to_i
182
+ @assists = HonStats::API.get_data("acc_heroassists", data).to_i
183
+ @deaths = HonStats::API.get_data("acc_deaths", data).to_i
184
+ @gold_lost = HonStats::API.get_data("acc_goldlost2death", data).to_i
185
+ @seconds_dead = HonStats::API.get_data("acc_secs_dead", data).to_i
186
+ @buybacks = HonStats::API.get_data("acc_buybacks", data).to_i
187
+ @consumables = HonStats::API.get_data("acc_consumables", data).to_i
188
+ @wards = HonStats::API.get_data("acc_wards", data).to_i
189
+
190
+ seconds_played = HonStats::API.get_data("acc_secs", data).to_i
191
+ minutes_played = seconds_played / 60
192
+ @kills_per_minute = "%.02f" % (@kills.to_f / minutes_played.to_f)
193
+ @assists_per_minute = "%.02f" % (@assists.to_f / minutes_played.to_f)
194
+ @xp_per_minute = "%.02f" % (@xp.to_f / minutes_played.to_f)
195
+ @time_dead_percentage = "%.02f" % ((@seconds_dead.to_f / seconds_played.to_f) * 100)
196
+ @kill_death_ratio = "%.02f" % (@kills.to_f / @deaths.to_f)
197
+ end
198
+ end
199
+
200
+ # Consilidated neutral creep stats
201
+ class Building
202
+ attr_reader :damage, :xp, :raized, :gold
203
+
204
+ def initialize(data)
205
+ @damage = HonStats::API.get_data("acc_bdmg", data).to_i
206
+ @xp = HonStats::API.get_data("acc_bdmgexp", data).to_i
207
+ @raized = HonStats::API.get_data("acc_razed", data).to_i
208
+ @gold = HonStats::API.get_data("acc_bgold", data).to_i
209
+ end
210
+ end
211
+
212
+ # Consilidated last match stats
213
+ class LastMatch
214
+ attr_reader :id, :date
215
+
216
+ def initialize(data)
217
+ @id = HonStats::API.get_data("match_id", data).to_i
218
+ @date = Time.parse(HonStats::API.get_data("mdt", data).to_s)
219
+ end
220
+ end
221
+
222
+ class SearchCharacter < Character
223
+ end
224
+ end
225
+ end
@@ -0,0 +1,71 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ module HonStats
5
+ module Classes
6
+ class Game
7
+ attr_reader :server_id, :session, :name, :class, :private, :modes,
8
+ :max_players, :tier, :official, :ip, :port, :players, :state,
9
+ :last_update, :location
10
+
11
+ alias_method :to_i, :server_id
12
+ alias_method :to_s, :name
13
+
14
+ def initialize(data)
15
+ @server_id = HonStats::API.get_data("server_id", data).to_i
16
+ @session = HonStats::API.get_data("session", data).to_s
17
+ @name = HonStats::API.get_data("mname", data).to_s
18
+ @class = HonStats::API.get_data("class", data).to_i
19
+ @private = HonStats::API.get_data("private", data).to_i
20
+ @max_players = (HonStats::API.get_data("max_players", data).to_i * 2)
21
+ @tier = HonStats::API.get_data("tier", data).to_i
22
+ @official = HonStats::API.get_data("officl", data).to_i
23
+ @ip = HonStats::API.get_data("ip", data).to_s
24
+ @port = HonStats::API.get_data("port", data).to_i
25
+ @players = HonStats::API.get_data("num_conn", data).to_i
26
+ @state = HonStats::API.get_data("c_state", data).to_i
27
+ @last_update = Time.parse(HonStats::API.get_data("last_upd", data).to_s)
28
+ @location = HonStats::API.get_data("location", data).to_s
29
+ @modes = Modes.new(data)
30
+ end
31
+
32
+ end
33
+
34
+ # Consilidated modes
35
+ class Modes
36
+ attr_reader :normal_mode, :single_draft, :random_draft, :death_match,
37
+ :league, :no_repick, :no_agility, :item_drop, :no_respawn_timer,
38
+ :no_swap, :no_intelligence, :alternate_picking, :no_strength,
39
+ :no_powerups, :duplicate_hero, :all_pick, :all_random,
40
+ :easy_mode, :rs, :no_leavers, :reverse_hero, :veto,
41
+ :shuffle_players
42
+
43
+ def initialize(data)
44
+ @normal_mode = HonStats::API.get_data("nm", data).to_i
45
+ @single_draft = HonStats::API.get_data("sd", data).to_i
46
+ @random_draft = HonStats::API.get_data("rd", data).to_i
47
+ @death_match = HonStats::API.get_data("dm", data).to_i
48
+ @league = HonStats::API.get_data("league", data).to_i
49
+ @no_repick = HonStats::API.get_data("no_repick", data).to_i
50
+ @no_agility = HonStats::API.get_data("no_agi", data).to_i
51
+ @item_drop = HonStats::API.get_data("drp_itm", data).to_i
52
+ @no_respawn_timer = HonStats::API.get_data("no_timer", data).to_i
53
+ @no_swapping = HonStats::API.get_data("no_swap", data).to_i
54
+ @no_intelligence = HonStats::API.get_data("no_int", data).to_i
55
+ @alternate_picking = HonStats::API.get_data("alt_pick", data).to_i
56
+ @no_strength = HonStats::API.get_data("no_str", data).to_i
57
+ @no_powerups = HonStats::API.get_data("no_pups", data).to_i
58
+ @duplicate_hero = HonStats::API.get_data("dup_h", data).to_i
59
+ @all_pick = HonStats::API.get_data("ap", data).to_i
60
+ @all_random = HonStats::API.get_data("ar", data).to_i
61
+ @easy_mode = HonStats::API.get_data("em", data).to_i
62
+ @rs = HonStats::API.get_data("rs", data).to_i
63
+ @no_leavers = HonStats::API.get_data("nl", data).to_i
64
+ @reverse_hero = HonStats::API.get_data("rev_hs", data).to_i
65
+ @veto = HonStats::API.get_data("veto", data).to_i
66
+ @shuffle_players = HonStats::API.get_data("shuf", data).to_i
67
+ end
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,37 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ module HonStats
5
+ module Classes
6
+ module Ignorelist
7
+ class Ignorelist
8
+ attr_reader :id, :ignores
9
+ alias_method :to_i, :id
10
+
11
+ def initialize(data)
12
+ if data[0]
13
+ ignores = []
14
+ data.each do |ignore|
15
+ ignores << Ignore.new(ignore)
16
+ end
17
+ @ignores = ignores
18
+ @id = HonStats::API.get_data("account_id", data[0]).to_i
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ class Ignore
25
+ attr_reader :account_id, :ignored_id, :nickname
26
+
27
+ def initialize(data)
28
+ @account_id = HonStats::API.get_data("account_id", data).to_i
29
+ @ignored_id = HonStats::API.get_data("ignored_id", data).to_i
30
+ @nickname = HonStats::API.get_data("nickname", data).to_s
31
+ # @reason = HonStats::API.get_data("reason", data).to_s
32
+ # @ignored_at = Time.parse(HonStats::API.get_data("ignore_date", data).to_s)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,20 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ module HonStats
5
+ module Classes
6
+ class Server
7
+ attr_reader :id, :session, :ip, :port
8
+
9
+ alias_method :to_i, :id
10
+
11
+ def initialize(data)
12
+ @id = HonStats::API.get_data("server_id", data).to_i
13
+ @session = HonStats::API.get_data("session", data).to_s
14
+ @ip = HonStats::API.get_data("ip", data).to_s
15
+ @port = HonStats::API.get_data("port", data).to_s
16
+ end
17
+
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: honstats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.7
5
+ platform: ruby
6
+ authors:
7
+ - Lloyd Pick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-07-28 00:00:00 -03:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: HonStats is a Ruby library for extracting player statistics and other information from the Heroes of Newerth master server.
17
+ email: lloydpick@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - README
26
+ - lib/honstats.rb
27
+ - lib/honstats/character.rb
28
+ - lib/honstats/game.rb
29
+ - lib/honstats/server.rb
30
+ - lib/honstats/ban.rb
31
+ - lib/honstats/ignore.rb
32
+ has_rdoc: true
33
+ homepage: https://github.com/lloydpick/hon-stats
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options:
38
+ - --inline-source
39
+ - --charset=UTF-8
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ version:
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ requirements: []
55
+
56
+ rubyforge_project:
57
+ rubygems_version: 1.3.5
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: HonStats is a Ruby Gem for extracting player statistics and other information from the Heroes of Newerth master server.
61
+ test_files: []
62
+