steam-condenser 1.3.2 → 1.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steam-condenser (1.3.2)
4
+ steam-condenser (1.3.3)
5
5
  bzip2-ruby (~> 0.2.7)
6
6
  multi_json (~> 1.5.0)
7
7
  multi_xml (~> 0.5.1)
@@ -13,8 +13,8 @@ GEM
13
13
  metaclass (0.0.1)
14
14
  mocha (0.13.1)
15
15
  metaclass (~> 0.0.1)
16
- multi_json (1.5.0)
17
- multi_xml (0.5.2)
16
+ multi_json (1.5.1)
17
+ multi_xml (0.5.3)
18
18
  rake (10.0.3)
19
19
  shoulda-context (1.0.2)
20
20
  yard (0.8.3)
@@ -10,12 +10,4 @@ require 'errors/steam_condenser_error'
10
10
  #
11
11
  # @author Sebastian Staudt
12
12
  class PacketFormatError < SteamCondenserError
13
-
14
- # Creates a new `PacketFormatError` instance
15
- #
16
- # @param [String] message The message to attach to the error
17
- def initialize(message)
18
- super message
19
- end
20
-
21
13
  end
@@ -1,11 +1,26 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2008-2011, Sebastian Staudt
4
+ # Copyright (c) 2008-2013, Sebastian Staudt
5
5
 
6
6
  # This error class is used as a base class for all errors related to Steam
7
7
  # Condenser's operation
8
8
  #
9
9
  # @author Sebastian Staudt
10
10
  class SteamCondenserError < StandardError
11
+
12
+ # Returns the exception that caused this error
13
+ #
14
+ # @return [Exception] The exception that caused this error
15
+ attr_reader :cause
16
+
17
+ # Creates a new `SteamCondenserError` instance
18
+ #
19
+ # @param [String] message The message to attach to the error
20
+ # @param [Exception] cause The exception that caused this error
21
+ def initialize(message, cause = nil)
22
+ super message
23
+ @cause = cause
24
+ end
25
+
11
26
  end
@@ -6,6 +6,6 @@
6
6
  module SteamCondenser
7
7
 
8
8
  # The current version of Steam Condenser
9
- VERSION = '1.3.2'
9
+ VERSION = '1.3.3'
10
10
 
11
11
  end
@@ -37,28 +37,30 @@ class AlienSwarmStats < GameStats
37
37
  super steam_id, 'alienswarm'
38
38
 
39
39
  if public?
40
- @hours_played = @xml_data['stats']['lifetime']['timeplayed']
40
+ lifetime_data = @xml_data['stats']['lifetime']
41
+
42
+ @hours_played = lifetime_data['timeplayed']
41
43
 
42
44
  @lifetime_stats = {}
43
- @lifetime_stats[:accuracy] = @xml_data['stats']['lifetime']['accuracy'].to_f
44
- @lifetime_stats[:aliens_burned] = @xml_data['stats']['lifetime']['aliensburned'].to_i
45
- @lifetime_stats[:aliens_killed] = @xml_data['stats']['lifetime']['alienskilled'].to_i
46
- @lifetime_stats[:campaigns] = @xml_data['stats']['lifetime']['campaigns'].to_i
47
- @lifetime_stats[:damage_taken] = @xml_data['stats']['lifetime']['damagetaken'].to_i
48
- @lifetime_stats[:experience] = @xml_data['stats']['lifetime']['experience'].to_i
49
- @lifetime_stats[:experience_required] = @xml_data['stats']['lifetime']['xprequired'].to_i
50
- @lifetime_stats[:fast_hacks] = @xml_data['stats']['lifetime']['fasthacks'].to_i
51
- @lifetime_stats[:friendly_fire] = @xml_data['stats']['lifetime']['friendlyfire'].to_i
52
- @lifetime_stats[:games_successful] = @xml_data['stats']['lifetime']['gamessuccess'].to_i
53
- @lifetime_stats[:healing] = @xml_data['stats']['lifetime']['healing'].to_i
54
- @lifetime_stats[:kills_per_hour] = @xml_data['stats']['lifetime']['killsperhour'].to_f
55
- @lifetime_stats[:level] = @xml_data['stats']['lifetime']['level'].to_i
56
- @lifetime_stats[:promotion] = @xml_data['stats']['lifetime']['promotion'].to_i
57
- @lifetime_stats[:promotion_img] = BASE_URL + @xml_data['stats']['lifetime']['promotionpic'] if @lifetime_stats[:promotion] > 0
58
- @lifetime_stats[:next_unlock] = @xml_data['stats']['lifetime']['nextunlock']
59
- @lifetime_stats[:next_unlock_img] = BASE_URL + @xml_data['stats']['lifetime']['nextunlockimg']
60
- @lifetime_stats[:shots_fired] = @xml_data['stats']['lifetime']['shotsfired'].to_i
61
- @lifetime_stats[:total_games] = @xml_data['stats']['lifetime']['totalgames'].to_i
45
+ @lifetime_stats[:accuracy] = lifetime_data['accuracy'].to_f
46
+ @lifetime_stats[:aliens_burned] = lifetime_data['aliensburned'].to_i
47
+ @lifetime_stats[:aliens_killed] = lifetime_data['alienskilled'].to_i
48
+ @lifetime_stats[:campaigns] = lifetime_data['campaigns'].to_i
49
+ @lifetime_stats[:damage_taken] = lifetime_data['damagetaken'].to_i
50
+ @lifetime_stats[:experience] = lifetime_data['experience'].to_i
51
+ @lifetime_stats[:experience_required] = lifetime_data['xprequired'].to_i
52
+ @lifetime_stats[:fast_hacks] = lifetime_data['fasthacks'].to_i
53
+ @lifetime_stats[:friendly_fire] = lifetime_data['friendlyfire'].to_i
54
+ @lifetime_stats[:games_successful] = lifetime_data['gamessuccess'].to_i
55
+ @lifetime_stats[:healing] = lifetime_data['healing'].to_i
56
+ @lifetime_stats[:kills_per_hour] = lifetime_data['killsperhour'].to_f
57
+ @lifetime_stats[:level] = lifetime_data['level'].to_i
58
+ @lifetime_stats[:promotion] = lifetime_data['promotion'].to_i
59
+ @lifetime_stats[:promotion_img] = BASE_URL + lifetime_data['promotionpic'] if @lifetime_stats[:promotion] > 0
60
+ @lifetime_stats[:next_unlock] = lifetime_data['nextunlock']
61
+ @lifetime_stats[:next_unlock_img] = BASE_URL + lifetime_data['nextunlockimg']
62
+ @lifetime_stats[:shots_fired] = lifetime_data['shotsfired'].to_i
63
+ @lifetime_stats[:total_games] = lifetime_data['totalgames'].to_i
62
64
 
