class SteamWebApi::Player
Attributes
steam_id[RW]
Public Class Methods
bans(*ids)
click to toggle source
# File lib/steam_web_api/player.rb, line 18 def bans(*ids) response = Faraday.get('http://api.steampowered.com/ISteamUser/GetPlayerBans/v1', options(ids)) build_response(response, 'players') { |data| { players: data } } end
new(steam_id)
click to toggle source
# File lib/steam_web_api/player.rb, line 7 def initialize(steam_id) @steam_id = steam_id end
summary(*ids)
click to toggle source
# File lib/steam_web_api/player.rb, line 13 def summary(*ids) response = Faraday.get('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002', options(ids)) build_response(response, 'response') { |data| { players: data['players'] } } end
Private Class Methods
options(*ids)
click to toggle source
# File lib/steam_web_api/player.rb, line 25 def options(*ids) { key: SteamWebApi.config.api_key, steamids: ids.join(',') } end
Public Instance Methods
achievements(app_id, options={})
click to toggle source
# File lib/steam_web_api/player.rb, line 41 def achievements(app_id, options={}) @response = get('/ISteamUserStats/GetPlayerAchievements/v0001', achievements_options(app_id, options)) build_response('playerstats') { |data| { steam_id: data['steamID'], game_name: data['gameName'], achievements: data['achievements'] } } end
bans()
click to toggle source
# File lib/steam_web_api/player.rb, line 66 def bans data = self.class.bans(steam_id) get_first_data(data) { |data| { bans: data.players.first } } end
friends(relationship='all')
click to toggle source
# File lib/steam_web_api/player.rb, line 51 def friends(relationship='all') @response = get('/ISteamUser/GetFriendList/v0001', friends_list_options(relationship)) build_response('friendslist') { |data| { friends: data['friends'] } } end
owned_games(options={})
click to toggle source
# File lib/steam_web_api/player.rb, line 31 def owned_games(options={}) @response = get('/IPlayerService/GetOwnedGames/v0001', owned_games_options(options)) build_response('response') { |data| { count: data['game_count'], games: data['games'] } } end
recently_played_games(count=nil)
click to toggle source
# File lib/steam_web_api/player.rb, line 56 def recently_played_games(count=nil) @response = get('/IPlayerService/GetRecentlyPlayedGames/v0001', recent_games_options(count)) build_response('response') { |data| { games: data['games'], total_count: data['total_count'] } } end
stats_for_game(app_id)
click to toggle source
# File lib/steam_web_api/player.rb, line 36 def stats_for_game(app_id) @response = get('/ISteamUserStats/GetUserStatsForGame/v0002', stats_for_game_options(app_id)) build_response('playerstats') { |data| { steam_id: data['steamID'], game_name: data['gameName'], achievements: data['achievements'], stats: data['stats'] } } end
summary()
click to toggle source
# File lib/steam_web_api/player.rb, line 46 def summary data = self.class.summary(steam_id) get_first_data(data) { |data| { profile: data.players.first } } end
Private Instance Methods
achievements_options(game_id, options)
click to toggle source
# File lib/steam_web_api/player.rb, line 90 def achievements_options(game_id, options) { appid: game_id, key: SteamWebApi.config.api_key, steamid: steam_id }.merge!(options) end
friends_list_options(relationship)
click to toggle source
# File lib/steam_web_api/player.rb, line 94 def friends_list_options(relationship) { key: SteamWebApi.config.api_key, steamid: steam_id, relationship: relationship } end
get_first_data(data) { |data| ... }
click to toggle source
# File lib/steam_web_api/player.rb, line 73 def get_first_data(data) if data.success && data.players.size > 0 OpenStruct.new yield(data).merge!(success: true) else OpenStruct.new(success: false) end end
owned_games_options(options)
click to toggle source
# File lib/steam_web_api/player.rb, line 81 def owned_games_options(options) options.each { |k, v| options[k] = v ? 1 : 0 } { key: SteamWebApi.config.api_key, steamid: steam_id }.merge!(options) end
recent_games_options(count)
click to toggle source
# File lib/steam_web_api/player.rb, line 98 def recent_games_options(count) { key: SteamWebApi.config.api_key, steamid: steam_id, count: count } end
stats_for_game_options(game_id)
click to toggle source
# File lib/steam_web_api/player.rb, line 86 def stats_for_game_options(game_id) { appid: game_id, key: SteamWebApi.config.api_key, steamid: steam_id } end