Class: GameAchievement
- Inherits:
-
Object
- Object
- GameAchievement
- Defined in:
- lib/steam/community/game_achievement.rb
Overview
The GameAchievement class represents a specific achievement for a single game and for a single user
Instance Attribute Summary collapse
-
#app_id ⇒ Object
readonly
Returns the value of attribute app_id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#steam_id64 ⇒ Object
readonly
Returns the value of attribute steam_id64.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Class Method Summary collapse
-
.global_percentages(app_id) ⇒ Object
Loads the global unlock percentages of all achievements for the given game.
Instance Method Summary collapse
-
#initialize(steam_id64, app_id, achievement_data) ⇒ GameAchievement
constructor
Creates the achievement with the given name for the given user and game and achievement data.
-
#unlocked? ⇒ Boolean
Returns whether this achievement has been unlocked by its owner.
Constructor Details
#initialize(steam_id64, app_id, achievement_data) ⇒ GameAchievement
Creates the achievement with the given name for the given user and game and achievement data
steam_id64
-
The 64bit SteamID of the player this achievement belongs to
app_id
-
The unique Steam Application ID of the game (e.g.
440
for Team Fortress 2). See developer.valvesoftware.com/wiki/Steam_Application_IDs for all application IDs achievement_data
-
The achievement data extracted from JSON
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/steam/community/game_achievement.rb', line 43 def initialize(steam_id64, app_id, achievement_data) @app_id = app_id @name = achievement_data.elements['name'].text @steam_id64 = steam_id64 @unlocked = (achievement_data.attributes['closed'].to_i == 1) if @unlocked && !achievement_data.elements['unlockTimestamp'].nil? @timestamp = Time.at(achievement_data.elements['unlockTimestamp'].text.to_i) end end |
Instance Attribute Details
#app_id ⇒ Object (readonly)
Returns the value of attribute app_id.
14 15 16 |
# File 'lib/steam/community/game_achievement.rb', line 14 def app_id @app_id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/steam/community/game_achievement.rb', line 14 def name @name end |
#steam_id64 ⇒ Object (readonly)
Returns the value of attribute steam_id64.
14 15 16 |
# File 'lib/steam/community/game_achievement.rb', line 14 def steam_id64 @steam_id64 end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
14 15 16 |
# File 'lib/steam/community/game_achievement.rb', line 14 def @timestamp end |
Class Method Details
.global_percentages(app_id) ⇒ Object
Loads the global unlock percentages of all achievements for the given game
app_id
-
The unique Steam Application ID of the game (e.g.
440
for Team Fortress 2). See developer.valvesoftware.com/wiki/Steam_Application_IDs for all application IDs
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/steam/community/game_achievement.rb', line 22 def self.global_percentages(app_id) percentages = {} data = WebApi.json('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp', 1, { :gameid => app_id }) JSON.parse(data, { :symbolize_names => true })[:achievementpercentages][:achievements][:achievement].each do |percentage| percentages[percentage[:name].to_sym] = percentage[:percent] end percentages end |
Instance Method Details
#unlocked? ⇒ Boolean
Returns whether this achievement has been unlocked by its owner
55 56 57 |
# File 'lib/steam/community/game_achievement.rb', line 55 def unlocked? @unlocked end |