Class: SteamClient::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/steam-client/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key = nil) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/steam-client/client.rb', line 9

def initialize(api_key = nil)
  @api_key = api_key
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/steam-client/client.rb', line 7

def api_key
  @api_key
end

Instance Method Details

#find_profile_by_id(id) ⇒ Object



19
20
21
22
23
# File 'lib/steam-client/client.rb', line 19

def find_profile_by_id(id)
	url = "http://steamcommunity.com/profiles/#{id}?xml=1"
	xml = get_with_retries url
	return Profile.from_xml(xml)
end

#find_profile_by_name(name) ⇒ Object



13
14
15
16
17
# File 'lib/steam-client/client.rb', line 13

def find_profile_by_name(name)
	url = "http://steamcommunity.com/id/#{name}?xml=1"
	xml = get_with_retries url
	return Profile.from_xml(xml)
end

#get_friends_from_profile(profile) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/steam-client/client.rb', line 25

def get_friends_from_profile(profile)
    url = "http://steamcommunity.com/profiles/#{profile.steamID64}/friends?xml=1"
    xml = get_with_retries url
    hFriends = Crack::XML.parse xml
    friends = []
    hFriends['friendsList']['friends']['friend'].each do |friendID|
        friends << Profile.new(friendID)
    end
    profile.friends = friends
    return friends
end

#get_games_from_profile(profile) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/steam-client/client.rb', line 37

def get_games_from_profile(profile)
    url = "http://steamcommunity.com/profiles/#{profile.steamID64}/games\?xml\=1"
    xml = get_with_retries url
    hGames = Crack::XML.parse xml
    games = []
    hGames['gamesList']['games']['game'].each do |game|
        games << Game.new(game)
    end
    profile.games = games
    return games
end

#get_with_retries(url, retries = 10) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/steam-client/client.rb', line 49

def get_with_retries(url, retries = 10)
    attempt = 0
    while attempt < retries
        begin
            resp = RestClient.get url
            return resp
        rescue RestClient::ServiceUnavailable
            attempt += 1
        end
    end

    throw new RestClient::ServiceUnavailable
end