Module: Steam::UserStats

Defined in:
lib/steam-api/steam/user_stats.rb

Overview

A Ruby DSL for communicating with the Steam Web API.

Class Method Summary collapse

Class Method Details

.achievement_percentages(appid) ⇒ Hash

Get Global Achievement Percentages for App

Parameters:

  • appid (Fixnum)

    The ID of the game or application

Returns:

  • (Hash)

    The hash object of information on the global achievements overview of a specific game in percentages.

See Also:

Since:

  • 1.0.0



11
12
13
14
15
16
17
# File 'lib/steam-api/steam/user_stats.rb', line 11

def self.achievement_percentages(appid)
  response = client.get 'GetGlobalAchievementPercentagesForApp/v2',
                        params: { gameid: appid }
  response = response.parse_key('achievementpercentages')
                     .parse_key('achievements')
  response
end

.clientObject

Since:

  • 1.0.0



90
91
92
# File 'lib/steam-api/steam/user_stats.rb', line 90

def self.client
  build_client('ISteamUserStats')
end

.game_schema(appid, language: nil) ⇒ Hash

Get stat schema

Parameters:

  • appid (Fixnum)

    The application ID for the Steam Game.

  • language (String) (defaults to: nil)

    (Optional) Language

Returns:

  • (Hash)

    A hash containing the API response

See Also:

Since:

  • 1.0.0



44
45
46
47
48
49
# File 'lib/steam-api/steam/user_stats.rb', line 44

def self.game_schema(appid, language: nil)
  params = { appid: appid }
  params[:l] = language unless language.nil?
  response = client.get 'GetSchemaForGame/v2', params: params
  response.parse_key('game')
end

.global_for_game(appid, params: {}) ⇒ Hash

Get Global Stats for Game

Parameters:

  • appid (Fixnum)

    The ID of the game or application

  • params (Hash) (defaults to: {})

    Parameters to pass to the API

Options Hash (params:):

  • :count (Fixnum)

    Number of stats to get data for.

  • :name[0] (String)

    Names of the stats to get. For more than one value, use a parameter for each request. (name, name, …) Not all stats are globally aggregated. The developer of the game must mark the stat as globally aggregated.

  • :startdate (String)

    Start date for daily totals (unix epoch timestamp). (Optional)

  • :enddate (String)

    End date for daily totals (unix epoch timestamp). (Optional)

Returns:

  • (Hash)

    A hash containing the API response

See Also:

Since:

  • 1.0.0



33
34
35
36
37
# File 'lib/steam-api/steam/user_stats.rb', line 33

def self.global_for_game(appid, params: {})
  params[:appid] = appid
  response = client.get 'GetGlobalStatsForGame/v1', params: params
  response.parse_key('response')
end

.player_achievements(appid, steamid, language: nil) ⇒ Hash

Get Player Achievements

Parameters:

  • steamid (Fixnum)

    64 bit Steam ID to return Achievements list for.

  • appid (Fixnum)

    AppID to get achievements for

  • language (String) (defaults to: nil)

    Language. If specified, it will return language data for the requested language. (Optional)

Returns:

  • (Hash)

    A hash containing the API response

See Also:

Since:

  • 1.0.0



69
70
71
72
73
74
75
76
77
# File 'lib/steam-api/steam/user_stats.rb', line 69

def self.player_achievements(appid, steamid, language: nil)
  params = { appid: appid, steamid: steamid }
  params[:l] = language unless language.nil?
  response = client.get 'GetPlayerAchievements/v1', params: params
  response = response.parse_key('playerstats')
  response.check_success
  response.delete('success')
  response
end

.player_count(appid) ⇒ Hash

Get Number of Current Players

Parameters:

  • appid (Fixnum)

    to pass to the API

Returns:

  • (Hash)

    A hash containing the API response

See Also:

Since:

  • 1.0.0



55
56
57
58
59
60
# File 'lib/steam-api/steam/user_stats.rb', line 55

def self.player_count(appid)
  response = client.get 'GetNumberOfCurrentPlayers/v1',
                        params: { appid: appid }
  response.parse_key('response')
          .parse_key('player_count')
end

.player_stats(appid, steamid) ⇒ Hash

Get User Stats for Game

Parameters:

  • appid (Fixnum)

    AppID to get stats for.

  • steamid (Fixnum)

    64 bit Steam ID to return stats for.

Returns:

  • (Hash)

    A hash containing the API response.

See Also:

Since:

  • 1.0.0



84
85
86
87
88
# File 'lib/steam-api/steam/user_stats.rb', line 84

def self.player_stats(appid, steamid)
  params = { appid: appid, steamid: steamid }
  response = client.get 'GetUserStatsForGame/v2', params: params
  response.parse_key('playerstats')
end