63
65
  @lifetime_stats[:games_successful_percentage] = (@lifetime_stats[:total_games] > 0) ? @lifetime_stats[:games_successful].to_f / @lifetime_stats[:total_games] : 0;
64
66
  end
@@ -73,27 +75,29 @@ class AlienSwarmStats < GameStats
73
75
  return unless public?
74
76
 
75
77
  if @favorites.nil?
78
+ favorites_data = @xml_data['stats']['favorites']
79
+
76
80
  @favorites = {}
77
- @favorites[:class] = @xml_data['stats']['favorites']['class']
78
- @favorites[:class_img] = @xml_data['stats']['favorites']['classimg']
79
- @favorites[:class_percentage] = @xml_data['stats']['favorites']['classpct'].to_f
80
- @favorites[:difficulty] = @xml_data['stats']['favorites']['difficulty']
81
- @favorites[:difficulty_percentage] = @xml_data['stats']['favorites']['difficultypct'].to_f
82
- @favorites[:extra] = @xml_data['stats']['favorites']['extra']
83
- @favorites[:extra_img] = @xml_data['stats']['favorites']['extraimg']
84
- @favorites[:extra_percentage] = @xml_data['stats']['favorites']['extrapct'].to_f
85
- @favorites[:marine] = @xml_data['stats']['favorites']['marine']
86
- @favorites[:marine_img] = @xml_data['stats']['favorites']['marineimg']
87
- @favorites[:marine_percentage] = @xml_data['stats']['favorites']['marinepct'].to_f
88
- @favorites[:mission] = @xml_data['stats']['favorites']['mission']
89
- @favorites[:mission_img] = @xml_data['stats']['favorites']['missionimg']
90
- @favorites[:mission_percentage] = @xml_data['stats']['favorites']['missionpct'].to_f
91
- @favorites[:primary_weapon] = @xml_data['stats']['favorites']['primary']
92
- @favorites[:primary_weapon_img] = @xml_data['stats']['favorites']['primaryimg']
93
- @favorites[:primary_weapon_percentage] = @xml_data['stats']['favorites']['primarypct'].to_f
94
- @favorites[:secondary_weapon] = @xml_data['stats']['favorites']['secondary']
95
- @favorites[:secondary_weapon_img] = @xml_data['stats']['favorites']['secondaryimg']
96
- @favorites[:secondary_weapon_percentage] = @xml_data['stats']['favorites']['secondarypct'].to_f
81
+ @favorites[:class] = favorites_data['class']
82
+ @favorites[:class_img] = favorites_data['classimg']
83
+ @favorites[:class_percentage] = favorites_data['classpct'].to_f
84
+ @favorites[:difficulty] = favorites_data['difficulty']
85
+ @favorites[:difficulty_percentage] = favorites_data['difficultypct'].to_f
86
+ @favorites[:extra] = favorites_data['extra']
87
+ @favorites[:extra_img] = favorites_data['extraimg']
88
+ @favorites[:extra_percentage] = favorites_data['extrapct'].to_f
89
+ @favorites[:marine] = favorites_data['marine']
90
+ @favorites[:marine_img] = favorites_data['marineimg']
91
+ @favorites[:marine_percentage] = favorites_data['marinepct'].to_f
92
+ @favorites[:mission] = favorites_data['mission']
93
+ @favorites[:mission_img] = favorites_data['missionimg']
94
+ @favorites[:mission_percentage] = favorites_data['missionpct'].to_f
95
+ @favorites[:primary_weapon] = favorites_data['primary']
96
+ @favorites[:primary_weapon_img] = favorites_data['primaryimg']
97
+ @favorites[:primary_weapon_percentage] = favorites_data['primarypct'].to_f
98
+ @favorites[:secondary_weapon] = favorites_data['secondary']
99
+ @favorites[:secondary_weapon_img] = favorites_data['secondaryimg']
100
+ @favorites[:secondary_weapon_percentage] = favorites_data['secondarypct'].to_f
97
101
  end
