Class: Steam::Profile
- Inherits:
-
Base
- Object
- Base
- Steam::Profile
show all
- Includes:
- HTTParty
- Defined in:
- lib/steam/profile.rb
Constant Summary
collapse
- CUSTOM_URL_URI =
'http://steamcommunity.com/id'
- PROFILE_URI =
'http://steamcommunity.com/profiles'
- LOGIN_URL =
'https://steamcommunity.com/'
- VISIBILITY_STATES =
[nil, :private, :friends, :public]
- DEFAULT_AVATAR_SIZE =
:icon
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#attribute_names, #attributes, #inspect
Instance Attribute Details
#friends ⇒ Object
Returns the value of attribute friends.
30
31
32
|
# File 'lib/steam/profile.rb', line 30
def friends
@friends
end
|
#id ⇒ Object
Returns the value of attribute id.
30
31
32
|
# File 'lib/steam/profile.rb', line 30
def id
@id
end
|
#steam_id ⇒ Object
Returns the value of attribute steam_id.
30
31
32
|
# File 'lib/steam/profile.rb', line 30
def steam_id
@steam_id
end
|
Class Method Details
.find(id, options = {}) ⇒ Object
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/steam/profile.rb', line 102
def find id, options = {}
if id.is_a? Hash
options = id
id = options.delete :id
base_uri PROFILE_URI
else
base_uri CUSTOM_URL_URI
end
data = get("/#{id}", options)['profile']
unless data.nil?
new(data)
else
raise ProfileNotFound.new(id)
end
end
|
.login(username, password) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/steam/profile.rb', line 120
def login username, password
request = HTTParty::Request.new Net::HTTP::Post, LOGIN_URL, :body => {:steamAccountName => username, :steamPassword => password, :action => 'doLogin'}, :format => :html
response = request.perform
cookies = HTTParty::CookieHash.new
cookies.add_cookies request.options[:headers]['Cookie'] if request.options[:headers] && request.options[:headers]['Cookie']
if cookies.has_key? :steamLogin
find(username, :cookies => cookies).tap do |profile|
profile.send :steam_login=, cookies[:steamLogin]
end
else
raise InvalidLogin.new("Invalid login for '#{username}'")
end
end
|
Instance Method Details
#==(profile) ⇒ Object
97
98
99
|
# File 'lib/steam/profile.rb', line 97
def == profile
steam_id == profile.steam_id
end
|
#avatar(size = DEFAULT_AVATAR_SIZE) ⇒ Object
60
61
62
63
64
65
66
|
# File 'lib/steam/profile.rb', line 60
def avatar size = DEFAULT_AVATAR_SIZE
unless respond_to? "avatar_#{size}"
size = DEFAULT_AVATAR_SIZE
end
send "avatar_#{size}"
end
|
#banned? ⇒ Boolean
40
41
42
|
# File 'lib/steam/profile.rb', line 40
def banned?
@vac_banned == '1'
end
|
#games(reload = false) ⇒ Object
72
73
74
75
76
77
78
|
# File 'lib/steam/profile.rb', line 72
def games reload = false
if reload or @games.nil?
@games = Game.find_all self, :cookies => cookies
end
@games
end
|
#limited_account? ⇒ Boolean
48
49
50
|
# File 'lib/steam/profile.rb', line 48
def limited_account?
@is_limited_account == '1'
end
|
#loaded? ⇒ Boolean
52
53
54
|
# File 'lib/steam/profile.rb', line 52
def loaded?
@loaded
end
|
#logged_in? ⇒ Boolean
32
33
34
|
# File 'lib/steam/profile.rb', line 32
def logged_in?
!@steam_login.nil?
end
|
#online? ⇒ Boolean
36
37
38
|
# File 'lib/steam/profile.rb', line 36
def online?
@online_state == 'online'
end
|
#private? ⇒ Boolean
44
45
46
|
# File 'lib/steam/profile.rb', line 44
def private?
@privacy_state == 'private'
end
|
#reload! ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/steam/profile.rb', line 80
def reload!
@loaded = false
profile = unless custom_url.blank?
self.class.find custom_url
else
self.class.find :id => steam_id
end
@built_attributes = false
build_attributes profile.attributes
end
|
#to_s ⇒ Object
93
94
95
|
# File 'lib/steam/profile.rb', line 93
def to_s
@id
end
|
#url ⇒ Object
68
69
70
|
# File 'lib/steam/profile.rb', line 68
def url
@custom_url ? "#{CUSTOM_URL_URI}/#{custom_url}" : "#{PROFILE_URI}/#{steam_id}"
end
|
#visibility ⇒ Object
56
57
58
|
# File 'lib/steam/profile.rb', line 56
def visibility
VISIBILITY_STATES[@visibility_state]
end
|