steam-condenser 1.3.5 → 1.3.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +228 -0
  3. data/CONTRIBUTING.md +59 -0
  4. data/Gemfile.lock +12 -13
  5. data/README.md +9 -4
  6. data/lib/steam-condenser/version.rb +1 -1
  7. data/lib/steam/community/alien_swarm/alien_swarm_mission.rb +10 -9
  8. data/lib/steam/community/alien_swarm/alien_swarm_stats.rb +74 -72
  9. data/lib/steam/community/css/css_map.rb +2 -2
  10. data/lib/steam/community/css/css_stats.rb +54 -56
  11. data/lib/steam/community/css/css_weapon.rb +4 -4
  12. data/lib/steam/community/game_item.rb +2 -3
  13. data/lib/steam/community/game_leaderboard.rb +22 -15
  14. data/lib/steam/community/l4d/abstract_l4d_stats.rb +64 -61
  15. data/lib/steam/community/l4d/l4d2_stats.rb +26 -21
  16. data/lib/steam/community/steam_id.rb +8 -11
  17. data/lib/steam/community/web_api.rb +19 -14
  18. data/lib/steam/packets/s2a_info2_packet.rb +16 -14
  19. data/lib/steam/packets/s2a_info_detailed_packet.rb +24 -19
  20. data/lib/steam/packets/steam_packet_factory.rb +7 -2
  21. data/lib/steam/servers/game_server.rb +3 -2
  22. data/lib/steam/servers/master_server.rb +1 -1
  23. data/lib/steam/sockets/source_socket.rb +4 -9
  24. data/pkg/steam-condenser-1.3.5.gem +0 -0
  25. data/pkg/steam-condenser-1.3.5/Gemfile +7 -0
  26. data/pkg/steam-condenser-1.3.5/Gemfile.lock +45 -0
  27. data/pkg/steam-condenser-1.3.5/LICENSE +25 -0
  28. data/pkg/steam-condenser-1.3.5/README.md +70 -0
  29. data/pkg/steam-condenser-1.3.5/Rakefile +46 -0
  30. data/pkg/steam-condenser-1.3.5/lib/core_ext/stringio.rb +91 -0
  31. data/pkg/steam-condenser-1.3.5/lib/errors/packet_format_error.rb +13 -0
  32. data/pkg/steam-condenser-1.3.5/lib/errors/rcon_ban_error.rb +22 -0
  33. data/pkg/steam-condenser-1.3.5/lib/errors/rcon_no_auth_error.rb +21 -0
  34. data/pkg/steam-condenser-1.3.5/lib/errors/steam_condenser_error.rb +26 -0
  35. data/pkg/steam-condenser-1.3.5/lib/errors/timeout_error.rb +28 -0
  36. data/pkg/steam-condenser-1.3.5/lib/errors/web_api_error.rb +57 -0
  37. data/pkg/steam-condenser-1.3.5/lib/steam-condenser.rb +18 -0
  38. data/pkg/steam-condenser-1.3.5/lib/steam-condenser/community.rb +24 -0
  39. data/pkg/steam-condenser-1.3.5/lib/steam-condenser/servers.rb +24 -0
  40. data/pkg/steam-condenser-1.3.5/lib/steam-condenser/version.rb +11 -0
  41. data/pkg/steam-condenser-1.3.5/lib/steam/community/alien_swarm/alien_swarm_mission.rb +119 -0
  42. data/pkg/steam-condenser-1.3.5/lib/steam/community/alien_swarm/alien_swarm_stats.rb +186 -0
  43. data/pkg/steam-condenser-1.3.5/lib/steam/community/alien_swarm/alien_swarm_weapon.rb +49 -0
  44. data/pkg/steam-condenser-1.3.5/lib/steam/community/app_news.rb +133 -0
  45. data/pkg/steam-condenser-1.3.5/lib/steam/community/cacheable.rb +199 -0
  46. data/pkg/steam-condenser-1.3.5/lib/steam/community/css/css_map.rb +61 -0
  47. data/pkg/steam-condenser-1.3.5/lib/steam/community/css/css_stats.rb +142 -0
  48. data/pkg/steam-condenser-1.3.5/lib/steam/community/css/css_weapon.rb +69 -0
  49. data/pkg/steam-condenser-1.3.5/lib/steam/community/defense_grid/defense_grid_stats.rb +238 -0
  50. data/pkg/steam-condenser-1.3.5/lib/steam/community/dods/dods_class.rb +90 -0
  51. data/pkg/steam-condenser-1.3.5/lib/steam/community/dods/dods_stats.rb +62 -0
  52. data/pkg/steam-condenser-1.3.5/lib/steam/community/dods/dods_weapon.rb +67 -0
  53. data/pkg/steam-condenser-1.3.5/lib/steam/community/dota2/dota2_beta_inventory.rb +30 -0
  54. data/pkg/steam-condenser-1.3.5/lib/steam/community/dota2/dota2_inventory.rb +30 -0
  55. data/pkg/steam-condenser-1.3.5/lib/steam/community/dota2/dota2_item.rb +33 -0
  56. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_achievement.rb +109 -0
  57. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_class.rb +22 -0
  58. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_inventory.rb +171 -0
  59. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_item.rb +156 -0
  60. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_item_schema.rb +131 -0
  61. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_leaderboard.rb +205 -0
  62. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_leaderboard_entry.rb +43 -0
  63. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_stats.rb +175 -0
  64. data/pkg/steam-condenser-1.3.5/lib/steam/community/game_weapon.rb +41 -0
  65. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/abstract_l4d_stats.rb +185 -0
  66. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/abstract_l4d_weapon.rb +56 -0
  67. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d2_map.rb +90 -0
  68. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d2_stats.rb +174 -0
  69. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d2_weapon.rb +38 -0
  70. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d_explosive.rb +34 -0
  71. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d_map.rb +65 -0
  72. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d_stats.rb +73 -0
  73. data/pkg/steam-condenser-1.3.5/lib/steam/community/l4d/l4d_weapon.rb +26 -0
  74. data/pkg/steam-condenser-1.3.5/lib/steam/community/portal2/portal2_inventory.rb +30 -0
  75. data/pkg/steam-condenser-1.3.5/lib/steam/community/portal2/portal2_item.rb +55 -0
  76. data/pkg/steam-condenser-1.3.5/lib/steam/community/portal2/portal2_stats.rb +33 -0
  77. data/pkg/steam-condenser-1.3.5/lib/steam/community/steam_game.rb +193 -0
  78. data/pkg/steam-condenser-1.3.5/lib/steam/community/steam_group.rb +129 -0
  79. data/pkg/steam-condenser-1.3.5/lib/steam/community/steam_id.rb +498 -0
  80. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_beta_inventory.rb +28 -0
  81. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_class.rb +92 -0
  82. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_class_factory.rb +40 -0
  83. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_engineer.rb +43 -0
  84. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_golden_wrench.rb +70 -0
  85. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_inventory.rb +30 -0
  86. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_item.rb +55 -0
  87. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_medic.rb +35 -0
  88. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_sniper.rb +28 -0
  89. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_spy.rb +41 -0
  90. data/pkg/steam-condenser-1.3.5/lib/steam/community/tf2/tf2_stats.rb +77 -0
  91. data/pkg/steam-condenser-1.3.5/lib/steam/community/web_api.rb +130 -0
  92. data/pkg/steam-condenser-1.3.5/lib/steam/community/xml_data.rb +27 -0
  93. data/pkg/steam-condenser-1.3.5/lib/steam/packets/a2m_get_servers_batch2_packet.rb +59 -0
  94. data/pkg/steam-condenser-1.3.5/lib/steam/packets/a2s_info_packet.rb +24 -0
  95. data/pkg/steam-condenser-1.3.5/lib/steam/packets/a2s_player_packet.rb +31 -0
  96. data/pkg/steam-condenser-1.3.5/lib/steam/packets/a2s_rules_packet.rb +32 -0
  97. data/pkg/steam-condenser-1.3.5/lib/steam/packets/a2s_serverquery_getchallenge_packet.rb +25 -0
  98. data/pkg/steam-condenser-1.3.5/lib/steam/packets/c2m_checkmd5_packet.rb +31 -0
  99. data/pkg/steam-condenser-1.3.5/lib/steam/packets/m2a_server_batch_packet.rb +52 -0
  100. data/pkg/steam-condenser-1.3.5/lib/steam/packets/m2c_isvalidmd5_packet.rb +34 -0
  101. data/pkg/steam-condenser-1.3.5/lib/steam/packets/m2s_requestrestart_packet.rb +34 -0
  102. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_auth_request.rb +28 -0
  103. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_auth_response.rb +30 -0
  104. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_exec_request.rb +28 -0
  105. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_exec_response.rb +37 -0
  106. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_goldsrc_request.rb +35 -0
  107. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_goldsrc_response.rb +34 -0
  108. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_packet.rb +57 -0
  109. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_packet_factory.rb +43 -0
  110. data/pkg/steam-condenser-1.3.5/lib/steam/packets/rcon/rcon_terminator.rb +29 -0
  111. data/pkg/steam-condenser-1.3.5/lib/steam/packets/request_with_challenge.rb +19 -0
  112. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2a_info2_packet.rb +74 -0
  113. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2a_info_base_packet.rb +25 -0
  114. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2a_info_detailed_packet.rb +59 -0
  115. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2a_logstring_packet.rb +30 -0
  116. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2a_player_packet.rb +44 -0
  117. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2a_rules_packet.rb +48 -0
  118. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2c_challenge_packet.rb +35 -0
  119. data/pkg/steam-condenser-1.3.5/lib/steam/packets/s2m_heartbeat2_packet.rb +72 -0
  120. data/pkg/steam-condenser-1.3.5/lib/steam/packets/steam_packet.rb +52 -0
  121. data/pkg/steam-condenser-1.3.5/lib/steam/packets/steam_packet_factory.rb +108 -0
  122. data/pkg/steam-condenser-1.3.5/lib/steam/servers/game_server.rb +392 -0
  123. data/pkg/steam-condenser-1.3.5/lib/steam/servers/goldsrc_server.rb +74 -0
  124. data/pkg/steam-condenser-1.3.5/lib/steam/servers/master_server.rb +188 -0
  125. data/pkg/steam-condenser-1.3.5/lib/steam/servers/server.rb +115 -0
  126. data/pkg/steam-condenser-1.3.5/lib/steam/servers/source_server.rb +117 -0
  127. data/pkg/steam-condenser-1.3.5/lib/steam/sockets/goldsrc_socket.rb +142 -0
  128. data/pkg/steam-condenser-1.3.5/lib/steam/sockets/master_server_socket.rb +34 -0
  129. data/pkg/steam-condenser-1.3.5/lib/steam/sockets/rcon_socket.rb +103 -0
  130. data/pkg/steam-condenser-1.3.5/lib/steam/sockets/source_socket.rb +78 -0
  131. data/pkg/steam-condenser-1.3.5/lib/steam/sockets/steam_socket.rb +91 -0
  132. data/pkg/steam-condenser-1.3.5/lib/steam/steam_player.rb +143 -0
  133. data/pkg/steam-condenser-1.3.5/steam-condenser.gemspec +26 -0
  134. data/pkg/steam-condenser-1.3.5/test/core_ext/test_stringio.rb +59 -0
  135. data/pkg/steam-condenser-1.3.5/test/fixtures/invalid.xml +2 -0
  136. data/pkg/steam-condenser-1.3.5/test/fixtures/sonofthor.xml +882 -0
  137. data/pkg/steam-condenser-1.3.5/test/fixtures/status_goldsrc +3 -0
  138. data/pkg/steam-condenser-1.3.5/test/fixtures/status_source +3 -0
  139. data/pkg/steam-condenser-1.3.5/test/fixtures/valve-members.xml +231 -0
  140. data/pkg/steam-condenser-1.3.5/test/helper.rb +48 -0
  141. data/pkg/steam-condenser-1.3.5/test/steam/community/test_cacheable.rb +100 -0
  142. data/pkg/steam-condenser-1.3.5/test/steam/community/test_steam_group.rb +83 -0
  143. data/pkg/steam-condenser-1.3.5/test/steam/community/test_steam_id.rb +144 -0
  144. data/pkg/steam-condenser-1.3.5/test/steam/community/test_web_api.rb +98 -0
  145. data/pkg/steam-condenser-1.3.5/test/steam/packets/test_steam_packet.rb +37 -0
  146. data/pkg/steam-condenser-1.3.5/test/steam/servers/test_game_server.rb +296 -0
  147. data/pkg/steam-condenser-1.3.5/test/steam/servers/test_goldsrc_server.rb +59 -0
  148. data/pkg/steam-condenser-1.3.5/test/steam/servers/test_master_server.rb +131 -0
  149. data/pkg/steam-condenser-1.3.5/test/steam/servers/test_server.rb +72 -0
  150. data/pkg/steam-condenser-1.3.5/test/steam/servers/test_source_server.rb +134 -0
  151. data/pkg/steam-condenser-1.3.5/test/steam/sockets/test_goldsrc_socket.rb +127 -0
  152. data/pkg/steam-condenser-1.3.5/test/steam/sockets/test_master_server_socket.rb +42 -0
  153. data/pkg/steam-condenser-1.3.5/test/steam/sockets/test_rcon_socket.rb +118 -0
  154. data/pkg/steam-condenser-1.3.5/test/steam/sockets/test_source_socket.rb +77 -0
  155. data/pkg/steam-condenser-1.3.5/test/steam/sockets/test_steam_socket.rb +97 -0
  156. data/steam-condenser.gemspec +2 -3
  157. data/test/steam/community/test_cacheable.rb +3 -0
  158. data/test/steam/community/test_web_api.rb +15 -2
  159. data/test/steam/packets/test_steam_packet.rb +1 -1
  160. data/test/steam/sockets/test_source_socket.rb +1 -1
  161. metadata +151 -27
