Class: SteamGame
- Inherits:
-
Object
- Object
- SteamGame
- Includes:
- Cacheable
- Defined in:
- lib/steam/community/steam_game.rb
Overview
This class represents a game available on Steam
Instance Attribute Summary collapse
-
#app_id ⇒ Fixnum
readonly
Returns the Steam application ID of this game.
-
#icon_url ⇒ String
readonly
Returns the URL for the icon image of this game.
-
#name ⇒ String
readonly
Returns the full name of this game.
-
#short_name ⇒ String
readonly
Returns the short name of this game (also known as “friendly name”).
Attributes included from Cacheable
Class Method Summary collapse
-
.check_steam_inf(path) ⇒ Boolean
Checks if a game is up-to-date by reading information from a ‘steam.inf` file and comparing it using the Web API.
-
.new(app_id, game_data = nil) ⇒ Object
Creates a new instance of a game with the given data and caches it.
-
.uptodate?(app_id, version) ⇒ Boolean
Returns whether the given version of the game with the given application ID is up-to-date.
Instance Method Summary collapse
-
#has_stats? ⇒ Boolean
Returns whether this game has statistics available.
-
#id ⇒ Fixnum, String
Returns a unique identifier for this game.
-
#leaderboard(id) ⇒ GameLeaderboard
Returns the leaderboard for this game and the given leaderboard ID or name.
-
#leaderboards ⇒ Array<GameLeaderboard>
Returns an array containing all of this game’s leaderboards.
-
#logo_thumbnail_url ⇒ String
Returns the URL for the logo thumbnail image of this game.
-
#logo_url ⇒ String
Returns the URL for the logo image of this game.
-
#player_count ⇒ Fixnum
Returns the overall number of players currently playing this game.
-
#store_url ⇒ String
Returns the URL of this game’s page in the Steam Store.
-
#uptodate?(version) ⇒ Boolean
Returns whether the given version of this game is up-to-date.
-
#user_stats(steam_id) ⇒ GameStats
Creates a stats object for the given user and this game.
Methods included from Cacheable
#cache, #fetch, #fetched?, included
Instance Attribute Details
#app_id ⇒ Fixnum (readonly)
Returns the Steam application ID of this game
22 23 24 |
# File 'lib/steam/community/steam_game.rb', line 22 def app_id @app_id end |
#icon_url ⇒ String (readonly)
Returns the URL for the icon image of this game
27 28 29 |
# File 'lib/steam/community/steam_game.rb', line 27 def icon_url @icon_url end |
#name ⇒ String (readonly)
Returns the full name of this game
32 33 34 |
# File 'lib/steam/community/steam_game.rb', line 32 def name @name end |
#short_name ⇒ String (readonly)
Returns the short name of this game (also known as “friendly name”)
37 38 39 |
# File 'lib/steam/community/steam_game.rb', line 37 def short_name @short_name end |
Class Method Details
.check_steam_inf(path) ⇒ Boolean
Checks if a game is up-to-date by reading information from a ‘steam.inf` file and comparing it using the Web API
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/steam/community/steam_game.rb', line 44 def self.check_steam_inf(path) steam_inf = File.read path begin app_id = steam_inf.match(/^\s*appID=(\d+)\s*$/im)[1].to_i version = steam_inf.match(/^\s*PatchVersion=([\d\.]+)\s*$/im)[1].gsub('.', '').to_i rescue raise SteamCondenserError, "The steam.inf file at \"#{path}\" is invalid." end uptodate? app_id, version end |
.new(app_id, game_data = nil) ⇒ Object
Creates a new instance of a game with the given data and caches it
59 60 61 62 63 64 65 66 67 |
# File 'lib/steam/community/steam_game.rb', line 59 def self.new(app_id, game_data = nil) if cached? app_id class_variable_get(:@@cache)[app_id] else game = SteamGame.allocate game.send :initialize, app_id, game_data game end end |
.uptodate?(app_id, version) ⇒ Boolean
Returns whether the given version of the game with the given application ID is up-to-date
75 76 77 78 79 80 81 |
# File 'lib/steam/community/steam_game.rb', line 75 def self.uptodate?(app_id, version) params = { :appid => app_id, :version => version } result = WebApi.json 'ISteamApps', 'UpToDateCheck', 1, params result = MultiJson.load(result, { :symbolize_keys => true})[:response] raise SteamCondenserError, result[:error] unless result[:success] result[:up_to_date] end |
Instance Method Details
#has_stats? ⇒ Boolean
Returns whether this game has statistics available
96 97 98 |
# File 'lib/steam/community/steam_game.rb', line 96 def has_stats? !@short_name.nil? end |
#id ⇒ Fixnum, String
Returns a unique identifier for this game
This is either the numeric application ID or the unique short name
105 106 107 |
# File 'lib/steam/community/steam_game.rb', line 105 def id @short_name == @app_id.to_s ? @app_id : @short_name end |
#leaderboard(id) ⇒ GameLeaderboard
Returns the leaderboard for this game and the given leaderboard ID or name
113 114 115 |
# File 'lib/steam/community/steam_game.rb', line 113 def leaderboard(id) GameLeaderboard.leaderboard @short_name, id end |
#leaderboards ⇒ Array<GameLeaderboard>
Returns an array containing all of this game’s leaderboards
120 121 122 |
# File 'lib/steam/community/steam_game.rb', line 120 def leaderboards GameLeaderboard.leaderboards @short_name end |
#logo_thumbnail_url ⇒ String
Returns the URL for the logo thumbnail image of this game
135 136 137 138 |
# File 'lib/steam/community/steam_game.rb', line 135 def logo_thumbnail_url return nil if @logo_hash.nil? "http://media.steampowered.com/steamcommunity/public/images/apps/#@app_id/#{@logo_hash}_thumb.jpg" end |
#logo_url ⇒ String
Returns the URL for the logo image of this game
127 128 129 130 |
# File 'lib/steam/community/steam_game.rb', line 127 def logo_url return nil if @logo_hash.nil? "http://media.steampowered.com/steamcommunity/public/images/apps/#@app_id/#@logo_hash.jpg" end |
#player_count ⇒ Fixnum
Returns the overall number of players currently playing this game
86 87 88 89 90 91 |
# File 'lib/steam/community/steam_game.rb', line 86 def player_count params = { :appid => @app_id } result = WebApi.json 'ISteamUserStats', 'GetNumberOfCurrentPlayers', 1, params result = MultiJson.load(result, { :symbolize_keys => true})[:response] result[:player_count] end |
#store_url ⇒ String
Returns the URL of this game’s page in the Steam Store
143 144 145 |
# File 'lib/steam/community/steam_game.rb', line 143 def store_url "http://store.steampowered.com/app/#@app_id" end |
#uptodate?(version) ⇒ Boolean
Returns whether the given version of this game is up-to-date
151 152 153 |
# File 'lib/steam/community/steam_game.rb', line 151 def uptodate?(version) self.class.uptodate? @app_id, version end |
#user_stats(steam_id) ⇒ GameStats
Creates a stats object for the given user and this game
160 161 162 163 164 |
# File 'lib/steam/community/steam_game.rb', line 160 def user_stats(steam_id) return unless has_stats? GameStats.create_game_stats steam_id, @short_name end |