98
102
 
99
103
  @favorites
@@ -109,28 +113,30 @@ class AlienSwarmStats < GameStats
109
113
  return unless public?
110
114
 
111
115
  if @item_stats.nil?
116
+ weapons_data = @xml_data['stats']['weapons']
117
+
112
118
  @item_stats = {}
113
- @item_stats[:ammo_deployed] = @xml_data['stats']['weapons']['ammo_deployed'].to_i
114
- @item_stats[:sentryguns_deployed] = @xml_data['stats']['weapons']['sentryguns_deployed'].to_i
115
- @item_stats[:sentry_flamers_deployed] = @xml_data['stats']['weapons']['sentry_flamers_deployed'].to_i
116
- @item_stats[:sentry_freeze_deployed] = @xml_data['stats']['weapons']['sentry_freeze_deployed'].to_i
117
- @item_stats[:sentry_cannon_deployed] = @xml_data['stats']['weapons']['sentry_cannon_deployed'].to_i
118
- @item_stats[:medkits_used] = @xml_data['stats']['weapons']['medkits_used'].to_i
119
- @item_stats[:flares_used] = @xml_data['stats']['weapons']['flares_used'].to_i
120
- @item_stats[:adrenaline_used] = @xml_data['stats']['weapons']['adrenaline_used'].to_i
121
- @item_stats[:tesla_traps_deployed] = @xml_data['stats']['weapons']['tesla_traps_deployed'].to_i
122
- @item_stats[:freeze_grenades_thrown] = @xml_data['stats']['weapons']['freeze_grenades_thrown'].to_i
123
- @item_stats[:electric_armor_used] = @xml_data['stats']['weapons']['electric_armor_used'].to_i
124
- @item_stats[:healgun_heals] = @xml_data['stats']['weapons']['healgun_heals'].to_i
125
- @item_stats[:healgun_heals_self] = @xml_data['stats']['weapons']['healgun_heals_self'].to_i
126
- @item_stats[:healbeacon_heals] = @xml_data['stats']['weapons']['healbeacon_heals'].to_i
127
- @item_stats[:healbeacon_heals_self] = @xml_data['stats']['weapons']['healbeacon_heals_self'].to_i
128
- @item_stats[:damage_amps_used] = @xml_data['stats']['weapons']['damage_amps_used'].to_i
129
- @item_stats[:healbeacons_deployed] = @xml_data['stats']['weapons']['healbeacons_deployed'].to_i
130
- @item_stats[:healbeacon_heals_pct] = @xml_data['stats']['weapons']['healbeacon_heals_pct'].to_f
131
- @item_stats[:healgun_heals_pct] = @xml_data['stats']['weapons']['healgun_heals_pct'].to_f
132
- @item_stats[:healbeacon_heals_pct_self] = @xml_data['stats']['weapons']['healbeacon_heals_pct_self'].to_f
133
- @item_stats[:healgun_heals_pct_self] = @xml_data['stats']['weapons']['healgun_heals_pct_self'].to_f
119
+ @item_stats[:ammo_deployed] = weapons_data['ammo_deployed'].to_i
120
+ @item_stats[:sentryguns_deployed] = weapons_data['sentryguns_deployed'].to_i
121
+ @item_stats[:sentry_flamers_deployed] = weapons_data['sentry_flamers_deployed'].to_i
122
+ @item_stats[:sentry_freeze_deployed] = weapons_data['sentry_freeze_deployed'].to_i
123
+ @item_stats[:sentry_cannon_deployed] = weapons_data['sentry_cannon_deployed'].to_i
124
+ @item_stats[:medkits_used] = weapons_data['medkits_used'].to_i
125
+ @item_stats[:flares_used] = weapons_data['flares_used'].to_i
126
+ @item_stats[:adrenaline_used] = weapons_data['adrenaline_used'].to_i
127
+ @item_stats[:tesla_traps_deployed] = weapons_data['tesla_traps_deployed'].to_i
128
+ @item_stats[:freeze_grenades_thrown] = weapons_data['freeze_grenades_thrown'].to_i
129
+ @item_stats[:electric_armor_used] = weapons_data['electric_armor_used'].to_i
130
+ @item_stats[:healgun_heals] = weapons_data['healgun_heals'].to_i
131
+ @item_stats[:healgun_heals_self] = weapons_data['healgun_heals_self'].to_i
132
+ @item_stats[:healbeacon_heals] = weapons_data['healbeacon_heals'].to_i
133
+ @item_stats[:healbeacon_heals_self] = weapons_data['healbeacon_heals_self'].to_i
134
+ @item_stats[:damage_amps_used] = weapons_data['damage_amps_used'].to_i
135
+ @item_stats[:healbeacons_deployed] = weapons_data['healbeacons_deployed'].to_i
136
+ @item_stats[:healbeacon_heals_pct] = weapons_data['healbeacon_heals_pct'].to_f
137
+ @item_stats[:healgun_heals_pct] = weapons_data['healgun_heals_pct'].to_f
138
+ @item_stats[:healbeacon_heals_pct_self] = weapons_data['healbeacon_heals_pct_self'].to_f
139
+ @item_stats[:healgun_heals_pct_self] = weapons_data['healgun_heals_pct_self'].to_f
134
140
  end