@@ -0,0 +1,186 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2010-2011, Sebastian Staudt
5
+
6
+ require 'steam/community/alien_swarm/alien_swarm_mission'
7
+ require 'steam/community/alien_swarm/alien_swarm_weapon'
8
+
9
+ # This class represents the game statistics for a single user in Alien Swarm
10
+ #
11
+ # @author Sebastian Staudt
12
+ class AlienSwarmStats < GameStats
13
+
14
+ # Returns general stats for the players
15
+ #
16
+ # @return [Hash<Symbol, Object>] The stats for the player
17
+ attr_reader :lifetime_stats
18
+
19
+ # The base URL for all images referenced in the stats
20
+ BASE_URL = 'http://cdn.steamcommunity.com/public/images/gamestats/swarm/'
21
+
22
+ # The names of all weapons in Alien Swarm
23
+ WEAPONS = [ 'Autogun', 'Cannon_Sentry', 'Chainsaw', 'Flamer',
24
+ 'Grenade_Launcher', 'Hand_Grenades', 'Hornet_Barrage',
25
+ 'Incendiary_Sentry', 'Laser_Mines', 'Marskman_Rifle', 'Minigun',
26
+ 'Mining_Laser', 'PDW', 'Pistol', 'Prototype_Rifle', 'Rail_Rifle',
27
+ 'Rifle', 'Rifle_Grenade', 'Sentry_Gun', 'Shotgun',
28
+ 'Tesla_Cannon', 'Vindicator', 'Vindicator_Grenade' ]
29
+
30
+ # Creates a new `AlienSwarmStats` instance by calling the super constructor
31
+ # with the game name `'alienswarm'`
32
+ #
33
+ # @param [String, Fixnum] steam_id The custom URL or the 64bit Steam ID of
34
+ # the user
35
+ # @macro cacheable
36
+ def initialize(steam_id)
37
+ super steam_id, 'alienswarm'
38
+
39
+ if public?
40
+ lifetime_data = @xml_data['stats']['lifetime']
41
+
42
+ @hours_played = lifetime_data['timeplayed']
43
+
44
+ @lifetime_stats = {}
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
64
+
65
+ @lifetime_stats[:games_successful_percentage] = (@lifetime_stats[:total_games] > 0) ? @lifetime_stats[:games_successful].to_f / @lifetime_stats[:total_games] : 0;
66
+ end
67
+ end
68
+
69
+ # Returns the favorites of this user like weapons and marine
70
+ #
71
+ # If the favorites haven't been parsed already, parsing is done now.
72
+ #
73
+ # @return [Hash<Symbol, Object>] The favorites of this player
74
+ def favorites
75
+ return unless public?
76
+
77
+ if @favorites.nil?
78
+ favorites_data = @xml_data['stats']['favorites']
79
+
80
+ @favorites = {}
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
101
+ end
102
+
103
+ @favorites
104
+ end
105
+
106
+ # Returns the item stats for this user like ammo deployed and medkits
107
+ # used
108
+ #
109
+ # If the items haven't been parsed already, parsing is done now.
110
+ #
111
+ # @return [Hash<Symbol, Object>] The item stats of this player
112
+ def item_stats
113
+ return unless public?
114
+
115
+ if @item_stats.nil?
116
+ weapons_data = @xml_data['stats']['weapons']
117
+
118
+ @item_stats = {}
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
140
+ end
141
+
142
+ @item_stats
143
+ end
144
+
145
+ # Returns the stats for individual missions for this user containing all
146
+ # Alien Swarm missions
147
+ #
148
+ # If the mission stats haven't been parsed already, parsing is done now.
149
+ #
150
+ # @return [Hash<String, AlienSwarmMission>] The mission stats for this player
151
+ def mission_stats
152
+ return unless public?
153
+
154
+ if @mission_stats.nil?
155
+ @mission_stats = {}
156
+ @xml_data['stats']['missions'].each do |mission_data|
157
+ mission = AlienSwarmMission.new *mission_data
158
+ @mission_stats[mission.name] = mission
159
+ end
160
+ end
161
+
162
+ @mission_stats
163
+ end
164
+
165
+ # Returns the stats for individual weapons for this user containing all
166
+ # Alien Swarm weapons
167
+ #
168
+ # If the weapon stats haven't been parsed already, parsing is done now.
169
+ #
170
+ # @return [Hash<String, AlienSwarmWeapon>] The weapon stats for this player
171
+ def weapon_stats
172
+ return unless public?
173
+
174
+ if @weapon_stats.nil?
175
+ @weapon_stats = {}
176
+ WEAPONS.each do |weapon_node|
177
+ weapon_data = @xml_data['stats']['weapons'][weapon_node]
178
+ weapon = AlienSwarmWeapon.new(weapon_data)
179
+ @weapon_stats[weapon.name] = weapon
180
+ end
181
+ end
182
+
183
+ @weapon_stats
184
+ end
185
+
186
+ end
@@ -0,0 +1,49 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2010-2011, Sebastian Staudt
5
+
6
+ require 'steam/community/game_weapon'
7
+
8
+ # This class holds statistical information about weapons used by a player
9
+ # in Alien Swarm
10
+ #
11
+ # @author Sebastian Staudt
12
+ class AlienSwarmWeapon
13
+
14
+ include GameWeapon
15
+
16
+ # Returns the accuracy of the player with this weapon
17
+ #
18
+ # @return [Float] The accuracy of the player with this weapon
19
+ attr_reader :accuracy
20
+
21
+ # Returns the damage achieved with this weapon
22
+ #
23
+ # @return [Fixnum] The damage achieved with this weapon
24
+ attr_reader :damage
25
+
26
+ # Returns the damage dealt to team mates with this weapon
27
+ #
28
+ # @return [Fixnum] The damage dealt to team mates with this weapon
29
+ attr_reader :friendly_fire
30
+
31
+ # Returns the name of this weapon
32
+ #
33
+ # @return [String] The name of this weapon
34
+ attr_reader :name
35
+
36
+ # Creates a new weapon instance based on the assigned weapon XML data
37
+ #
38
+ # @param [Hash<String, Object>] weapon_data The data representing this weapon
39
+ def initialize(weapon_data)
40
+ super
41
+
42
+ @accuracy = weapon_data['accuracy'].to_f
43
+ @damage = weapon_data['damage'].to_i
44
+ @friendly_fire = weapon_data['friendlyfire'].to_i
45
+ @name = weapon_data['name']
46
+ @shots = weapon_data['shotsfired'].to_i
47
+ end
48
+
49
+ end
@@ -0,0 +1,133 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2010-2011, Sebastian Staudt
5
+
6
+ require 'multi_json'
7
+
8
+ require 'steam/community/web_api'
9
+
10
+ # This class represents Steam news and can be used to load a list of current
11
+ # news about specific games
12
+ #
13
+ # @author Sebastian Staudt
14
+ class AppNews
15
+
16
+ # Returns the Steam Application ID of the game this news belongs to
17
+ #
18
+ # @return [Fixnum] The application ID of the game this news belongs to
19
+ attr_reader :app_id
20
+
21
+ # Returns the name of the author of this news
22
+ #
23
+ # @return [String] The author of this news
24
+ attr_reader :author
25
+
26
+ # Returns the contents of this news
27
+ #
28
+ # This might contain HTML code.
29
+ #
30
+ # @note Depending on the setting for the maximum length of a news (see
31
+ # {.news_for_app}), the contents might be truncated.
32
+ # @return [String] The contents of this news
33
+ attr_reader :contents
34
+
35
+ # Returns the date this news item has been published
36
+ #
37
+ # @return [Time] The date this news has been published
38
+ attr_reader :date
39
+
40
+ # Returns the name of the feed this news item belongs to
41
+ #
42
+ # @return [String] The name of the feed this news belongs to
43
+ attr_reader :feed_label
44
+
45
+ # Returns the symbolic name of the feed this news item belongs to
46
+ #
47
+ # @return [String] The symbolic name of the feed this news belongs to
48
+ attr_reader :feed_name
49
+
50
+ # Returns a unique identifier for this news
51
+ #
52
+ # @return [Fixnum] A unique identifier for this news
53
+ attr_reader :gid
54
+
55
+ # Returns the title of this news
56
+ #
57
+ # @return [String] The title of this news
58
+ attr_reader :title
59
+
60
+ # Returns the URL of the original news
61
+ #
62
+ # This is a direct link to the news on the Steam website or a redirecting
63
+ # link to the external post.
64
+ #
65
+ # @return [String] The URL of the original news
66
+ attr_reader :url
67
+
68
+ # Loads the news for the given game with the given restrictions
69
+ #
70
+ # @param [Fixnum] app_id The unique Steam Application ID of the game (e.g.
71
+ # `440` for Team Fortress 2). See
72
+ # http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
73
+ # all application IDs.
74
+ # @param [Fixnum] count The maximum number of news to load. There's no
75
+ # reliable way to load all news. Use a really great number instead.
76
+ # @param [Fixnum] max_length The maximum content length of the news. If a
77
+ # maximum length is defined, the content of the news will only be at
78
+ # most `max_length` characters long plus an ellipsis.
79
+ # @return [Array<AppNews>] An array of news items for the specified game with
80
+ # the given options
81
+ def self.news_for_app(app_id, count = 5, max_length = nil)
82
+ params = { :appid => app_id, :count => count, :maxlength => max_length }
83
+ data = WebApi.json('ISteamNews', 'GetNewsForApp', 2, params)
84
+
85
+ news_items = []
86
+ MultiJson.load(data, { :symbolize_keys => true })[:appnews][:newsitems].each do |news_data|
87
+ news_items << AppNews.new(app_id, news_data)
88
+ end
89
+
90
+ news_items
91
+ end
92
+
93
+ # Returns whether this news item originates from a source other than Steam
94
+ # itself (e.g. an external blog)
95
+ #
96
+ # @return [Boolean] `true` if this news item is from an external source
97
+ def external?
98
+ @external
99
+ end
100
+
101
+ # Returns a simple textual representation of this news item
102
+ #
103
+ # Will consist of the name of the feed this news belongs to and the title of
104
+ # the news.
105
+ #
106
+ # @return [String] A simple text representing this news
107
+ def to_s
108
+ "#@feed_label: #@title"
109
+ end
110
+
111
+ private
112
+
113
+ # Creates a new instance of an AppNews news item with the given data
114
+ #
115
+ # @param [Fixnum] app_id The unique Steam Application ID of the game (e.g.
116
+ # `440` for Team Fortress 2). See
117
+ # http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
118
+ # all application IDs.
119
+ # @param [Hash<Symbol, Object>] news_data The news data extracted from JSON
120
+ def initialize(app_id, news_data)
121
+ @app_id = app_id
122
+ @author = news_data[:author]
123
+ @contents = news_data[:contents].strip
124
+ @data = Time.at(news_data[:date])
125
+ @external = news_data[:is_external_url]
126
+ @feed_label = news_data[:feedlabel]
127
+ @feed_name = news_data[:feedname]
128
+ @gid = news_data[:gid]
129
+ @title = news_data[:title]
130
+ @url = news_data[:url]
131
+ end
132
+
133
+ end
@@ -0,0 +1,199 @@
1
+ # This code is free software; you can redistribute it and/or modify it under
2
+ # the terms of the new BSD License.
3
+ #
4
+ # Copyright (c) 2009-2012, Sebastian Staudt
5
+
6
+ # @macro [new] cacheable
7
+ # @overload $0(${1--1}, fetch = true, bypass_cache = false)
8
+ # @param [Boolean] fetch if `true` the object's data is fetched after
9
+ # creation
10
+ # @param [Boolean] bypass_cache if `true` the object's data is fetched again
11
+ # even if it has been cached already
12
+
13
+ # This module implements caching functionality to be used in any object class
14
+ # having one or more unique object identifier (i.e. ID) and using a `fetch`
15
+ # method to fetch data, e.g. using a HTTP download.
16
+ #
17
+ # @author Sebastian Staudt
18
+ module Cacheable
19
+
20
+ # When this module is included in another class it is initialized to make use
21
+ # of caching
22
+ #
23
+ # The original `initialize` method of the including class will be wrapped,
24
+ # relaying all instantiations to the `new` method defined in {ClassMethods}.
25
+ # Additionally the class variable to save the attributes to cache (i.e. cache
26
+ # IDs) and the cache class variable itself are initialized.
27
+ #
28
+ # @param [Class] base The class to extend with caching functionality
29
+ # @see ClassMethods
30
+ def self.included(base)
31
+ base.extend ClassMethods
32
+ base.send :class_variable_set, :@@cache, {}
33
+ base.send :class_variable_set, :@@cache_ids, []
34
+
35
+ class << base
36
+ def method_added(name)
37
+ if name == :fetch && !(@@in_method_added ||= false)
38
+ @@in_method_added = true
39
+ alias_method :original_fetch, :fetch
40
+
41
+ define_method :fetch do
42
+ original_fetch
43
+ @fetch_time = Time.now
44
+ end
45
+ @@in_method_added = false
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ # This module implements functionality to access the cache of a class that
52
+ # includes the {Cacheable} module as class methods
53
+ #
54
+ # @author Sebastian Staudt
55
+ module ClassMethods
56
+
57
+ # Defines wich instance variables which should be used to index the cached
58
+ # objects
59
+ #
60
+ # @note A call to this method is needed if you want a class including this
61
+ # module to really use the cache.
62
+ # @param [Array<Symbol, Array<Symbol>>] ids The symbolic names of the
63
+ # instance variables representing a unique identifier for this
64
+ # object class. Arrays of symbols are also allowed and are used as
65
+ # compound IDs.
66
+ def cacheable_with_ids(*ids)
67
+ class_variable_set :@@cache_ids, ids
68
+ end
69
+
70
+ # Returns whether an object with the given ID is already cached
71
+ #
72
+ # @param [Object] id The ID of the desired object
73
+ # @return [Boolean] `true` if the object with the given ID is already
74
+ # cached
75
+ def cached?(id)
76
+ id.downcase! if id.is_a? String
77
+ cache.key?(id)
78
+ end
79
+
80
+ # Clears the object cache for the class this method is called on
81
+ def clear_cache
82
+ class_variable_set :@@cache, {}
83
+ end
84
+
85
+ # This checks the cache for an existing object. If it exists it is
86
+ # returned, otherwise a new object is created.
87
+ # Overrides the default `new` method of the cacheable object class.
88
+ #
89
+ # @param [Array<Object>] args The parameters of the object that should be
90
+ # created and if possible loaded from cache
91
+ # @see #cached?
92
+ # @see #fetch
93
+ def new(*args)
94
+ arity = self.instance_method(:initialize).arity.abs
95
+ args += [nil] * (arity - args.size) if args.size < arity
96
+ bypass_cache = args.size > arity + 1 ? !!args.pop : false
97
+ fetch = args.size > arity ? !!args.pop : true
98
+
99
+ object = self.allocate
100
+ object.send :initialize, *args
101
+ cached_object = object.send :cached_instance
102
+ object = cached_object unless cached_object.nil? || bypass_cache
103
+
104
+ if fetch && (bypass_cache || !object.fetched?)
105
+ object.fetch
106
+ object.cache
107
+ end
108
+
109
+ object
110
+ end
111
+
112
+ private
113
+
114
+ # Returns the current cache for the cacheable class
115
+ #
116
+ # @return [Hash<Object, Cacheable>] The cache for cacheable class
117
+ def cache
118
+ class_variable_get :@@cache
119
+ end
120
+
121
+ # Returns the list of IDs used for caching objects
122
+ #
123
+ # @return [Array<Symbol, Array<Symbol>>] The IDs used for caching objects
124
+ def cache_ids
125
+ class_variable_get :@@cache_ids
126
+ end
127
+
128
+ end
129
+
130
+ # Returns the time the object's data has been fetched the last time
131
+ #
132
+ # @return [Time] The time the object has been updated the last time
133
+ attr_reader :fetch_time
134
+
135
+ # Saves this object in the cache
136
+ #
137
+ # This will use the ID attributes selected for caching
138
+ def cache
139
+ cache = self.class.send :cache
140
+ cache_ids.each do |cache_id|
141
+ cache[cache_id] = self if cache_id
142
+ end
143
+
144
+ true
145
+ end
146
+
147
+ # Fetches the object from some data source
148
+ #
149
+ # @note This method should be overridden in cacheable object classes and
150
+ # should implement the logic to retrieve the object's data. Updating
151
+ # the time is handled dynamically and does not need to be implemented
152
+ # separately.
153
+ def fetch
154
+ end
155
+
156
+ # Returns whether the data for this object has already been fetched
157
+ #
158
+ # @return [Boolean] `true` if this object's data is available
159
+ def fetched?
160
+ !@fetch_time.nil?
161
+ end
162
+
163
+ private
164
+
165
+ # If available, returns the cached instance for the object it is called on
166
+ #
167
+ # This may be used to either replace an initial object with a completely
168
+ # cached instance of the same ID or to compare a modified object with the
169
+ # copy that was cached before.
170
+ #
171
+ # @see #cache_ids
172
+ def cached_instance
173
+ ids = cache_ids
174
+ cached = self.class.send(:cache).find { |id, object| ids.include? id}
175
+ cached.nil? ? nil : cached.last
176
+ end
177
+
178
+ # Returns a complete list of all values for the cache IDs of the cachable
179
+ # object
180
+ #
181
+ # @return [Array<Object, Array<Object>>] The values for the cache IDs
182
+ # @see #cache_id_value
183
+ def cache_ids
184
+ values = lambda do |id|
185
+ id.is_a?(Array) ? id.map(&values) : cache_id_value(id)
186
+ end
187
+
188
+ self.class.send(:cache_ids).map &values
189
+ end
190
+
191
+ # Returns the value for the ID
192
+ #
193
+ # @param [Symbol] id The name of an instance variable
194
+ # @return [Object] The value of the given instance variable
195
+ def cache_id_value(id)
196
+ instance_variable_get "@#{id}".to_sym
197
+ end
198
+
199
+ end