Class: SteamClient::Profile
- Inherits:
-
Object
- Object
- SteamClient::Profile
- Defined in:
- lib/steam-client/profile.rb
Instance Attribute Summary collapse
-
#avatarFull ⇒ Object
Returns the value of attribute avatarFull.
-
#avatarIcon ⇒ Object
Returns the value of attribute avatarIcon.
-
#avatarMedium ⇒ Object
Returns the value of attribute avatarMedium.
-
#customURL ⇒ Object
Returns the value of attribute customURL.
-
#friends ⇒ Object
Returns the value of attribute friends.
-
#games ⇒ Object
Returns the value of attribute games.
-
#hoursPlayed2Wk ⇒ Object
Returns the value of attribute hoursPlayed2Wk.
-
#location ⇒ Object
Returns the value of attribute location.
-
#onlineState ⇒ Object
Returns the value of attribute onlineState.
-
#realname ⇒ Object
Returns the value of attribute realname.
-
#steamID ⇒ Object
Returns the value of attribute steamID.
-
#steamID64 ⇒ Object
Returns the value of attribute steamID64.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(steamID64 = nil) ⇒ Profile
constructor
A new instance of Profile.
Constructor Details
#initialize(steamID64 = nil) ⇒ Profile
Returns a new instance of Profile.
24 25 26 27 28 |
# File 'lib/steam-client/profile.rb', line 24 def initialize(steamID64 = nil) self.steamID64 = steamID64 @friends = [] @games = [] end |
Instance Attribute Details
#avatarFull ⇒ Object
Returns the value of attribute avatarFull.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def avatarFull @avatarFull end |
#avatarIcon ⇒ Object
Returns the value of attribute avatarIcon.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def avatarIcon @avatarIcon end |
#avatarMedium ⇒ Object
Returns the value of attribute avatarMedium.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def avatarMedium @avatarMedium end |
#customURL ⇒ Object
Returns the value of attribute customURL.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def customURL @customURL end |
#friends ⇒ Object
Returns the value of attribute friends.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def friends @friends end |
#games ⇒ Object
Returns the value of attribute games.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def games @games end |
#hoursPlayed2Wk ⇒ Object
Returns the value of attribute hoursPlayed2Wk.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def hoursPlayed2Wk @hoursPlayed2Wk end |
#location ⇒ Object
Returns the value of attribute location.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def location @location end |
#onlineState ⇒ Object
Returns the value of attribute onlineState.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def onlineState @onlineState end |
#realname ⇒ Object
Returns the value of attribute realname.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def realname @realname end |
#steamID ⇒ Object
Returns the value of attribute steamID.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def steamID @steamID end |
#steamID64 ⇒ Object
Returns the value of attribute steamID64.
22 23 24 |
# File 'lib/steam-client/profile.rb', line 22 def steamID64 @steamID64 end |
Class Method Details
.from_json(json) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/steam-client/profile.rb', line 30 def self.from_json(json) p = JSON.parse(json) if p['response']['players'].empty? raise SteamClient::Error::ProfileNotFound end player = p['response']['players'].first profile = Profile.new profile.steamID = player['personaname'] profile.steamID64 =player['steamid'] profile.avatarIcon = player['avatar'] profile.avatarMedium = player['avatarmedium'] profile.avatarFull = player['avatarfull'] profile.customURL = player['profileurl'] profile.hoursPlayed2Wk = 0.0 profile.location = "#{player['loccityid'] || ''} #{player['locstatecode'] || ''} #{player['loccountrycode']}".strip profile.realname = player['realname'] profile.friends = [] profile.games = [] profile.onlineState = SteamClient::OnlineState::UNKNOWN return profile end |
.from_xml(xml) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/steam-client/profile.rb', line 56 def self.from_xml(xml) p = Crack::XML.parse(xml) if p.has_key? 'response' and p['response'].has_key? 'error' raise SteamClient::Error::ProfileNotFound end profile = Profile.new profile.steamID = p['profile']['steamID'] profile.steamID64 = p['profile']['steamID64'] profile.avatarIcon = p['profile']['avatarIcon'] profile.avatarMedium = p['profile']['avatarMedium'] profile.avatarFull = p['profile']['avatarFull'] profile.customURL = p['profile']['customURL'] profile.hoursPlayed2Wk = p['profile']['hoursPlayed2Wk'].to_f profile.location = p['profile']['location'] profile.realname = p['profile']['realname'] profile.friends = [] profile.games = [] case p['profile']['onlineState'] when 'online' profile.onlineState = SteamClient::OnlineState::ONLINE when 'offline' profile.onlineState = SteamClient::OnlineState::OFFLINE else profile.onlineState = SteamClient::OnlineState::UNKNOWN end return profile end |