135
141
 
136
142
  @item_stats
@@ -1,7 +1,7 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2010, Sebastian Staudt
4
+ # Copyright (c) 2010-2013, Sebastian Staudt
5
5
 
6
6
  require 'steam/community/css/css_map'
7
7
  require 'steam/community/css/css_weapon'
@@ -44,48 +44,53 @@ class CSSStats < GameStats
44
44
  super steam_id, 'cs:s'
45
45
 
46
46
  if public?
47
+ last_match_data = @xml_data['stats']['lastmatch']
48
+ lifetime_data = @xml_data['stats']['lifetime']
49
+ summary_data = @xml_data['stats']['summary']
50
+
47
51
  @last_match_stats = {}
48
52
  @total_stats = {}
49
53
 
50
- @last_match_stats[:cost_per_kill] = @xml_data['stats']['lastmatch']['costkill'].to_f
51
- @last_match_stats[:ct_wins] = @xml_data['stats']['lastmatch']['ct_wins'].to_i
52
- @last_match_stats[:damage] = @xml_data['stats']['lastmatch']['dmg'].to_i
53
- @last_match_stats[:deaths] = @xml_data['stats']['lastmatch']['deaths'].to_i
54
- @last_match_stats[:dominations] = @xml_data['stats']['lastmatch']['dominations'].to_i
55
- @last_match_stats[:favorite_weapon_id] = @xml_data['stats']['lastmatch']['favwpnid'].to_i
56
- @last_match_stats[:kills] = @xml_data['stats']['lastmatch']['kills'].to_i
57
- @last_match_stats[:max_players] = @xml_data['stats']['lastmatch']['max_players'].to_i
58
- @last_match_stats[:money] = @xml_data['stats']['lastmatch']['money'].to_i
59
- @last_match_stats[:revenges] = @xml_data['stats']['lastmatch']['revenges'].to_i
60
- @last_match_stats[:stars] = @xml_data['stats']['lastmatch']['stars'].to_i
61
- @last_match_stats[:t_wins] = @xml_data['stats']['lastmatch']['t_wins'].to_i
62
- @last_match_stats[:wins] = @xml_data['stats']['lastmatch']['wins'].to_i
63
- @total_stats[:blind_kills] = @xml_data['stats']['lifetime']['blindkills'].to_i
64
- @total_stats[:bombs_defused] = @xml_data['stats']['lifetime']['bombsdefused'].to_i
65
- @total_stats[:bombs_planted] = @xml_data['stats']['lifetime']['bombsplanted'].to_i
66
- @total_stats[:damage] = @xml_data['stats']['lifetime']['dmg'].to_i
67
- @total_stats[:deaths] = @xml_data['stats']['summary']['deaths'].to_i
68
- @total_stats[:domination_overkills] = @xml_data['stats']['lifetime']['dominationoverkills'].to_i
69
- @total_stats[:dominations] = @xml_data['stats']['lifetime']['dominations'].to_i
70
- @total_stats[:earned_money] = @xml_data['stats']['lifetime']['money'].to_i
71
- @total_stats[:enemy_weapon_kills] = @xml_data['stats']['lifetime']['enemywpnkills'].to_i
72
- @total_stats[:headshots] = @xml_data['stats']['lifetime']['headshots'].to_i
73
- @total_stats[:hits] = @xml_data['stats']['summary']['shotshit'].to_i
74
- @total_stats[:hostages_rescued] = @xml_data['stats']['lifetime']['hostagesrescued'].to_i
75
- @total_stats[:kills] = @xml_data['stats']['summary']['kills'].to_i
76
- @total_stats[:knife_kills] = @xml_data['stats']['lifetime']['knifekills'].to_i
77
- @total_stats[:logos_sprayed] = @xml_data['stats']['lifetime']['decals'].to_i
78
- @total_stats[:nightvision_damage] = @xml_data['stats']['lifetime']['nvgdmg'].to_i
79
- @total_stats[:pistol_rounds_won] = @xml_data['stats']['lifetime']['pistolrounds'].to_i
80
- @total_stats[:revenges] = @xml_data['stats']['lifetime']['revenges'].to_i
81
- @total_stats[:rounds_played] = @xml_data['stats']['summary']['rounds'].to_i
82
- @total_stats[:rounds_won] = @xml_data['stats']['summary']['wins'].to_i
83
- @total_stats[:seconds_played] = @xml_data['stats']['summary']['timeplayed'].to_i
84
- @total_stats[:shots] = @xml_data['stats']['summary']['shots'].to_i
85
- @total_stats[:stars] = @xml_data['stats']['summary']['stars'].to_i
86
- @total_stats[:weapons_donated] = @xml_data['stats']['lifetime']['wpndonated'].to_i
87
- @total_stats[:windows_broken] = @xml_data['stats']['lifetime']['winbroken'].to_i
88
- @total_stats[:zoomed_sniper_kills] = @xml_data['stats']['lifetime']['zsniperkills'].to_i
54
+ @last_match_stats[:cost_per_kill] = last_match_data['costkill'].to_f
55
+ @last_match_stats[:ct_wins] = last_match_data['ct_wins'].to_i
56
+ @last_match_stats[:damage] = last_match_data['dmg'].to_i
57
+ @last_match_stats[:deaths] = last_match_data['deaths'].to_i
58
+ @last_match_stats[:dominations] = last_match_data['dominations'].to_i
59
+ @last_match_stats[:favorite_weapon_id] = last_match_data['favwpnid'].to_i
60
+ @last_match_stats[:kills] = last_match_data['kills'].to_i
61
+ @last_match_stats[:max_players] = last_match_data['max_players'].to_i
62
+ @last_match_stats[:money] = last_match_data['money'].to_i
63
+ @last_match_stats[:revenges] = last_match_data['revenges'].to_i
64
+ @last_match_stats[:stars] = last_match_data['stars'].to_i
65
+ @last_match_stats[:t_wins] = last_match_data['t_wins'].to_i
66
+ @last_match_stats[:wins] = last_match_data['wins'].to_i
67
+
68
+ @total_stats[:blind_kills] = lifetime_data['blindkills'].to_i
69
+ @total_stats[:bombs_defused] = lifetime_data['bombsdefused'].to_i
70
+ @total_stats[:bombs_planted] = lifetime_data['bombsplanted'].to_i
71
+ @total_stats[:damage] = lifetime_data['dmg'].to_i
72
+ @total_stats[:deaths] = summary_data['deaths'].to_i
73
+ @total_stats[:domination_overkills] = lifetime_data['dominationoverkills'].to_i
74
+ @total_stats[:dominations] = lifetime_data['dominations'].to_i
75
+ @total_stats[:earned_money] = lifetime_data['money'].to_i
76
+ @total_stats[:enemy_weapon_kills] = lifetime_data['enemywpnkills'].to_i
77
+ @total_stats[:headshots] = lifetime_data['headshots'].to_i
78
+ @total_stats[:hits] = summary_data['shotshit'].to_i
79
+ @total_stats[:hostages_rescued] = lifetime_data['hostagesrescued'].to_i
80
+ @total_stats[:kills] = summary_data['kills'].to_i
81
+ @total_stats[:knife_kills] = lifetime_data['knifekills'].to_i
82
+ @total_stats[:logos_sprayed] = lifetime_data['decals'].to_i
83
+ @total_stats[:nightvision_damage] = lifetime_data['nvgdmg'].to_i
84
+ @total_stats[:pistol_rounds_won] = lifetime_data['pistolrounds'].to_i
85
+ @total_stats[:revenges] = lifetime_data['revenges'].to_i
86
+ @total_stats[:rounds_played] = summary_data['rounds'].to_i
87
+ @total_stats[:rounds_won] = summary_data['wins'].to_i
88
+ @total_stats[:seconds_played] = summary_data['timeplayed'].to_i
89
+ @total_stats[:shots] = summary_data['shots'].to_i
90
+ @total_stats[:stars] = summary_data['stars'].to_i
91
+ @total_stats[:weapons_donated] = lifetime_data['wpndonated'].to_i
92
+ @total_stats[:windows_broken] = lifetime_data['winbroken'].to_i
93
+ @total_stats[:zoomed_sniper_kills] = lifetime_data['zsniperkills'].to_i
89
94
 
