Class: Stew::CommunityClient

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

Overview

Creation of all profile* objects. Uses a given or default XmlClient instance to communicate with the Steam API The main identifier for most methods is the 64-bit steam id

Examples:

Create a Profile

Stew::CommunityClient.new.profile(76561197992917668) #=> Stew::Community::Profile

Resolve a Steam Vanity name

Stew::CommunityClient.steam_id_from_vanity_name('eekon20') #=> 76561197986383225

Constant Summary collapse

COMMUNITY_URL =
'http://steamcommunity.com'
DEFAULT_BASE_PATH =
'profiles'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ CommunityClient

Returns a new instance of CommunityClient.



19
20
21
22
# File 'lib/stew/community_client.rb', line 19

def initialize(opts = {})
  @xml_client = opts[:client] || Stew.config[:default_xml_client].new(COMMUNITY_URL)
  @base_path = opts[:base_path] || DEFAULT_BASE_PATH
end

Class Method Details

.steam_id_from_vanity_name(vanity_name) ⇒ Object



15
16
17
# File 'lib/stew/community_client.rb', line 15

def self.steam_id_from_vanity_name(vanity_name)
  Stew::XmlClient.new(COMMUNITY_URL).get("/id/#{vanity_name}")['profile']['steamID64'].to_i
end

Instance Method Details

#profile(steam_id) ⇒ Object



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

def profile(steam_id)
  Community::Profile.new @xml_client.get(path(steam_id))['profile']
end

#profile_friends(steam_id) ⇒ Object



32
33
34
# File 'lib/stew/community_client.rb', line 32

def profile_friends(steam_id)
  Community::ProfileFriends.new @xml_client.get(path(steam_id,'friends'))['friendsList']['friends']['friend']
end

#profile_games(steam_id) ⇒ Object



28
29
30
# File 'lib/stew/community_client.rb', line 28

def profile_games(steam_id)
  Community::ProfileGames.new @xml_client.get(path(steam_id,'games'))['gamesList']['games']['game']
end