SteamWebApi
This is a gem that makes trivial interacting with the Steam Web API. It supports all methods listed here: https://developer.valvesoftware.com/wiki/Steam_Web_API and one more.
Supported Ruby version
Gem supports Ruby: 2.0, 2.1, 2.2
Installation
Add this line to your application's Gemfile:
gem 'steam_web_api'
And then execute:
$ bundle
Or run in the console:
$ gem install steam_web_api
Usage
Configuration
Some Steam Web API methods return publicly accessible data and do not require authorization when called. Other methods may require clients to register for an API key and pass that in using the key parameter. There are also methods that return sensitive data or perform a protected action and require special access permissions. To retrieve API key for your application, you'll need log in to your Steam account and fill this form
When you have your API key, you can configure the gem:
SteamWebApi.configure do |config|
config.api_key = 'your api key'
end
This is better not to include API key as plain text in you repository. For better solution, please check dotenv gem.
Player
Get list of owned games
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(player_steam_id)
data = player.owned_games
data.count
data.games
data.success
game = data.games.first
game['appid']
game['playtime_forever']
data = player.owned_games(include_played_free_games: true, include_appinfo: true)
game = data.games.first
game['name']
game['playtime_2weeks']
game['img_icon_url']
game['img_logo_url']
game['has_community_visible_stats']
Get user stats for game
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetUserStatsForGame_.28v0002.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(player_steam_id)
data = player.stats_for_game(game_id)
data.steam_id
data.game_name
data.achievements
data.stats
data.success
achievement = data.achievements.first
achievement['name']
achievement['achieved']
stat = data.stats.first
stat['name']
stat['value']
Get user achievements for game
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerAchievements_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(player_steam_id)
data = player.achievements(game_id)
data.steam_id
data.game_name
data.achievements
data.success
achievement = data.achievements.first
achievement['apiname']
achievement['achieved']
data = player.achievements(game_id, l: 'en')
achievement = data.achievements.first
achievement['name']
achievement['description']
Get accounts summaries for list of players
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
data = SteamWebApi::Player.summary(player.steam_id, player_2.steam_id)
data.players
data.success
first_player = data.players.first
first_player['steamid']
first_player['communityvisibilitystate']
first_player['profilestate']
first_player['personaname']
first_player['lastlogoff']
first_player['profileurl']
first_player['avatar']
first_player['avatarmedium']
first_player['avatarfull']
first_player['personastate']
first_player['realname']
first_player['primaryclanid']
first_player['timecreated']
first_player['personastateflags']
first_player['gameextrainfo']
first_player['gameid']
first_player['loccountrycode']
first_player['locstatecode']
first_player['loccityid']
Get account summary for single player
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29). This is just more convinient method to get account summary if you already have player instance. To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(steam_id)
data = player.summary
data.profile
data.success
data.profile['steamid']
data.profile['communityvisibilitystate']
data.profile['profilestate']
data.profile['personaname']
data.profile['lastlogoff']
data.profile['profileurl']
data.profile['avatar']
data.profile['avatarmedium']
data.profile['avatarfull']
data.profile['personastate']
data.profile['realname']
data.profile['primaryclanid']
data.profile['timecreated']
data.profile['personastateflags']
data.profile['gameextrainfo']
data.profile['gameid']
data.profile['loccountrycode']
data.profile['locstatecode']
data.profile['loccityid']
Get player friends list
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetFriendList_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(steam_id)
data = player.friends
data.friends
data.success
friend = data.friends.first
friend['steamid']
friend['relationship']
friend['friend_since']
player.friends('friend')
Get list of recently played games
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetRecentlyPlayedGames_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(steam_id)
data = player.recently_played_games
data.games
data.total_count
data.success
game = data.games.first
game['appid']
game['name']
game['playtime_2weeks']
game['playtime_forever']
game['img_icon_url']
game['img_logo_url']
player.recently_played_games(2)
Check if player is playing shared game
(https://developer.valvesoftware.com/wiki/Steam_Web_API#IsPlayingSharedGame_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
player = SteamWebApi::Player.new(steam_id)
data = player.playing_shared_game(game_id)
data.lender_steamid
data.success
Get list of bans for list of players
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerBans_.28v1.29). To make this API call, you need to have API key.
data = SteamWebApi::Player.bans(player_1.steam_id, player_2.steam_id)
data.players
data.success
bans = data.players.first
bans['SteamId']
bans['CommunityBanned']
bans['VACBanned']
bans['NumberOfVACBans']
bans['DaysSinceLastBan']
bans['EconomyBan']
Get list of bans for single player
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerBans_.28v1.29). This is just more convinient method to get player bans if you already have player instance. To make this API call, you need to have API key.
player = SteamWebApi::Player.new(steam_id)
data = player.bans
data.success
data.bans['SteamId']
data.bans['CommunityBanned']
data.bans['VACBanned']
data.bans['NumberOfVACBans']
data.bans['DaysSinceLastBan']
data.bans['EconomyBan']
Game
Get list of all games
This end-point is not described in official documentation.
data = SteamWebApi::Game.all
data.games
data.success
game = data.games.first
game['appid']
game['name']
Get game schema
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetSchemaForGame_.28v2.29). To make this API call, you need to have API key for your app.
game = SteamWebApi::Game.new(game_id)
schema = game.schema
schema.name
schema.version
schema.achievements
schema.stats
schema.success
achievement = schema.achievements.first
achievement['name']
achievement['defaultvalue']
achievement['displayName']
achievement['hidden']
achievement['description']
achievement['icon']
achievement['icongray']
stats = schema.stats.first
stats['name']
stats['defaultvalue']
stats['displayName']
Get list of global game achievements in percentage
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetGlobalAchievementPercentagesForApp_.28v0002.29)
game = SteamWebApi::Game.new(game_id)
data = game.achievement_percentages
data.achievements
data.success
achievement = data.achievements.first
achievement['name']
achievement['percent']
Get list of news
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetNewsForApp_.28v0002.29)
game = SteamWebApi::Game.new(game_id)
news = game.news
news.app_id
news.news_items
news.success
first_news = news.news_items.first
first_news['gid']
first_news['title']
first_news['url']
first_news['is_external_url']
first_news['author']
first_news['contents']
first_news['feedlabel']
first_news['date']
first_news['feedname']
data = game.news(count: 10, max_length: 1000)
Contributing
- Fork it ( https://github.com/[my-github-username]/steam_web_api/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request