Class: Stew::Community::CommunityClient

Inherits:
Object
  • Object
show all
Defined in:
lib/stew/community/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.



21
22
23
24
# File 'lib/stew/community/community_client.rb', line 21

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

Deprecated.

Use CommunityClient.new.steam_id_from_vanity_name instead



17
18
19
# File 'lib/stew/community/community_client.rb', line 17

def self.steam_id_from_vanity_name(vanity_name)
  self.new.steam_id_from_vanity_name(vanity_name)
end

Instance Method Details

#profile(steam_id) ⇒ Object



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

def profile(steam_id)
  response = XmlClientResponseProfile.new(@xml_client.get(path(steam_id)))
  Community::Profile.new(response.profile)
end

#profile_friends(steam_id) ⇒ Object



41
42
43
44
# File 'lib/stew/community/community_client.rb', line 41

def profile_friends(steam_id)
  response = XmlClientResponseFriends.new(@xml_client.get(path(steam_id,'friends')))
  Community::ProfileFriends.new(response.friends)
end

#profile_games(steam_id) ⇒ Object



36
37
38
39
# File 'lib/stew/community/community_client.rb', line 36

def profile_games(steam_id)
  response = XmlClientResponseGames.new(@xml_client.get(path(steam_id,'games')))
  Community::ProfileGames.new(response.games)
end

#steam_id_from_vanity_name(vanity_name) ⇒ Object



26
27
28
29
# File 'lib/stew/community/community_client.rb', line 26

def steam_id_from_vanity_name(vanity_name)
  response = XmlClientResponseProfile.new(@xml_client.get("/id/#{vanity_name}"))
  response.profile['steamID64'].to_i
end