90
95
  @last_match_stats[:kdratio] = (@total_stats[:deaths] > 0) ? @last_match_stats[:kills].to_f / @last_match_stats[:deaths] : 0
91
96
  @total_stats[:accuracy] = (@total_stats[:shots] > 0) ? @total_stats[:hits].to_f / @total_stats[:shots] : 0
@@ -1,18 +1,21 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2011-2012, Sebastian Staudt
4
+ # Copyright (c) 2011-2013, Sebastian Staudt
5
5
 
6
6
  require 'multi_xml'
7
7
 
8
8
  require 'steam/community/game_leaderboard_entry'
9
9
  require 'steam/community/steam_id'
10
+ require 'steam/community/xml_data'
10
11
 
11
12
  # The GameLeaderboard class represents a single leaderboard for a specific game
12
13
  #
13
14
  # @author Sebastian Staudt
14
15
  class GameLeaderboard
15
16
 
17
+ include XMLData
18
+
16
19
  LEADERBOARD_DISPLAY_TYPE_NONE = 0
17
20
  LEADERBOARD_DISPLAY_TYPE_NUMERIC = 1
18
21
  LEADERBOARD_DISPLAY_TYPE_SECONDS = 2
@@ -86,13 +89,12 @@ class GameLeaderboard
86
89
  def entry_for_steam_id(steam_id)
87
90
  steam_id = steam_id.steam_id64 if steam_id.is_a? SteamId
88
91
 
89
- url = "#@url&steamid=#{steam_id}"
90
- xml_data = MultiXml.parse(open(url, {:proxy => true})).values.first
92
+ parse "#@url&steamid=#{steam_id}"
91
93
 
92
- error = xml_data['error']
94
+ error = @xml_data['error']
93
95
  raise SteamCondenserError, error unless error.nil?
94
96
 
95
- xml_data['entries']['entry'].each do |entry_data|
97
+ @xml_data['entries']['entry'].each do |entry_data|
96
98
  if entry_data['steamid'].to_i == steam_id
97
99
  return GameLeaderboardEntry.new entry_data, self
