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



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

def self.achievement_percentages(appid)
  response = client.get 'GetGlobalAchievementPercentagesForApp/v2',
                        params: { gameid: appid }
  response = response.parse_key('achievementpercentages')
                     .parse_key('achievements')
  response
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



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

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



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

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



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

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



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

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