steam-condenser 0.14.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/Gemfile.lock +22 -0
- data/LICENSE +1 -1
- data/README.md +14 -6
- data/Rakefile +35 -0
- data/lib/{stringio_additions.rb → core_ext/stringio.rb} +1 -1
- data/lib/{exceptions/packet_format_exception.rb → errors/packet_format_error.rb} +5 -5
- data/lib/{exceptions/rcon_ban_exception.rb → errors/rcon_ban_error.rb} +5 -5
- data/lib/{exceptions/rcon_no_auth_exception.rb → errors/rcon_no_auth_error.rb} +5 -5
- data/lib/{exceptions/steam_condenser_exception.rb → errors/steam_condenser_error.rb} +3 -3
- data/lib/errors/timeout_error.rb +28 -0
- data/lib/{exceptions/web_api_exception.rb → errors/web_api_error.rb} +8 -8
- data/lib/steam/community/alien_swarm/alien_swarm_mission.rb +86 -11
- data/lib/steam/community/alien_swarm/alien_swarm_stats.rb +38 -15
- data/lib/steam/community/alien_swarm/alien_swarm_weapon.rb +29 -8
- data/lib/steam/community/app_news.rb +91 -27
- data/lib/steam/community/cacheable.rb +65 -21
- data/lib/steam/community/css/css_map.rb +39 -9
- data/lib/steam/community/css/css_stats.rb +32 -12
- data/lib/steam/community/css/css_weapon.rb +46 -10
- data/lib/steam/community/defense_grid/defense_grid_stats.rb +129 -17
- data/lib/steam/community/dods/dods_class.rb +66 -10
- data/lib/steam/community/dods/dods_stats.rb +20 -7
- data/lib/steam/community/dods/dods_weapon.rb +35 -24
- data/lib/steam/community/game_achievement.rb +50 -19
- data/lib/steam/community/game_class.rb +16 -5
- data/lib/steam/community/game_inventory.rb +37 -4
- data/lib/steam/community/game_item.rb +64 -3
- data/lib/steam/community/game_stats.rb +81 -16
- data/lib/steam/community/game_weapon.rb +29 -11
- data/lib/steam/community/l4d/abstract_l4d_stats.rb +91 -65
- data/lib/steam/community/l4d/abstract_l4d_weapon.rb +38 -8
- data/lib/steam/community/l4d/l4d2_map.rb +30 -5
- data/lib/steam/community/l4d/l4d2_stats.rb +83 -45
- data/lib/steam/community/l4d/l4d2_weapon.rb +20 -6
- data/lib/steam/community/l4d/l4d_explosive.rb +13 -5
- data/lib/steam/community/l4d/l4d_map.rb +35 -7
- data/lib/steam/community/l4d/l4d_stats.rb +23 -10
- data/lib/steam/community/l4d/l4d_weapon.rb +11 -7
- data/lib/steam/community/portal2/portal2_inventory.rb +4 -0
- data/lib/steam/community/portal2/portal2_item.rb +13 -1
- data/lib/steam/community/portal2/portal2_stats.rb +10 -6
- data/lib/steam/community/steam_game.rb +74 -0
- data/lib/steam/community/steam_group.rb +48 -14
- data/lib/steam/community/steam_id.rb +295 -64
- data/lib/steam/community/tf2/tf2_class.rb +66 -7
- data/lib/steam/community/tf2/tf2_class_factory.rb +14 -7
- data/lib/steam/community/tf2/tf2_engineer.rb +26 -6
- data/lib/steam/community/tf2/tf2_golden_wrench.rb +37 -10
- data/lib/steam/community/tf2/tf2_inventory.rb +4 -0
- data/lib/steam/community/tf2/tf2_item.rb +13 -1
- data/lib/steam/community/tf2/tf2_medic.rb +20 -5
- data/lib/steam/community/tf2/tf2_sniper.rb +15 -5
- data/lib/steam/community/tf2/tf2_spy.rb +20 -6
- data/lib/steam/community/tf2/tf2_stats.rb +20 -6
- data/lib/steam/community/web_api.rb +50 -32
- data/lib/steam/packets/c2m_checkmd5_packet.rb +1 -1
- data/lib/steam/packets/m2a_server_batch_packet.rb +3 -2
- data/lib/steam/packets/m2s_requestrestart_packet.rb +3 -3
- data/lib/steam/packets/rcon/rcon_packet_factory.rb +4 -4
- data/lib/steam/packets/request_with_challenge.rb +1 -1
- data/lib/steam/packets/s2a_info_base_packet.rb +1 -1
- data/lib/steam/packets/s2a_info_detailed_packet.rb +10 -10
- data/lib/steam/packets/s2a_player_packet.rb +5 -1
- data/lib/steam/packets/s2a_rules_packet.rb +4 -3
- data/lib/steam/packets/s2m_heartbeat2_packet.rb +2 -2
- data/lib/steam/packets/steam_packet.rb +1 -1
- data/lib/steam/packets/steam_packet_factory.rb +12 -16
- data/lib/steam/servers/game_server.rb +38 -32
- data/lib/steam/servers/goldsrc_server.rb +10 -1
- data/lib/steam/servers/master_server.rb +42 -21
- data/lib/steam/servers/server.rb +4 -5
- data/lib/steam/servers/source_server.rb +20 -5
- data/lib/steam/sockets/goldsrc_socket.rb +53 -22
- data/lib/steam/sockets/master_server_socket.rb +14 -4
- data/lib/steam/sockets/rcon_socket.rb +39 -6
- data/lib/steam/sockets/source_socket.rb +19 -15
- data/lib/steam/sockets/steam_socket.rb +33 -23
- data/lib/steam/steam_player.rb +86 -11
- data/lib/steam-condenser/community.rb +24 -24
- data/lib/steam-condenser/servers.rb +2 -2
- data/lib/steam-condenser/version.rb +3 -3
- data/steam-condenser.gemspec +23 -0
- data/test/query_tests.rb +12 -12
- data/test/rcon_tests.rb +3 -3
- data/test/steam/communtiy/steam_community_test_suite.rb +12 -0
- data/test/steam/communtiy/steam_group_tests.rb +6 -5
- data/test/steam/communtiy/steam_id_tests.rb +6 -5
- data/test/steam_community_tests.rb +3 -3
- data/test/stringio_additions_tests.rb +7 -7
- metadata +61 -43
- data/lib/exceptions/timeout_exception.rb +0 -24
- data/test/datagram_channel_tests.rb +0 -42
- data/test/socket_channel_tests.rb +0 -43
@@ -1,22 +1,36 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009-
|
4
|
+
# Copyright (c) 2009-2011, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/l4d/abstract_l4d_weapon'
|
7
7
|
|
8
|
+
# This class represents the statistics of a single weapon for a user in
|
9
|
+
# Left4Dead 2
|
10
|
+
#
|
11
|
+
# @author Sebastian Staudt
|
8
12
|
class L4D2Weapon
|
9
13
|
|
10
14
|
include AbstractL4DWeapon
|
11
15
|
|
12
|
-
|
16
|
+
# Returns the amount of damage done by the player with this weapon
|
17
|
+
#
|
18
|
+
# @return [Fixnum] The damage done by this weapon
|
19
|
+
attr_reader :damage
|
20
|
+
|
21
|
+
# Returns the weapon group this weapon belongs to
|
22
|
+
#
|
23
|
+
# @return [String] The group this weapon belongs to
|
24
|
+
attr_reader :weapon_group
|
13
25
|
|
14
|
-
# Creates a new instance of
|
26
|
+
# Creates a new instance of a weapon based on the given XML data
|
27
|
+
#
|
28
|
+
# @param [REXML::Element] weapon_data The XML data of this weapon
|
15
29
|
def initialize(weapon_data)
|
16
30
|
super weapon_data
|
17
31
|
|
18
32
|
@damage = weapon_data.elements['damage'].text.to_i
|
19
|
-
@kill_percentage = weapon_data.elements['pctkills'].text
|
33
|
+
@kill_percentage = weapon_data.elements['pctkills'].text.to_f * 0.01
|
20
34
|
@weapon_group = weapon_data.attribute('group')
|
21
35
|
end
|
22
36
|
|
@@ -1,15 +1,21 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009-
|
4
|
+
# Copyright (c) 2009-2011, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/game_weapon'
|
7
7
|
|
8
|
+
# This class represents the statistics of a single explosive weapon for a user
|
9
|
+
# in Left4Dead
|
10
|
+
#
|
11
|
+
# @author Sebastian Staudt
|
8
12
|
class L4DExplosive
|
9
13
|
|
10
14
|
include GameWeapon
|
11
15
|
|
12
|
-
# Creates a new instance of
|
16
|
+
# Creates a new instance of an explosivve based on the given XML data
|
17
|
+
#
|
18
|
+
# @param [REXML::Element] weapon_data The XML data of this explosive
|
13
19
|
def initialize(weapon_data)
|
14
20
|
super weapon_data
|
15
21
|
|
@@ -17,7 +23,9 @@ class L4DExplosive
|
|
17
23
|
@shots = weapon_data.elements['thrown'].text.to_i
|
18
24
|
end
|
19
25
|
|
20
|
-
# Returns the average number of
|
26
|
+
# Returns the average number of killed zombies for one shot of this explosive
|
27
|
+
#
|
28
|
+
# @return [Float] The average number of kills per shot
|
21
29
|
def avg_kills_per_shot
|
22
30
|
1 / avg_shots_per_kill
|
23
31
|
end
|
@@ -1,20 +1,48 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009-
|
4
|
+
# Copyright (c) 2009-2011, Sebastian Staudt
|
5
5
|
|
6
|
-
#
|
7
|
-
# Survival mode of Left4Dead
|
6
|
+
# This class holds statistical information about a map played by a player in
|
7
|
+
# Survival mode of Left4Dead
|
8
|
+
#
|
9
|
+
# @author Sebastian Staudt
|
8
10
|
class L4DMap
|
9
11
|
|
10
|
-
|
12
|
+
# Returns the best survival time of this player on this map
|
13
|
+
#
|
14
|
+
# @return [Float] The best survival time of this player on this map
|
15
|
+
attr_reader :best_time
|
16
|
+
|
17
|
+
# Returns the ID of this map
|
18
|
+
#
|
19
|
+
# @return [String] The ID of this map
|
20
|
+
attr_reader :id
|
21
|
+
|
22
|
+
# Returns the highest medal this player has won on this map
|
23
|
+
#
|
24
|
+
# @return [Fixnum] The highest medal won by this player on this map
|
25
|
+
attr_reader :medal
|
26
|
+
|
27
|
+
# Returns the name of the map
|
28
|
+
#
|
29
|
+
# @return [String] The name of the map
|
30
|
+
attr_reader :name
|
31
|
+
|
32
|
+
# Returns the number of times this map has been played by this player
|
33
|
+
#
|
34
|
+
# @return [Fixnum] The number of times this map has been played
|
35
|
+
attr_reader :times_played
|
11
36
|
|
12
37
|
GOLD = 1
|
13
38
|
SILVER = 2
|
14
39
|
BRONZE = 3
|
15
40
|
NONE = 0
|
16
41
|
|
17
|
-
# Creates a new instance of
|
42
|
+
# Creates a new instance of a Left4Dead Survival map based on the given
|
43
|
+
# XML data
|
44
|
+
#
|
45
|
+
# @param [REXML::Element] map_data The XML data for this map
|
18
46
|
def initialize(map_data)
|
19
47
|
@best_time = map_data.elements['besttimeseconds'].text.to_f
|
20
48
|
@id = map_data.name
|
@@ -1,41 +1,54 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009-
|
4
|
+
# Copyright (c) 2009-2011, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/l4d/abstract_l4d_stats'
|
7
7
|
require 'steam/community/l4d/l4d_explosive'
|
8
8
|
require 'steam/community/l4d/l4d_map'
|
9
9
|
require 'steam/community/l4d/l4d_weapon'
|
10
10
|
|
11
|
+
# This class represents the game statistics for a single user in Left4Dead
|
12
|
+
#
|
13
|
+
# @author Sebastian Staudt
|
11
14
|
class L4DStats < GameStats
|
12
15
|
|
13
16
|
include AbstractL4DStats
|
14
17
|
|
15
|
-
# Creates a L4DStats object by calling the super constructor
|
16
|
-
# name
|
18
|
+
# Creates a `L4DStats` object by calling the super constructor
|
19
|
+
# with the game name `'l4d'`
|
20
|
+
#
|
21
|
+
# @param [String] steam_id The custom URL or 64bit Steam ID of the user
|
17
22
|
def initialize(steam_id)
|
18
23
|
super steam_id, 'l4d'
|
19
24
|
end
|
20
25
|
|
21
|
-
# Returns a
|
22
|
-
#
|
26
|
+
# Returns a hash of Survival statistics for this user like revived teammates
|
27
|
+
#
|
28
|
+
# If the Survival statistics haven't been parsed already, parsing is done
|
29
|
+
# now.
|
30
|
+
#
|
31
|
+
# @return [Hash<String, Object>] The stats for the Survival mode
|
23
32
|
def survival_stats
|
24
33
|
return unless public?
|
25
34
|
|
26
35
|
if @survival_stats.nil?
|
27
36
|
super
|
28
|
-
@survival_stats[
|
37
|
+
@survival_stats[:maps] = {}
|
29
38
|
@xml_data.elements.each('stats/survival/maps/*') do |map_data|
|
30
|
-
@survival_stats[
|
39
|
+
@survival_stats[:maps][map_data.name] = L4DMap.new(map_data)
|
31
40
|
end
|
32
41
|
end
|
33
42
|
|
34
43
|
@survival_stats
|
35
44
|
end
|
36
45
|
|
37
|
-
# Returns a
|
46
|
+
# Returns a hash of `L4DWeapon` for this user containing all Left4Dead
|
47
|
+
# weapons
|
48
|
+
#
|
38
49
|
# If the weapons haven't been parsed already, parsing is done now.
|
50
|
+
#
|
51
|
+
# @return [Hash<String, Object>] The weapon statistics
|
39
52
|
def weapon_stats
|
40
53
|
return unless public?
|
41
54
|
|
@@ -1,21 +1,25 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009-
|
4
|
+
# Copyright (c) 2009-2011, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/l4d/abstract_l4d_weapon'
|
7
7
|
|
8
|
+
# This class represents the statistics of a single weapon for a user in
|
9
|
+
# Left4Dead
|
10
|
+
#
|
11
|
+
# @author Sebastian Staudt
|
8
12
|
class L4DWeapon
|
9
13
|
|
10
14
|
include AbstractL4DWeapon
|
11
15
|
|
12
|
-
|
13
|
-
|
14
|
-
#
|
16
|
+
# Creates a new instance of a weapon based on the given XML data
|
17
|
+
#
|
18
|
+
# @param [REXML::Element] weapon_data The XML data for this weapon
|
15
19
|
def initialize(weapon_data)
|
16
20
|
super weapon_data
|
17
21
|
|
18
|
-
@kill_percentage = weapon_data.elements['killpct'].text
|
22
|
+
@kill_percentage = weapon_data.elements['killpct'].text.to_f * 0.01
|
19
23
|
end
|
20
24
|
|
21
25
|
end
|
@@ -7,6 +7,8 @@ require 'steam/community/game_inventory'
|
|
7
7
|
require 'steam/community/portal2/portal2_item'
|
8
8
|
|
9
9
|
# Represents the inventory (a.k.a. Robot Enrichment) of a Portal 2 player
|
10
|
+
#
|
11
|
+
# @author Sebastian Staudt
|
10
12
|
class Portal2Inventory
|
11
13
|
|
12
14
|
include Cacheable
|
@@ -14,8 +16,10 @@ class Portal2Inventory
|
|
14
16
|
|
15
17
|
include GameInventory
|
16
18
|
|
19
|
+
# The Steam Application ID of Portal 2
|
17
20
|
@@app_id = 620
|
18
21
|
|
22
|
+
# The class representing Portal 2 items
|
19
23
|
@@item_class = Portal2Item
|
20
24
|
|
21
25
|
end
|
@@ -6,13 +6,20 @@
|
|
6
6
|
require 'steam/community/game_item'
|
7
7
|
|
8
8
|
# Represents a Portal 2 item
|
9
|
+
#
|
10
|
+
# @author Sebastian Staudt
|
9
11
|
class Portal2Item
|
10
12
|
|
11
13
|
include GameItem
|
12
14
|
|
15
|
+
# The names of the bots available in Portal 2
|
13
16
|
BOTS = [ :pbody, :atlas ]
|
14
17
|
|
15
|
-
# Creates a new instance of a
|
18
|
+
# Creates a new instance of a Portal 2 item with the given data
|
19
|
+
#
|
20
|
+
# @param [Portal2Inventory] inventory The inventory this item is contained in
|
21
|
+
# @param [Hash<Symbol, Object>] item_data The data specifying this item
|
22
|
+
# @raise [WebApiError] on Web API errors
|
16
23
|
def initialize(inventory, item_data)
|
17
24
|
super
|
18
25
|
|
@@ -23,11 +30,16 @@ class Portal2Item
|
|
23
30
|
end
|
24
31
|
|
25
32
|
# Returns the symbols for each bot this player has equipped this item
|
33
|
+
#
|
34
|
+
# @return [Array<String>] The names of the bots this player has equipped this
|
35
|
+
# item
|
26
36
|
def bots_equipped?
|
27
37
|
@equipped.reject { |bot_id, equipped| !equipped }
|
28
38
|
end
|
29
39
|
|
30
40
|
# Returns whether this item is equipped by this player at all
|
41
|
+
#
|
42
|
+
# @return [Boolean] `true` if the player has equipped this item at all
|
31
43
|
def equipped?
|
32
44
|
@equipped.has_value? true
|
33
45
|
end
|
@@ -6,20 +6,24 @@
|
|
6
6
|
require 'steam/community/game_stats'
|
7
7
|
require 'steam/community/portal2/portal2_inventory'
|
8
8
|
|
9
|
-
#
|
10
|
-
#
|
9
|
+
# This class represents the game statistics for a single user in Portal 2
|
10
|
+
#
|
11
|
+
# @author Sebastian Staudt
|
11
12
|
class Portal2Stats < GameStats
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
#
|
16
|
-
#
|
14
|
+
# Creates a `Portal2Stats` object by calling the super constructor with the
|
15
|
+
# game name `'portal2'`
|
16
|
+
#
|
17
|
+
# @param [String, Fixnum] steam_id The custom URL or 64bit Steam ID of the
|
18
|
+
# user
|
17
19
|
def initialize(steam_id)
|
18
20
|
super steam_id, 'portal2'
|
19
21
|
end
|
20
22
|
|
21
23
|
# Returns the current Portal 2 inventory (a.k.a Robot Enrichment) of this
|
22
24
|
# player
|
25
|
+
#
|
26
|
+
# @return [TF2Inventory] This player's Portal 2 inventory
|
23
27
|
def inventory
|
24
28
|
@inventory = Portal2Inventory.new(steam_id64) if @inventory.nil?
|
25
29
|
@inventory
|
@@ -0,0 +1,74 @@
|
|
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) 2011, Sebastian Staudt
|
5
|
+
|
6
|
+
# This class represents a game available on Steam
|
7
|
+
#
|
8
|
+
# @author Sebastian Staudt
|
9
|
+
class SteamGame
|
10
|
+
|
11
|
+
@@games = {}
|
12
|
+
|
13
|
+
# Returns the Steam application ID of this game
|
14
|
+
#
|
15
|
+
# @return [Fixnum] The Steam application ID of this game
|
16
|
+
attr_reader :app_id
|
17
|
+
|
18
|
+
# Returns the full name of this game
|
19
|
+
#
|
20
|
+
# @return [String] The full name of this game
|
21
|
+
attr_reader :name
|
22
|
+
|
23
|
+
# Returns the short name of this game (also known as "friendly name")
|
24
|
+
#
|
25
|
+
# @return [String] The short name of this game
|
26
|
+
attr_reader :short_name
|
27
|
+
|
28
|
+
# Creates a new or cached instance of the game specified by the given XML
|
29
|
+
# data
|
30
|
+
#
|
31
|
+
# @param [REXML::Element] game_data The XML data of the game
|
32
|
+
# @see #initialize
|
33
|
+
def self.new(game_data)
|
34
|
+
app_id = game_data.elements['appID'].text.to_i
|
35
|
+
@@games.key?(app_id) ? @@games[app_id] : super(app_id, game_data)
|
36
|
+
end
|
37
|
+
|
38
|
+
# Returns whether this game has statistics available
|
39
|
+
#
|
40
|
+
# @return [Boolean] `true` if this game has stats
|
41
|
+
def has_stats?
|
42
|
+
!@short_name.nil?
|
43
|
+
end
|
44
|
+
|
45
|
+
# Creates a stats object for the given user and this game
|
46
|
+
#
|
47
|
+
# @param [String, Fixnum] steam_id The custom URL or the 64bit Steam ID of
|
48
|
+
# the user
|
49
|
+
# @return [GameStats] The stats of this game for the given user
|
50
|
+
def user_stats(steam_id)
|
51
|
+
return unless has_stats?
|
52
|
+
|
53
|
+
GameStats.create_game_stats steam_id, @short_name
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
# Creates a new instance of a game with the given data and caches it
|
59
|
+
#
|
60
|
+
# @param [Fixnum] app_id The application ID of the game
|
61
|
+
# @param [REXML::Element] game_data The XML data of the game
|
62
|
+
def initialize(app_id, game_data)
|
63
|
+
@app_id = app_id
|
64
|
+
@name = game_data.elements['name'].text
|
65
|
+
if game_data.elements['globalStatsLink'].nil?
|
66
|
+
@short_name = nil
|
67
|
+
else
|
68
|
+
@short_name = game_data.elements['globalStatsLink'].text.match(/http:\/\/steamcommunity.com\/stats\/([^?\/]+)\/achievements\//)[1].downcase
|
69
|
+
end
|
70
|
+
|
71
|
+
@@games[@app_id] = self
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
# This code is free software; you can redistribute it and/or modify it under
|
2
|
-
# terms of the new BSD License.
|
1
|
+
# This code is free software; you can redistribute it and/or modify it under
|
2
|
+
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2008-
|
4
|
+
# Copyright (c) 2008-2011, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'open-uri'
|
7
7
|
require 'rexml/document'
|
@@ -10,14 +10,32 @@ require 'steam/community/cacheable'
|
|
10
10
|
require 'steam/community/steam_id'
|
11
11
|
|
12
12
|
# The SteamGroup class represents a group in the Steam Community
|
13
|
+
#
|
14
|
+
# @author Sebastian Staudt
|
13
15
|
class SteamGroup
|
14
16
|
|
15
17
|
include Cacheable
|
16
18
|
cacheable_with_ids :custom_url, :group_id64
|
17
19
|
|
18
|
-
|
19
|
-
|
20
|
-
#
|
20
|
+
# Returns the custom URL of this group
|
21
|
+
#
|
22
|
+
# The custom URL is a admin specified unique string that can be used instead
|
23
|
+
# of the 64bit SteamID as an identifier for a group.
|
24
|
+
#
|
25
|
+
# @return [String] The custom URL of this group
|
26
|
+
attr_reader :custom_url
|
27
|
+
|
28
|
+
# Returns this group's 64bit SteamID
|
29
|
+
#
|
30
|
+
# @return [Fixnum] This group's 64bit SteamID
|
31
|
+
attr_reader :group_id64
|
32
|
+
|
33
|
+
# Creates a new `SteamGroup` instance for the group with the given ID
|
34
|
+
#
|
35
|
+
# @param [String, Fixnum] id The custom URL of the group specified by the
|
36
|
+
# group admin or the 64bit group ID
|
37
|
+
# @param [Boolean] fetch if `true` the groups's data is loaded into the
|
38
|
+
# object
|
21
39
|
def initialize(id, fetch = true)
|
22
40
|
begin
|
23
41
|
if id.is_a? Numeric
|
@@ -28,11 +46,15 @@ class SteamGroup
|
|
28
46
|
|
29
47
|
super(fetch)
|
30
48
|
rescue REXML::ParseException
|
31
|
-
raise
|
49
|
+
raise SteamCondenserError, 'Group could not be loaded.'
|
32
50
|
end
|
33
51
|
end
|
34
52
|
|
35
|
-
# Returns the URL
|
53
|
+
# Returns the base URL for this group's page
|
54
|
+
#
|
55
|
+
# This URL is different for groups having a custom URL.
|
56
|
+
#
|
57
|
+
# @return [String] The base URL for this group
|
36
58
|
def base_url
|
37
59
|
if @custom_url.nil?
|
38
60
|
"http://steamcommunity.com/gid/#{@group_id64}"
|
@@ -41,7 +63,12 @@ class SteamGroup
|
|
41
63
|
end
|
42
64
|
end
|
43
65
|
|
44
|
-
#
|
66
|
+
# Loads the members of this group
|
67
|
+
#
|
68
|
+
# This might take several HTTP requests as the Steam Community splits this
|
69
|
+
# data over several XML documents if the group has lots of members.
|
70
|
+
#
|
71
|
+
# @see Cacheable#fetch
|
45
72
|
def fetch
|
46
73
|
@members = []
|
47
74
|
page = 0
|
@@ -62,10 +89,13 @@ class SteamGroup
|
|
62
89
|
super
|
63
90
|
end
|
64
91
|
|
65
|
-
# Returns the number of members this group has
|
66
|
-
#
|
67
|
-
# the
|
68
|
-
# fetched
|
92
|
+
# Returns the number of members this group has
|
93
|
+
#
|
94
|
+
# If the members have already been fetched the size of the member array is
|
95
|
+
# returned. Otherwise the group size is separately fetched without needing
|
96
|
+
# multiple requests for big groups.
|
97
|
+
#
|
98
|
+
# @return [Fixnum] The number of this group's members
|
69
99
|
def member_count
|
70
100
|
if @members.nil?
|
71
101
|
url = open("#{base_url}/memberslistxml", {:proxy => true})
|
@@ -76,7 +106,11 @@ class SteamGroup
|
|
76
106
|
end
|
77
107
|
|
78
108
|
# Returns the members of this group
|
79
|
-
#
|
109
|
+
#
|
110
|
+
# If the members haven't been fetched yet, this is done now.
|
111
|
+
#
|
112
|
+
# @return [Array<SteamId>] The Steam ID's of the members of this group
|
113
|
+
# @see #fetch
|
80
114
|
def members
|
81
115
|
fetch if @members.nil? || @members[0].nil?
|
82
116
|
@members
|