98
100
  end
@@ -113,14 +115,13 @@ class GameLeaderboard
113
115
  def entry_for_steam_id_friends(steam_id)
114
116
  steam_id = steam_id.steam_id64 if steam_id.is_a? SteamId
115
117
 
116
- url = "#@url&steamid=#{steam_id}"
117
- xml_data = MultiXml.parse(open(url, {:proxy => true})).values.first
118
+ parse "#@url&steamid=#{steam_id}"
118
119
 
119
- error = xml_data['error']
120
+ error = @xml_data['error']
120
121
  raise SteamCondenserError, error unless error.nil?
121
122
 
122
123
  entries = []
123
- xml_data['entries']['entry'].each do |entry_data|
124
+ @xml_data['entries']['entry'].each do |entry_data|
124
125
  rank = entry_data['rank'].to_i
125
126
  entries[rank] = GameLeaderboardEntry.new entry_data, self
126
127
  end
@@ -150,14 +151,13 @@ class GameLeaderboard
150
151
  'Leaderboard entry lookup is currently limited to a maximum of 5001 entries per request.'
151
152
  end
152
153
 
153
- url = "#@url&start=#{first}&end=#{last}"
154
- xml_data = MultiXml.parse(open(url, {:proxy => true})).values.first
154
+ parse "#@url&start=#{first}&end=#{last}"
155
155
 
156
- error = xml_data['error']
156
+ error = @xml_data['error']
157
157
  raise SteamCondenserError, error unless error.nil?
158
158
 
159
159
  entries = []
160
- xml_data['entries']['entry'].each do |entry_data|
160
+ @xml_data['entries']['entry'].each do |entry_data|
161
161
  rank = entry_data['rank'].to_i
162
162
  entries[rank] = GameLeaderboardEntry.new entry_data, self
163
163
  end
@@ -185,8 +185,12 @@ class GameLeaderboard
185
185
  # @raise [SteamCondenserException] if an error occurs while fetching the
186
186
  # leaderboards
187
187
  def self.load_leaderboards(game_name)
188
- url = "http://steamcommunity.com/stats/#{game_name}/leaderboards/?xml=1"
189
- boards_data = MultiXml.parse(open(url, {:proxy => true})).values.first
188
+ begin
189
+ url = "http://steamcommunity.com/stats/#{game_name}/leaderboards/?xml=1"
190
+ boards_data = MultiXml.parse(open(url, {:proxy => true})).values.first
191
+ rescue
192
+ raise SteamCondenserError.new 'XML data could not be parsed.', $!
193
+ end
190
194
 
191
195
  error = boards_data['error']
192
196
  raise SteamCondenserError, error unless error.nil?
@@ -100,7 +100,7 @@ class GameStats
100
100
  # @param [String] game_id The application ID or friendly name of the game
101
101
  # @raise [SteamCondenserError] if the stats cannot be fetched
102
102
  def initialize(user_id, game_id)
103
- @xml_data = parse "#{self.class.base_url(user_id, game_id)}?xml=all"
103
+ parse "#{self.class.base_url(user_id, game_id)}?xml=all"
104
104
 
105
105
  @user = SteamId.new user_id, false
106
106
 
@@ -1,7 +1,7 @@
1
1
  # This code is free software; you can redistribute it and/or modify it under
2
2
  # the terms of the new BSD License.
3
3
  #
4
- # Copyright (c) 2009-2011, Sebastian Staudt
4
+ # Copyright (c) 2009-2013, Sebastian Staudt
5
5
 
6
6
  require 'steam/community/game_stats'
7
7
 
@@ -29,12 +29,14 @@ module AbstractL4DStats
29
29
  super steam_id, game_name
30
30
 
31
31
  if public?
32
+ most_recent_game_data = @xml_data['stats']['mostrecentgame']
33
+
32
34
  @most_recent_game = {}
33
- unless @xml_data['stats']['mostrecentgame'].nil?
34
- @most_recent_game[:difficulty] = @xml_data['stats']['mostrecentgame']['difficulty']
35
- @most_recent_game[:escaped] = (@xml_data['stats']['mostrecentgame']['bEscaped'] == 1)
36
- @most_recent_game[:movie] = @xml_data['stats']['mostrecentgame']['movie']
37
- @most_recent_game[:time_played] = @xml_data['stats']['mostrecentgame']['time']
35
+ unless most_recent_game_data.nil?
36
+ @most_recent_game[:difficulty] = most_recent_game_data['difficulty']
37
+ @most_recent_game[:escaped] = (most_recent_game_data['bEscaped'] == 1)
38
+ @most_recent_game[:movie] = most_recent_game_data['movie']
39
+ @most_recent_game[:time_played] = most_recent_game_data['time']
38
40
  end
39
41
  end
40
42
  end
@@ -48,15 +50,17 @@ module AbstractL4DStats
48
50
  return unless public?
49
51
 
50
52
  if @favorites.nil?
53
+ favorites_data = @xml_data['stats']['favorites']
54
+
51
55
  @favorites = {}
