Class: Stew::Community::WebApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stew/community/web_api_client.rb

Constant Summary collapse

BASE_URI =
'http://api.steampowered.com'

Instance Method Summary collapse

Constructor Details

#initialize(client = WebClient.new(BASE_URI), opts = {}) ⇒ WebApiClient

Returns a new instance of WebApiClient.



6
7
8
9
# File 'lib/stew/community/web_api_client.rb', line 6

def initialize(client = WebClient.new(BASE_URI), opts={})
  @api_key = opts[:steam_api_key] || Stew.config[:steam_api_key]
  @client = client
end

Instance Method Details

#profile(steam_id) ⇒ Object



16
17
18
# File 'lib/stew/community/web_api_client.rb', line 16

def profile(steam_id)
  @client.get("/ISteamUser/GetPlayerSummaries/v0002/?key=#{@api_key}&steamids=#{steam_id}")['response']['players'].first
end

#profile_friends(steam_id) ⇒ Object



24
25
26
# File 'lib/stew/community/web_api_client.rb', line 24

def profile_friends(steam_id)
  @client.get("/ISteamUser/GetFriendList/v0001/?key=#{@api_key}&steamid=#{steam_id}&relationship=friend")['friendslist']['friends']
end

#profile_games(steam_id) ⇒ Object



20
21
22
# File 'lib/stew/community/web_api_client.rb', line 20

def profile_games(steam_id)
  @client.get("/IPlayerService/GetOwnedGames/v0001/?key=#{@api_key}&steamid=#{steam_id}&include_appinfo=1")['response']['games']
end

#vanity_url_to_steam_id(vanity_url) ⇒ Object



11
12
13
14
# File 'lib/stew/community/web_api_client.rb', line 11

def vanity_url_to_steam_id(vanity_url)
  vanity_name = vanity_url.split('/').last
  @client.get("/ISteamUser/ResolveVanityURL/v0001/?key=#{@api_key}&vanityurl=#{vanity_name}")['response']['steamid'].to_i
end