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
It also provides the ability to load the global unlock percentages of all achievements of a specific game.
Instance Attribute Summary collapse
-
#api_name ⇒ String
readonly
Returns the symbolic API name of this achievement.
-
#description ⇒ String
readonly
Returns the description of this achievement.
-
#game ⇒ Steam
readonly
Return the game this achievement belongs to.
-
#icon_closed_url ⇒ String
readonly
Returns the url for the closed icon of this achievement.
-
#icon_open_url ⇒ String
readonly
Returns the url for the open icon of this achievement.
-
#name ⇒ String
readonly
Returns the name of this achievement.
-
#timestamp ⇒ Time
readonly
Returns the time this achievement has been unlocked by its owner.
-
#user ⇒ Fixnum
readonly
Returns the SteamID of the user who owns this achievement.
Class Method Summary collapse
-
.global_percentages(app_id) ⇒ Hash<Symbol, Float>
Loads the global unlock percentages of all achievements for the game with the given Steam Application ID.
Instance Method Summary collapse
-
#initialize(user, game, 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(user, game, achievement_data) ⇒ GameAchievement
Creates the achievement with the given name for the given user and game and achievement data
87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/steam/community/game_achievement.rb', line 87 def initialize(user, game, achievement_data) @api_name = achievement_data['apiname'] @description = achievement_data['description'] @game = game @icon_closed_url = achievement_data['iconClosed'] @icon_open_url = achievement_data['iconOpen'] @name = achievement_data['name'] @unlocked = (achievement_data['closed'].to_i == 1) @user = user if @unlocked && !achievement_data['unlockTimestamp'].nil? @timestamp = Time.at(achievement_data['unlockTimestamp'].to_i) end end |
Instance Attribute Details
#api_name ⇒ String (readonly)
Returns the symbolic API name of this achievement
22 23 24 |
# File 'lib/steam/community/game_achievement.rb', line 22 def api_name @api_name end |
#description ⇒ String (readonly)
Returns the description of this achievement
27 28 29 |
# File 'lib/steam/community/game_achievement.rb', line 27 def description @description end |
#game ⇒ Steam (readonly)
Return the game this achievement belongs to
32 33 34 |
# File 'lib/steam/community/game_achievement.rb', line 32 def game @game end |
#icon_closed_url ⇒ String (readonly)
Returns the url for the closed icon of this achievement
37 38 39 |
# File 'lib/steam/community/game_achievement.rb', line 37 def icon_closed_url @icon_closed_url end |
#icon_open_url ⇒ String (readonly)
Returns the url for the open icon of this achievement
42 43 44 |
# File 'lib/steam/community/game_achievement.rb', line 42 def icon_open_url @icon_open_url end |
#name ⇒ String (readonly)
Returns the name of this achievement
47 48 49 |
# File 'lib/steam/community/game_achievement.rb', line 47 def name @name end |
#timestamp ⇒ Time (readonly)
Returns the time this achievement has been unlocked by its owner
52 53 54 |
# File 'lib/steam/community/game_achievement.rb', line 52 def @timestamp end |
#user ⇒ Fixnum (readonly)
Returns the SteamID of the user who owns this achievement
57 58 59 |
# File 'lib/steam/community/game_achievement.rb', line 57 def user @user end |
Class Method Details
.global_percentages(app_id) ⇒ Hash<Symbol, Float>
Loads the global unlock percentages of all achievements for the game with the given Steam Application ID
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/steam/community/game_achievement.rb', line 69 def self.global_percentages(app_id) percentages = {} data = WebApi.json('ISteamUserStats', 'GetGlobalAchievementPercentagesForApp', 2, { :gameid => app_id }) MultiJson.load(data, { :symbolize_keys => true })[:achievementpercentages][:achievements].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
105 106 107 |
# File 'lib/steam/community/game_achievement.rb', line 105 def unlocked? @unlocked end |