honclient 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +21 -0
- data/lib/honclient/match_stats.rb +80 -0
- data/lib/honclient/player_hero_stats.rb +46 -0
- data/lib/honclient/player_stats.rb +40 -0
- data/lib/honclient/stats.rb +44 -0
- data/lib/honclient.rb +11 -0
- metadata +88 -0
data/README
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# A wrapper for the Heroes of Newerth XML API
|
|
2
|
+
# -------------------------------------------
|
|
3
|
+
# Author: Chris Gillis
|
|
4
|
+
# -------------------------------------------
|
|
5
|
+
#
|
|
6
|
+
# A list of variables for stat() can be found on the xml.heroesofnewerth.com
|
|
7
|
+
# website by running the relevant example query
|
|
8
|
+
#
|
|
9
|
+
# DEPENDENCIES
|
|
10
|
+
# Requires rubygems
|
|
11
|
+
# rexml
|
|
12
|
+
#
|
|
13
|
+
# USAGE:
|
|
14
|
+
# require 'hon'
|
|
15
|
+
# @my_stats = HoN::PlayerStats.new("account_name")
|
|
16
|
+
# puts @my_stats.stat("acc_games_played")
|
|
17
|
+
# @match = HoN::MatchStats.new("match_id")
|
|
18
|
+
# puts @match.team_one
|
|
19
|
+
# puts @match.team_two
|
|
20
|
+
# puts @match.summary_stats("time_played")
|
|
21
|
+
# puts @match.team_one_stats("tm_losses")
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module HoN
|
|
2
|
+
class MatchStats < Stats
|
|
3
|
+
def initialize(match_id)
|
|
4
|
+
@match_id = match_id
|
|
5
|
+
@summary_stats = {}
|
|
6
|
+
@team_one_stats = {}
|
|
7
|
+
@team_two_stats = {}
|
|
8
|
+
@team_one_players = []
|
|
9
|
+
@team_two_players = []
|
|
10
|
+
begin
|
|
11
|
+
url = "http://xml.heroesofnewerth.com/xml_requester.php?f=match_stats&opt=mid&mid[]=#{@match_id}"
|
|
12
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
13
|
+
data = Nokogiri::XML.new(xml_data)
|
|
14
|
+
data.xpath('//xmlRequest/stats/match/summ/stat').each do |stat|
|
|
15
|
+
@summary_stats[stat["name"]] = stat.content
|
|
16
|
+
end
|
|
17
|
+
data.xpath("//xmlRequest/stats/match/team[@side=1]/stat").each do |stat|
|
|
18
|
+
@team_one_stats[stat["name"]] = stat.content
|
|
19
|
+
end
|
|
20
|
+
data.xpath("//xmlRequest/stats/match/team[@side=2]/stat").each do |stat|
|
|
21
|
+
@team_two_stats[stat["name"]] = stat.content
|
|
22
|
+
end
|
|
23
|
+
data.xpath("//xmlRequest/stats/match/match_stats/ms").each do |ms|
|
|
24
|
+
temp = {}
|
|
25
|
+
team = 0
|
|
26
|
+
ms.children.each do |stat|
|
|
27
|
+
if stat["name"] == "team"
|
|
28
|
+
team = stat.content.to_i
|
|
29
|
+
end
|
|
30
|
+
temp[stat["name"]] = stat.content
|
|
31
|
+
end
|
|
32
|
+
if team == 1
|
|
33
|
+
@team_one_players.push(temp)
|
|
34
|
+
else
|
|
35
|
+
@team_two_players.push(temp)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
rescue SocketError
|
|
39
|
+
@error = "Could not contact the Newerth XML API."
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
def team_one
|
|
43
|
+
@team_one_players
|
|
44
|
+
end
|
|
45
|
+
def team_two
|
|
46
|
+
@team_two_players
|
|
47
|
+
end
|
|
48
|
+
def match_id
|
|
49
|
+
if defined? @match_id
|
|
50
|
+
@match_id
|
|
51
|
+
else
|
|
52
|
+
nil
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
def summary_stats(key)
|
|
56
|
+
if @summary_stats.has_key? key
|
|
57
|
+
@summary_stats[key]
|
|
58
|
+
else
|
|
59
|
+
return 0
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
def team_one_stats(key)
|
|
63
|
+
if @team_one_stats.has_key? key
|
|
64
|
+
@team_one_stats[key]
|
|
65
|
+
else
|
|
66
|
+
return 0
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
def team_two_stats(key)
|
|
70
|
+
if @team_two_stats.has_key? key
|
|
71
|
+
@team_two_stats[key]
|
|
72
|
+
else
|
|
73
|
+
return 0
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
def dump_xml_stats
|
|
77
|
+
return @summary_stats, @team_one_stats, @team_two_stats, @team_one_players
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
module HoN
|
|
2
|
+
class PlayerHeroStats < Stats
|
|
3
|
+
def initialize(nickname)
|
|
4
|
+
@nickname = nickname
|
|
5
|
+
@heroes = {}
|
|
6
|
+
begin
|
|
7
|
+
url = "http://xml.heroesofnewerth.com/xml_requester.php?f=player_hero_stats&opt=nick&nick[]=#{@nickname}"
|
|
8
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
9
|
+
data = Nokogiri::XML.new(xml_data)
|
|
10
|
+
data.xpath("//xmlRequest/stats/player_hero_stats/hero").each do |hero|
|
|
11
|
+
temp = {}
|
|
12
|
+
hero.children.each do |stat|
|
|
13
|
+
temp[stat["name"]] = stat.content
|
|
14
|
+
end
|
|
15
|
+
@heroes[hero["cli_name"]] = temp
|
|
16
|
+
end
|
|
17
|
+
rescue SocketError
|
|
18
|
+
@error = "Could not contact the Newerth XML API."
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def nickname
|
|
23
|
+
@nickname
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def heroes
|
|
27
|
+
@heroes
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def stats(hero,key)
|
|
31
|
+
if !hero.empty?
|
|
32
|
+
if @heroes.has_key? hero
|
|
33
|
+
if @heroes[hero].has_key? key
|
|
34
|
+
@heroes[hero][key]
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
else
|
|
38
|
+
return 0
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def dump_xml_stats
|
|
43
|
+
return @heroes
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module HoN
|
|
2
|
+
class PlayerStats < Stats
|
|
3
|
+
MAPPINGS = {
|
|
4
|
+
:psr => "acc_pub_skill",
|
|
5
|
+
:kills => "acc_herokills",
|
|
6
|
+
:assists => "acc_heroassists",
|
|
7
|
+
:deaths => "acc_deaths",
|
|
8
|
+
:games => "acc_games_played"
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
def initialize(nickname)
|
|
12
|
+
@nickname = nickname
|
|
13
|
+
@stats = {}
|
|
14
|
+
begin
|
|
15
|
+
url = "http://xml.heroesofnewerth.com/xml_requester.php?f=player_stats&opt=nick&nick[]=#{@nickname}"
|
|
16
|
+
xml_data = Net::HTTP.get_response(URI.parse(url)).body
|
|
17
|
+
data = Nokogiri::XML.parse(xml_data)
|
|
18
|
+
data.xpath("//xmlRequest/stats/player_stats/stat").each do |stat|
|
|
19
|
+
@stats[stat["name"]] = stat.content
|
|
20
|
+
end
|
|
21
|
+
rescue SocketError
|
|
22
|
+
@error = "Could not contact the Newerth XML API."
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def kdr
|
|
27
|
+
"#{(kills.to_f / deaths.to_f * 100).round / 100.0}:1"
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def assists_per_game
|
|
31
|
+
(assists.to_f / games.to_f * 100).round / 100.0
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
MAPPINGS.each do |meth, key|
|
|
35
|
+
define_method meth do
|
|
36
|
+
@stats[key]
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module HoN
|
|
2
|
+
class Stats
|
|
3
|
+
attr_accessor :stats
|
|
4
|
+
def nickname
|
|
5
|
+
if @stats.has_key? "nickname"
|
|
6
|
+
@stats["nickname"]
|
|
7
|
+
else
|
|
8
|
+
"Unknown"
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def stat(key)
|
|
13
|
+
if @stats.has_key? key
|
|
14
|
+
@stats[key]
|
|
15
|
+
else
|
|
16
|
+
return 0
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def dump_xml_stats
|
|
21
|
+
@stats
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def error?
|
|
25
|
+
if defined? @error
|
|
26
|
+
true
|
|
27
|
+
else
|
|
28
|
+
false
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def error
|
|
33
|
+
@error
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def method_missing(meth, *args, &block)
|
|
37
|
+
if @stats.has_key?(meth.to_s)
|
|
38
|
+
@stats[meth.to_s]
|
|
39
|
+
else
|
|
40
|
+
super(meth, *args, &block)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/honclient.rb
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
libdir = File.dirname(__FILE__)
|
|
2
|
+
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
|
3
|
+
|
|
4
|
+
module HoN
|
|
5
|
+
require 'net/http'
|
|
6
|
+
require 'nokogiri'
|
|
7
|
+
require 'honclient/stats'
|
|
8
|
+
require 'honclient/player_stats'
|
|
9
|
+
require 'honclient/match_stats'
|
|
10
|
+
require 'honclient/player_hero_stats'
|
|
11
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: honclient
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 1
|
|
8
|
+
version: "0.1"
|
|
9
|
+
platform: ruby
|
|
10
|
+
authors:
|
|
11
|
+
- Chris Gillis
|
|
12
|
+
- Joseph Hsu
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-10-25 00:00:00 -04:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: nokogiri
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
none: false
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
segments:
|
|
29
|
+
- 1
|
|
30
|
+
- 4
|
|
31
|
+
- 3
|
|
32
|
+
version: 1.4.3
|
|
33
|
+
type: :runtime
|
|
34
|
+
version_requirements: *id001
|
|
35
|
+
description: HoN Client to interact with HoN data
|
|
36
|
+
email:
|
|
37
|
+
- jhsu@josephhsu.com
|
|
38
|
+
executables: []
|
|
39
|
+
|
|
40
|
+
extensions: []
|
|
41
|
+
|
|
42
|
+
extra_rdoc_files: []
|
|
43
|
+
|
|
44
|
+
files:
|
|
45
|
+
- README
|
|
46
|
+
- lib/honclient/player_hero_stats.rb
|
|
47
|
+
- lib/honclient/match_stats.rb
|
|
48
|
+
- lib/honclient/player_stats.rb
|
|
49
|
+
- lib/honclient/stats.rb
|
|
50
|
+
- lib/honclient.rb
|
|
51
|
+
has_rdoc: true
|
|
52
|
+
homepage: http://github.com/jhsu/honclient
|
|
53
|
+
licenses: []
|
|
54
|
+
|
|
55
|
+
post_install_message:
|
|
56
|
+
rdoc_options: []
|
|
57
|
+
|
|
58
|
+
require_paths:
|
|
59
|
+
- lib
|
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
61
|
+
none: false
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
segments:
|
|
66
|
+
- 1
|
|
67
|
+
- 8
|
|
68
|
+
- 7
|
|
69
|
+
version: 1.8.7
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
none: false
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
segments:
|
|
76
|
+
- 1
|
|
77
|
+
- 3
|
|
78
|
+
- 6
|
|
79
|
+
version: 1.3.6
|
|
80
|
+
requirements: []
|
|
81
|
+
|
|
82
|
+
rubyforge_project:
|
|
83
|
+
rubygems_version: 1.3.7
|
|
84
|
+
signing_key:
|
|
85
|
+
specification_version: 3
|
|
86
|
+
summary: Heroes of Newerth api client
|
|
87
|
+
test_files: []
|
|
88
|
+
|