52
- @favorites[:campaign] = @xml_data['stats']['favorites']['campaign']
53
- @favorites[:campaign_percentage] = @xml_data['stats']['favorites']['campaignpct'].to_i
54
- @favorites[:character] = @xml_data['stats']['favorites']['character']
55
- @favorites[:character_percentage] = @xml_data['stats']['favorites']['characterpct'].to_i
56
- @favorites[:level1_weapon] = @xml_data['stats']['favorites']['weapon1']
57
- @favorites[:level1_weapon_percentage] = @xml_data['stats']['favorites']['weapon1pct'].to_i
58
- @favorites[:level2_weapon] = @xml_data['stats']['favorites']['weapon2']
59
- @favorites[:level2_weapon_percentage] = @xml_data['stats']['favorites']['weapon2pct'].to_i
56
+ @favorites[:campaign] = favorites_data['campaign']
57
+ @favorites[:campaign_percentage] = favorites_data['campaignpct'].to_i
58
+ @favorites[:character] = favorites_data['character']
59
+ @favorites[:character_percentage] = favorites_data['characterpct'].to_i
60
+ @favorites[:level1_weapon] = favorites_data['weapon1']
61
+ @favorites[:level1_weapon_percentage] = favorites_data['weapon1pct'].to_i
62
+ @favorites[:level2_weapon] = favorites_data['weapon2']
63
+ @favorites[:level2_weapon_percentage] = favorites_data['weapon2pct'].to_i
60
64
  end
61
65
 
62
66
  @favorites
@@ -72,16 +76,18 @@ module AbstractL4DStats
72
76
  return unless public?
73
77
 
74
78
  if @lifetime_stats.nil?
79
+ lifetime_data = @xml_data['stats']['lifetime']
80
+
75
81
  @lifetime_stats = {}
76
- @lifetime_stats[:finales_survived] = @xml_data['stats']['lifetime']['finales'].to_i
77
- @lifetime_stats[:games_played] = @xml_data['stats']['lifetime']['gamesplayed'].to_i
78
- @lifetime_stats[:infected_killed] = @xml_data['stats']['lifetime']['infectedkilled'].to_i
79
- @lifetime_stats[:kills_per_hour] = @xml_data['stats']['lifetime']['killsperhour'].to_f
80
- @lifetime_stats[:avg_kits_shared] = @xml_data['stats']['lifetime']['kitsshared'].to_f
81
- @lifetime_stats[:avg_kits_used] = @xml_data['stats']['lifetime']['kitsused'].to_f
82
- @lifetime_stats[:avg_pills_shared] = @xml_data['stats']['lifetime']['pillsshared'].to_f
83
- @lifetime_stats[:avg_pills_used] = @xml_data['stats']['lifetime']['pillsused'].to_f
84
- @lifetime_stats[:time_played] = @xml_data['stats']['lifetime']['timeplayed']
82
+ @lifetime_stats[:finales_survived] = lifetime_data['finales'].to_i
83
+ @lifetime_stats[:games_played] = lifetime_data['gamesplayed'].to_i
84
+ @lifetime_stats[:infected_killed] = lifetime_data['infectedkilled'].to_i
85
+ @lifetime_stats[:kills_per_hour] = lifetime_data['killsperhour'].to_f
86
+ @lifetime_stats[:avg_kits_shared] = lifetime_data['kitsshared'].to_f
87
+ @lifetime_stats[:avg_kits_used] = lifetime_data['kitsused'].to_f
88
+ @lifetime_stats[:avg_pills_shared] = lifetime_data['pillsshared'].to_f
89
+ @lifetime_stats[:avg_pills_used] = lifetime_data['pillsused'].to_f
90
+ @lifetime_stats[:time_played] = lifetime_data['timeplayed']
85
91
 
86
92
  @lifetime_stats[:finales_survived_percentage] = @lifetime_stats[:finales_survived].to_f / @lifetime_stats[:games_played]
87
93
  end
@@ -99,12 +105,14 @@ module AbstractL4DStats
99
105
  return unless public?
100
106
 
101
107
  if @survival_stats.nil?
108
+ survival_data = @xml_data['stats']['survival']
109
+
102
110
  @survival_stats = {}
103
- @survival_stats[:gold_medals] = @xml_data['stats']['survival']['goldmedals'].to_i
104
- @survival_stats[:silver_medals] = @xml_data['stats']['survival']['silvermedals'].to_i
105
- @survival_stats[:bronze_medals] = @xml_data['stats']['survival']['bronzemedals'].to_i
106
- @survival_stats[:rounds_played] = @xml_data['stats']['survival']['roundsplayed'].to_i
107
- @survival_stats[:best_time] = @xml_data['stats']['survival']['besttime'].to_f
111
+ @survival_stats[:gold_medals] = survival_data['goldmedals'].to_i
112
+ @survival_stats[:silver_medals] = survival_data['silvermedals'].to_i
113
+ @survival_stats[:bronze_medals] = survival_data['bronzemedals'].to_i
114
+ @survival_stats[:rounds_played] = survival_data['roundsplayed'].to_i
115
+ @survival_stats[:best_time] = survival_data['besttime'].to_f
108
116
  end
109
117
 
110
118
  @survival_stats
@@ -120,18 +128,20 @@ module AbstractL4DStats
120
128
  return unless public?
121
129
 
122
130
  if @teamplay_stats.nil?
131
+ teamplay_data = @xml_data['stats']['teamplay']
132
+
123
133
  @teamplay_stats = {}
