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,29 +1,57 @@
|
|
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
|
-
require '
|
6
|
+
require 'multi_json'
|
7
7
|
|
8
8
|
require 'steam/community/web_api'
|
9
9
|
|
10
10
|
# The GameAchievement class represents a specific achievement for a single game
|
11
11
|
# and for a single user
|
12
|
+
#
|
13
|
+
# It also provides the ability to load the global unlock percentages of all
|
14
|
+
# achievements of a specific game.
|
15
|
+
#
|
16
|
+
# @author Sebastian Staudt
|
12
17
|
class GameAchievement
|
13
18
|
|
14
|
-
|
19
|
+
# Return the unique Steam Application ID of the game this achievement
|
20
|
+
# belongs to
|
21
|
+
#
|
22
|
+
# @return [Fixnum] The Steam Application ID of this achievement's game
|
23
|
+
attr_reader :app_id
|
24
|
+
|
25
|
+
# Returns the name of this achievement
|
26
|
+
#
|
27
|
+
# @return [String] The name of this achievement
|
28
|
+
attr_reader :name
|
29
|
+
|
30
|
+
# Returns the 64bit SteamID of the user who owns this achievement
|
31
|
+
#
|
32
|
+
# @return [Fixnum] The 64bit SteamID of this achievement's owner
|
33
|
+
attr_reader :steam_id64
|
15
34
|
|
16
|
-
#
|
35
|
+
# Returns the time this achievement has been unlocked by its owner
|
17
36
|
#
|
18
|
-
# [
|
19
|
-
|
20
|
-
|
21
|
-
#
|
37
|
+
# @return [Time] The time this achievement has been unlocked
|
38
|
+
attr_reader :timestamp
|
39
|
+
|
40
|
+
# Loads the global unlock percentages of all achievements for the game with
|
41
|
+
# the given Steam Application ID
|
42
|
+
#
|
43
|
+
# @param [Fixnum] app_id The unique Steam Application ID of the game (e.g.
|
44
|
+
# `440` for Team Fortress 2). See
|
45
|
+
# http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
|
46
|
+
# all application IDs
|
47
|
+
# @raise [WebApiError] if the request to Steam's Web API fails
|
48
|
+
# @return [Hash<Symbol, Float>] The symbolic achievement names with their
|
49
|
+
# corresponding unlock percentages
|
22
50
|
def self.global_percentages(app_id)
|
23
51
|
percentages = {}
|
24
52
|
|
25
|
-
data = WebApi.json('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp',
|
26
|
-
|
53
|
+
data = WebApi.json('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp', 2, { :gameid => app_id })
|
54
|
+
MultiJson.decode(data, { :symbolize_keys => true })[:achievementpercentages][:achievements].each do |percentage|
|
27
55
|
percentages[percentage[:name].to_sym] = percentage[:percent]
|
28
56
|
end
|
29
57
|
|
@@ -33,13 +61,14 @@ class GameAchievement
|
|
33
61
|
# Creates the achievement with the given name for the given user and game
|
34
62
|
# and achievement data
|
35
63
|
#
|
36
|
-
# [
|
37
|
-
#
|
38
|
-
# [
|
39
|
-
#
|
40
|
-
#
|
41
|
-
#
|
42
|
-
# [
|
64
|
+
# @param [Fixnum] steam_id64 The 64bit SteamID of the player this achievement
|
65
|
+
# belongs to
|
66
|
+
# @param [Fixnum] app_id The unique Steam Application ID of the game (e.g.
|
67
|
+
# `440` for Team Fortress 2). See
|
68
|
+
# http://developer.valvesoftware.com/wiki/Steam_Application_IDs for
|
69
|
+
# all application IDs
|
70
|
+
# @param [REXML::Element] achievement_data The achievement data extracted
|
71
|
+
# from XML
|
43
72
|
def initialize(steam_id64, app_id, achievement_data)
|
44
73
|
@app_id = app_id
|
45
74
|
@name = achievement_data.elements['name'].text
|
@@ -52,6 +81,8 @@ class GameAchievement
|
|
52
81
|
end
|
53
82
|
|
54
83
|
# Returns whether this achievement has been unlocked by its owner
|
84
|
+
#
|
85
|
+
# @return [Boolean] `true` if the achievement has been unlocked by the user
|
55
86
|
def unlocked?
|
56
87
|
@unlocked
|
57
88
|
end
|
@@ -1,11 +1,22 @@
|
|
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
|
+
# A module implementing basic functionality for classes representing player
|
7
|
+
# classes
|
8
|
+
#
|
9
|
+
# @author Sebastian Staudt
|
7
10
|
module GameClass
|
8
11
|
|
9
|
-
|
12
|
+
# Returns the name of this class
|
13
|
+
#
|
14
|
+
# @return [String] The name of this class
|
15
|
+
attr_reader :name
|
16
|
+
|
17
|
+
# Returns the time in minutes the player has played with this class
|
18
|
+
#
|
19
|
+
# @return [Fixnum] The time this class has been played
|
20
|
+
attr_reader :play_time
|
10
21
|
|
11
22
|
end
|
@@ -8,9 +8,19 @@ require 'steam/community/game_item'
|
|
8
8
|
require 'steam/community/web_api'
|
9
9
|
|
10
10
|
# Provides basic functionality to represent an inventory of player in a game
|
11
|
+
#
|
12
|
+
# @author Sebastian Staudt
|
11
13
|
module GameInventory
|
12
14
|
|
13
|
-
|
15
|
+
# Returns an array of all items in this players inventory.
|
16
|
+
#
|
17
|
+
# @return [Array<GameItem>] All items in the backpack
|
18
|
+
attr_reader :items
|
19
|
+
|
20
|
+
# Returns the 64bit SteamID of the player owning this inventory
|
21
|
+
#
|
22
|
+
# @return [String] The 64bit SteamID
|
23
|
+
attr_reader :steam_id64
|
14
24
|
|
15
25
|
@@attribute_schema = {}
|
16
26
|
|
@@ -20,7 +30,9 @@ module GameInventory
|
|
20
30
|
|
21
31
|
@@schema_language = 'en'
|
22
32
|
|
23
|
-
# Sets the language the schema should be fetched in (default is:
|
33
|
+
# Sets the language the schema should be fetched in (default is: `'en'`)
|
34
|
+
#
|
35
|
+
# @param [String] The ISO 639-1 code of the schema language
|
24
36
|
def self.schema_language=(language)
|
25
37
|
@@schema_language = language
|
26
38
|
end
|
@@ -28,6 +40,10 @@ module GameInventory
|
|
28
40
|
# Creates a new inventory object for the given AppID and SteamID64. This
|
29
41
|
# calls update to fetch the data and create the item instances contained in
|
30
42
|
# this players backpack
|
43
|
+
#
|
44
|
+
# @param [Fixnum] steam_id64 The 64bit SteamID of the player to get the
|
45
|
+
# inventory for
|
46
|
+
# @param [Boolean] fetch_now if `true` the data will be fetched immediately
|
31
47
|
def initialize(steam_id64, fetch_now = true)
|
32
48
|
@steam_id64 = steam_id64
|
33
49
|
|
@@ -36,11 +52,15 @@ module GameInventory
|
|
36
52
|
|
37
53
|
# Returns the item at the given position in the inventory. The positions
|
38
54
|
# range from 1 to 100 instead of the usual array indices (0 to 99).
|
55
|
+
#
|
56
|
+
# @return [GameItem] The item at the given position in the inventory
|
39
57
|
def [](index)
|
40
58
|
@items[index - 1]
|
41
59
|
end
|
42
60
|
|
43
|
-
# Returns the
|
61
|
+
# Returns the application ID of the game this inventory class belongs to
|
62
|
+
#
|
63
|
+
# @return [Fixnum] The application ID of the game
|
44
64
|
def app_id
|
45
65
|
self.class.send :class_variable_get, :@@app_id
|
46
66
|
end
|
@@ -48,6 +68,10 @@ module GameInventory
|
|
48
68
|
# Returns the attribute schema
|
49
69
|
#
|
50
70
|
# The schemas are fetched first if not done already
|
71
|
+
#
|
72
|
+
# @return [Hash<String, Hash<String, Object>>] The attribute schema for the
|
73
|
+
# game this inventory belongs to
|
74
|
+
# @see #update_schema
|
51
75
|
def attribute_schema
|
52
76
|
update_schema unless @@attribute_schema.key? app_id
|
53
77
|
|
@@ -71,6 +95,10 @@ module GameInventory
|
|
71
95
|
# Returns the item schema
|
72
96
|
#
|
73
97
|
# The schemas are fetched first if not done already
|
98
|
+
#
|
99
|
+
# @return [Hash<Fixnum, Hash<String, Object>>] The item schema for the game
|
100
|
+
# this inventory belongs to
|
101
|
+
# @see #upde_schema
|
74
102
|
def item_schema
|
75
103
|
update_schema unless @@item_schema.key? app_id
|
76
104
|
|
@@ -80,6 +108,9 @@ module GameInventory
|
|
80
108
|
# Returns the quality schema
|
81
109
|
#
|
82
110
|
# The schemas are fetched first if not done already
|
111
|
+
#
|
112
|
+
# @return [Hash<Fixnum, String>] The quality schema for this game
|
113
|
+
# @see #update_schema
|
83
114
|
def qualities
|
84
115
|
update_schema unless @@qualities.key? app_id
|
85
116
|
|
@@ -87,6 +118,8 @@ module GameInventory
|
|
87
118
|
end
|
88
119
|
|
89
120
|
# Returns the number of items in the user's inventory
|
121
|
+
#
|
122
|
+
# @return [Fixnum] The number of items in the inventory
|
90
123
|
def size
|
91
124
|
@items.size
|
92
125
|
end
|
@@ -94,7 +127,7 @@ module GameInventory
|
|
94
127
|
protected
|
95
128
|
|
96
129
|
# Updates the item schema (this includes attributes and qualities) using the
|
97
|
-
#
|
130
|
+
# `GetSchema` method of interface `IEconItems_[AppID]`
|
98
131
|
def update_schema
|
99
132
|
params = {}
|
100
133
|
params[:language] = @@schema_language unless @@schema_language.nil?
|
@@ -5,13 +5,72 @@
|
|
5
5
|
|
6
6
|
require 'steam/community/web_api'
|
7
7
|
|
8
|
-
#
|
8
|
+
# A module implementing basic functionality for classes representing an item in
|
9
|
+
# a game
|
10
|
+
#
|
11
|
+
# @author Sebastian Staudt
|
9
12
|
module GameItem
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
# Return the attributes of this item
|
15
|
+
#
|
16
|
+
# @return [Hash<Symbol, Object>] The attributes of this item
|
17
|
+
attr_reader :attributes
|
18
|
+
|
19
|
+
# Returns the position of this item in the player's inventory
|
20
|
+
#
|
21
|
+
# @return [Fixnum] The position of this item in the player's inventory
|
22
|
+
attr_reader :backpack_position
|
23
|
+
|
24
|
+
# Returns the class of this item
|
25
|
+
#
|
26
|
+
# @return [String] The class of this item
|
27
|
+
attr_reader :class
|
28
|
+
|
29
|
+
# Returns the number of items the player owns of this item
|
30
|
+
#
|
31
|
+
# @return [Fixnum] The quanitity of this item
|
32
|
+
attr_reader :count
|
33
|
+
|
34
|
+
# Returns the index where the item is defined in the schema
|
35
|
+
#
|
36
|
+
# @return [Fixnum] The schema index of this item
|
37
|
+
attr_reader :defindex
|
38
|
+
|
39
|
+
# Returns the ID of this item
|
40
|
+
#
|
41
|
+
# @return [Fixnum] The ID of this item
|
42
|
+
attr_reader :id
|
43
|
+
|
44
|
+
# Returns the level of this item
|
45
|
+
#
|
46
|
+
# @return [Fixnum] The level of this item
|
47
|
+
attr_reader :level
|
48
|
+
|
49
|
+
# Returns the level of this item
|
50
|
+
#
|
51
|
+
# @return [String] The level of this item
|
52
|
+
attr_reader :name
|
53
|
+
|
54
|
+
# Returns the quality of this item
|
55
|
+
#
|
56
|
+
# @return [String] The quality of this item
|
57
|
+
attr_reader :quality
|
58
|
+
|
59
|
+
# Returns the slot where this item can be equipped in or `nil` if this item
|
60
|
+
# cannot be equipped
|
61
|
+
#
|
62
|
+
# @return [String] The slot where this item can be equipped in
|
63
|
+
attr_reader :slot
|
64
|
+
|
65
|
+
# Returns the type of this item
|
66
|
+
#
|
67
|
+
# @return [String] The type of this item
|
68
|
+
attr_reader :type
|
13
69
|
|
14
70
|
# Creates a new instance of a GameItem with the given data
|
71
|
+
#
|
72
|
+
# @param [GameInventory] inventory The inventory this item is contained in
|
73
|
+
# @param [Hash<Symbol, Object>] item_data The data representing this item
|
15
74
|
def initialize(inventory, item_data)
|
16
75
|
@defindex = item_data[:defindex]
|
17
76
|
@backpack_position = item_data[:inventory] & 0xffff
|
@@ -31,6 +90,8 @@ module GameItem
|
|
31
90
|
end
|
32
91
|
|
33
92
|
# Returns whether this item is tradeable
|
93
|
+
#
|
94
|
+
# @return [Boolean] `true` if this item is tradeable
|
34
95
|
def tradeable?
|
35
96
|
@tradeable
|
36
97
|
end
|
@@ -8,15 +8,57 @@ require 'rexml/document'
|
|
8
8
|
|
9
9
|
require 'steam/community/game_achievement'
|
10
10
|
|
11
|
-
#
|
12
|
-
#
|
11
|
+
# This class represents the game statistics for a single user and a specific
|
12
|
+
# game
|
13
|
+
#
|
14
|
+
# It is subclassed for individual games if the games provide special statistics
|
15
|
+
# that are unique to this game.
|
16
|
+
#
|
17
|
+
# @author Sebastian Staudt
|
13
18
|
class GameStats
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
+
# Returns the Steam application ID of the game these stats belong to
|
21
|
+
#
|
22
|
+
# @return [Fixnum] The Steam application ID of the game
|
23
|
+
attr_reader :app_id
|
24
|
+
|
25
|
+
# Returns the custom URL of the player these stats belong to
|
26
|
+
#
|
27
|
+
# @return [String] The custom URL of the player
|
28
|
+
attr_reader :custom_url
|
29
|
+
|
30
|
+
# Returns the friendly name of the game these stats belong to
|
31
|
+
#
|
32
|
+
# @return [String ]The frienldy name of the game
|
33
|
+
attr_reader :game_friendly_name
|
34
|
+
|
35
|
+
# Returns the full name of the game these stats belong to
|
36
|
+
#
|
37
|
+
# @return [String] The name of the game
|
38
|
+
attr_reader :game_name
|
39
|
+
|
40
|
+
# Returns the number of hours this game has been played by the player
|
41
|
+
#
|
42
|
+
# @return [String] The number of hours this game has been played
|
43
|
+
attr_reader :hours_played
|
44
|
+
|
45
|
+
# Returns the privacy setting of the Steam ID profile
|
46
|
+
#
|
47
|
+
# @return [String] The privacy setting of the Steam ID
|
48
|
+
attr_reader :privacy_state
|
49
|
+
|
50
|
+
# Returns the 64bit numeric SteamID of the player these stats belong to
|
51
|
+
#
|
52
|
+
# @return [Fixnum] The 64bit numeric SteamID of the player
|
53
|
+
attr_reader :steam_id64
|
54
|
+
|
55
|
+
# Creates a `GameStats` (or one of its subclasses) instance for the given
|
56
|
+
# user and game
|
57
|
+
#
|
58
|
+
# @param [String, Fixnum] steam_id The custom URL or the 64bit Steam ID of
|
59
|
+
# the user
|
60
|
+
# @param [String] game_name The friendly name of the game
|
61
|
+
# @return [GameStats] The game stats object for the given user and game
|
20
62
|
def self.create_game_stats(steam_id, game_name)
|
21
63
|
case game_name
|
22
64
|
when 'alienswarm'
|
@@ -48,8 +90,13 @@ class GameStats
|
|
48
90
|
end
|
49
91
|
end
|
50
92
|
|
51
|
-
# Creates a GameStats object and fetches data from the Steam Community for
|
93
|
+
# Creates a `GameStats` object and fetches data from the Steam Community for
|
52
94
|
# the given user and game
|
95
|
+
#
|
96
|
+
# @param [String, Fixnum] id The custom URL or the 64bit Steam ID of the
|
97
|
+
# user
|
98
|
+
# @param [String] game_name The friendly name of the game
|
99
|
+
# @raise [SteamCondenserError] if the stats cannot be fetched
|
53
100
|
def initialize(id, game_name)
|
54
101
|
if id.is_a? Numeric
|
55
102
|
@steam_id64 = id
|
@@ -62,7 +109,7 @@ class GameStats
|
|
62
109
|
@xml_data = REXML::Document.new(open(url, {:proxy => true}).read).root
|
63
110
|
|
64
111
|
error = @xml_data.elements['error']
|
65
|
-
raise
|
112
|
+
raise SteamCondenserError, error.text unless error.nil?
|
66
113
|
|
67
114
|
@privacy_state = @xml_data.elements['privacyState'].text
|
68
115
|
if public?
|
@@ -74,8 +121,11 @@ class GameStats
|
|
74
121
|
end
|
75
122
|
end
|
76
123
|
|
77
|
-
# Returns the achievements for this stats' user and game
|
78
|
-
#
|
124
|
+
# Returns the achievements for this stats' user and game
|
125
|
+
#
|
126
|
+
# If the achievements' data hasn't been parsed yet, parsing is done now.
|
127
|
+
#
|
128
|
+
# @return [Array<GameAchievement>] All achievements belonging to this game
|
79
129
|
def achievements
|
80
130
|
return unless public?
|
81
131
|
|
@@ -91,20 +141,32 @@ class GameStats
|
|
91
141
|
@achievements
|
92
142
|
end
|
93
143
|
|
94
|
-
# Returns the
|
95
|
-
#
|
144
|
+
# Returns the number of achievements done by this player
|
145
|
+
#
|
146
|
+
# If achievements haven't been parsed yet for this player and this game,
|
147
|
+
# parsing is done now.
|
148
|
+
#
|
149
|
+
# @return [Fixnum] The number of achievements completed
|
150
|
+
# @see #achievements
|
96
151
|
def achievements_done
|
97
152
|
achievements if @achievements_done.nil?
|
98
153
|
@achievements_done
|
99
154
|
end
|
100
155
|
|
101
|
-
# Returns
|
102
|
-
#
|
156
|
+
# Returns the percentage of achievements done by this player
|
157
|
+
#
|
158
|
+
# If achievements haven't been parsed yet for this player and this game,
|
159
|
+
# parsing is done now.
|
160
|
+
#
|
161
|
+
# @return [Float] The percentage of achievements completed
|
162
|
+
# @see #achievements_done
|
103
163
|
def achievements_percentage
|
104
164
|
achievements_done.to_f / @achievements.size
|
105
165
|
end
|
106
166
|
|
107
|
-
# Returns the base URL for
|
167
|
+
# Returns the base Steam Communtiy URL for the stats contained in this object
|
168
|
+
#
|
169
|
+
# @return [String] The base URL used for queries on these stats
|
108
170
|
def base_url
|
109
171
|
if @custom_url.nil?
|
110
172
|
"http://steamcommunity.com/profiles/#{@steam_id64}/stats/#{@game_friendly_name}"
|
@@ -113,6 +175,9 @@ class GameStats
|
|
113
175
|
end
|
114
176
|
end
|
115
177
|
|
178
|
+
# Returns whether this Steam ID is publicly accessible
|
179
|
+
#
|
180
|
+
# @return [Boolean] `true` if this Steam ID is publicly accessible
|
116
181
|
def public?
|
117
182
|
@privacy_state == 'public'
|
118
183
|
end
|