124
- @teamplay_stats[:revived] = @xml_data['stats']['teamplay']['revived'].to_i
125
- @teamplay_stats[:most_revived_difficulty] = @xml_data['stats']['teamplay']['reviveddiff']
126
- @teamplay_stats[:avg_revived] = @xml_data['stats']['teamplay']['revivedavg'].to_f
127
- @teamplay_stats[:avg_was_revived] = @xml_data['stats']['teamplay']['wasrevivedavg'].to_f
128
- @teamplay_stats[:protected] = @xml_data['stats']['teamplay']['protected'].to_i
129
- @teamplay_stats[:most_protected_difficulty] = @xml_data['stats']['teamplay']['protecteddiff']
130
- @teamplay_stats[:avg_protected] = @xml_data['stats']['teamplay']['protectedavg'].to_f
131
- @teamplay_stats[:avg_was_protected] = @xml_data['stats']['teamplay']['wasprotectedavg'].to_f
132
- @teamplay_stats[:friendly_fire_damage] = @xml_data['stats']['teamplay']['ffdamage'].to_i
133
- @teamplay_stats[:most_friendly_fire_difficulty] = @xml_data['stats']['teamplay']['ffdamagediff']
134
- @teamplay_stats[:avg_friendly_fire_damage] = @xml_data['stats']['teamplay']['ffdamageavg'].to_f
134
+ @teamplay_stats[:revived] = teamplay_data['revived'].to_i
135
+ @teamplay_stats[:most_revived_difficulty] = teamplay_data['reviveddiff']
136
+ @teamplay_stats[:avg_revived] = teamplay_data['revivedavg'].to_f
137
+ @teamplay_stats[:avg_was_revived] = teamplay_data['wasrevivedavg'].to_f
138
+ @teamplay_stats[:protected] = teamplay_data['protected'].to_i
139
+ @teamplay_stats[:most_protected_difficulty] = teamplay_data['protecteddiff']
140
+ @teamplay_stats[:avg_protected] = teamplay_data['protectedavg'].to_f
141
+ @teamplay_stats[:avg_was_protected] = teamplay_data['wasprotectedavg'].to_f
142
+ @teamplay_stats[:friendly_fire_damage] = teamplay_data['ffdamage'].to_i
143
+ @teamplay_stats[:most_friendly_fire_difficulty] = teamplay_data['ffdamagediff']
144
+ @teamplay_stats[:avg_friendly_fire_damage] = teamplay_data['ffdamageavg'].to_f
135
145
  end
136
146
 
137
147
  @teamplay_stats
@@ -147,23 +157,25 @@ module AbstractL4DStats
147
157
  return unless public?
148
158
 
149
159
  if @versus_stats.nil?
160
+ versus_data = @xml_data['stats']['versus']
161
+
150
162
  @versus_stats = {}
151
- @versus_stats[:games_played] = @xml_data['stats']['versus']['gamesplayed'].to_i
152
- @versus_stats[:games_completed] = @xml_data['stats']['versus']['gamescompleted'].to_i
153
- @versus_stats[:finales_survived] = @xml_data['stats']['versus']['finales'].to_i
154
- @versus_stats[:points] = @xml_data['stats']['versus']['points'].to_i
155
- @versus_stats[:most_points_infected] = @xml_data['stats']['versus']['pointsas']
156
- @versus_stats[:games_won] = @xml_data['stats']['versus']['gameswon'].to_i
157
- @versus_stats[:games_lost] = @xml_data['stats']['versus']['gameslost'].to_i
158
- @versus_stats[:highest_survivor_score] = @xml_data['stats']['versus']['survivorscore'].to_i
163
+ @versus_stats[:games_played] = versus_data['gamesplayed'].to_i
164
+ @versus_stats[:games_completed] = versus_data['gamescompleted'].to_i
165
+ @versus_stats[:finales_survived] = versus_data['finales'].to_i
166
+ @versus_stats[:points] = versus_data['points'].to_i
167
+ @versus_stats[:most_points_infected] = versus_data['pointsas']
168
+ @versus_stats[:games_won] = versus_data['gameswon'].to_i
169
+ @versus_stats[:games_lost] = versus_data['gameslost'].to_i
170
+ @versus_stats[:highest_survivor_score] = versus_data['survivorscore'].to_i
159
171
 
160
172
  @versus_stats[:finales_survived_percentage] = @versus_stats[:finales_survived].to_f / @versus_stats[:games_played]
161
173
 
162
174
  self.class.const_get(:SPECIAL_INFECTED).each do |infected|
163
175
  @versus_stats[infected] = {}
164
- @versus_stats[infected][:special_attacks] = @xml_data['stats']['versus']["#{infected}special"].to_i
165
- @versus_stats[infected][:most_damage] = @xml_data['stats']['versus']["#{infected}dmg"].to_i
166
- @versus_stats[infected]['avg_lifespan'] = @xml_data['stats']['versus']["#{infected}lifespan"].to_i
176
+ @versus_stats[infected][:special_attacks] = versus_data["#{infected}special"].to_i
177
+ @versus_stats[infected][:most_damage] = versus_data["#{infected}dmg"].to_i
178
+ @versus_stats[infected]['avg_lifespan'] = versus_data["#{infected}lifespan"].to_i
167
179
  end
168
180
  end
169
181