steam_community 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +19 -0
- data/README.rdoc +27 -0
- data/lib/steam.rb +10 -0
- data/lib/steam/achievement.rb +42 -0
- data/lib/steam/base.rb +59 -0
- data/lib/steam/game.rb +53 -0
- data/lib/steam/profile.rb +168 -0
- data/rails/init.rb +1 -0
- metadata +104 -0
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (C) 2011 by Marty Zalega [http://github.com/evilmarty]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
==Steam
|
2
|
+
|
3
|
+
A ruby library to access the Steam Community. Lookup player profile information such as games, achievements and friends.
|
4
|
+
|
5
|
+
==Installation
|
6
|
+
|
7
|
+
git clone git://github.com/evilmarty/steam.git
|
8
|
+
|
9
|
+
==Usage
|
10
|
+
|
11
|
+
To get player by name:
|
12
|
+
|
13
|
+
player = Steam::Profile.find 'player name'
|
14
|
+
|
15
|
+
Or if you know the steam id of the player
|
16
|
+
|
17
|
+
player = Steam::Profile.find :id => 1234567890
|
18
|
+
|
19
|
+
|
20
|
+
==To Do
|
21
|
+
|
22
|
+
* Make into gem.
|
23
|
+
* Support logging into profile to fetch private information.
|
24
|
+
* Write tests :-p
|
25
|
+
|
26
|
+
|
27
|
+
This library is in no way affiliated with Valve Software or Steam.
|
data/lib/steam.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'active_support/inflector'
|
3
|
+
require 'httparty'
|
4
|
+
|
5
|
+
module Steam
|
6
|
+
autoload :Base, File.join(File.dirname(__FILE__), 'steam', 'base.rb')
|
7
|
+
autoload :Profile, File.join(File.dirname(__FILE__), 'steam', 'profile.rb')
|
8
|
+
autoload :Game, File.join(File.dirname(__FILE__), 'steam', 'game.rb')
|
9
|
+
autoload :Achievement, File.join(File.dirname(__FILE__), 'steam', 'achievement.rb')
|
10
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Steam
|
2
|
+
class Achievement < Base
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'http://steamcommunity.com'
|
5
|
+
default_params :xml => 1
|
6
|
+
format :xml
|
7
|
+
|
8
|
+
attr_reader :game
|
9
|
+
|
10
|
+
def completed?
|
11
|
+
@closed == '1'
|
12
|
+
end
|
13
|
+
|
14
|
+
def unlocked_at
|
15
|
+
Time.at @unlock_timestamp if @unlock_timestamp
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
name
|
20
|
+
end
|
21
|
+
|
22
|
+
class << self
|
23
|
+
def find_all game, options = {}
|
24
|
+
data = get game.stats_link, options
|
25
|
+
|
26
|
+
if data['playerstats'] && data['playerstats']['achievements'] && data['playerstats']['achievements']['achievement']
|
27
|
+
data['playerstats']['achievements']['achievement'].map do |achievement_data|
|
28
|
+
new game, achievement_data
|
29
|
+
end
|
30
|
+
else
|
31
|
+
[]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
def initialize game, data
|
38
|
+
@game = game
|
39
|
+
build_attributes data
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/steam/base.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Steam
|
2
|
+
class Base
|
3
|
+
def attribute_names
|
4
|
+
@attribute_names
|
5
|
+
end
|
6
|
+
|
7
|
+
def attributes
|
8
|
+
attribute_names.inject({}) do |attributes, name|
|
9
|
+
attributes.merge name => instance_variable_get("@#{name}")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def inspect
|
14
|
+
inspected_attributes = if @built_attributes
|
15
|
+
attributes.map do |key, value|
|
16
|
+
" #{key}=#{value.inspect}"
|
17
|
+
end.join
|
18
|
+
else
|
19
|
+
''
|
20
|
+
end
|
21
|
+
|
22
|
+
"#<#{self.class.name}:#{__id__}#{inspected_attributes}>"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def build_attributes attributes
|
27
|
+
return if @built_attributes
|
28
|
+
|
29
|
+
@attribute_names ||= []
|
30
|
+
|
31
|
+
attributes.each_pair do |key, value|
|
32
|
+
next if value.is_a?(Hash) or value.is_a?(Array)
|
33
|
+
|
34
|
+
key = key.underscore
|
35
|
+
|
36
|
+
@attribute_names << key unless @attribute_names.include? key
|
37
|
+
set_attribute key, value
|
38
|
+
|
39
|
+
unless respond_to? key
|
40
|
+
instance_eval <<-EOT
|
41
|
+
def #{key}
|
42
|
+
@#{key}
|
43
|
+
end
|
44
|
+
EOT
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
@built_attributes = true
|
49
|
+
end
|
50
|
+
|
51
|
+
def set_attribute name, value
|
52
|
+
if respond_to? "#{name}="
|
53
|
+
send "#{name}=", value
|
54
|
+
elsif @attribute_names.include? name
|
55
|
+
instance_variable_set "@#{name}", value
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/steam/game.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Steam
|
2
|
+
class Game < Base
|
3
|
+
include HTTParty
|
4
|
+
base_uri 'http://steamcommunity.com'
|
5
|
+
default_params :xml => 1
|
6
|
+
format :xml
|
7
|
+
|
8
|
+
attr_reader :profile, :id, :name
|
9
|
+
|
10
|
+
def has_achievements?
|
11
|
+
!@stats_link.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def achievements reload = false
|
15
|
+
return [] unless has_achievements?
|
16
|
+
|
17
|
+
if reload or @achievements.nil?
|
18
|
+
@achievements = Achievement.find_all self, @request_options
|
19
|
+
end
|
20
|
+
|
21
|
+
@achievements
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_s
|
25
|
+
name
|
26
|
+
end
|
27
|
+
|
28
|
+
class << self
|
29
|
+
def find_all profile, options = {}
|
30
|
+
base_uri profile.url
|
31
|
+
data = get '/games', options
|
32
|
+
|
33
|
+
if data['gamesList'] && data['gamesList']['games'] && data['gamesList']['games']['game']
|
34
|
+
data['gamesList']['games']['game'].map do |game_data|
|
35
|
+
new profile, game_data, options
|
36
|
+
end
|
37
|
+
else
|
38
|
+
[]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
def initialize profile, data, request_options
|
45
|
+
@profile = profile
|
46
|
+
@id = data.delete 'appID'
|
47
|
+
@name = data.delete 'name'
|
48
|
+
@request_options = request_options
|
49
|
+
|
50
|
+
build_attributes data
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
module Steam
|
2
|
+
class InvalidLogin < Exception; end
|
3
|
+
|
4
|
+
class ProfileNotFound < Exception
|
5
|
+
attr_reader :id
|
6
|
+
|
7
|
+
def initialize id
|
8
|
+
@id = id
|
9
|
+
@message = "Steam profile for '#{@id}' not found"
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
@message
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class Profile < Base
|
18
|
+
CUSTOM_URL_URI = 'http://steamcommunity.com/id'
|
19
|
+
PROFILE_URI = 'http://steamcommunity.com/profiles'
|
20
|
+
LOGIN_URL = 'https://steamcommunity.com/'
|
21
|
+
|
22
|
+
VISIBILITY_STATES = [nil, :private, :friends, :public]
|
23
|
+
DEFAULT_AVATAR_SIZE = :icon
|
24
|
+
|
25
|
+
include HTTParty
|
26
|
+
base_uri CUSTOM_URL_URI
|
27
|
+
default_params :xml => 1
|
28
|
+
format :xml
|
29
|
+
|
30
|
+
attr_reader :id, :steam_id, :friends
|
31
|
+
|
32
|
+
def logged_in?
|
33
|
+
!@steam_login.nil?
|
34
|
+
end
|
35
|
+
|
36
|
+
def online?
|
37
|
+
@online_state == 'online'
|
38
|
+
end
|
39
|
+
|
40
|
+
def banned?
|
41
|
+
@vac_banned == '1'
|
42
|
+
end
|
43
|
+
|
44
|
+
def private?
|
45
|
+
@privacy_state == 'private'
|
46
|
+
end
|
47
|
+
|
48
|
+
def limited_account?
|
49
|
+
@is_limited_account == '1'
|
50
|
+
end
|
51
|
+
|
52
|
+
def loaded?
|
53
|
+
@loaded
|
54
|
+
end
|
55
|
+
|
56
|
+
def visibility
|
57
|
+
VISIBILITY_STATES[@visibility_state]
|
58
|
+
end
|
59
|
+
|
60
|
+
def avatar size = DEFAULT_AVATAR_SIZE
|
61
|
+
unless respond_to? "avatar_#{size}"
|
62
|
+
size = DEFAULT_AVATAR_SIZE
|
63
|
+
end
|
64
|
+
|
65
|
+
send "avatar_#{size}"
|
66
|
+
end
|
67
|
+
|
68
|
+
def url
|
69
|
+
@custom_url ? "#{CUSTOM_URL_URI}/#{custom_url}" : "#{PROFILE_URI}/#{steam_id}"
|
70
|
+
end
|
71
|
+
|
72
|
+
def games reload = false
|
73
|
+
if reload or @games.nil?
|
74
|
+
@games = Game.find_all self, :cookies => cookies
|
75
|
+
end
|
76
|
+
|
77
|
+
@games
|
78
|
+
end
|
79
|
+
|
80
|
+
def reload!
|
81
|
+
@loaded = false
|
82
|
+
|
83
|
+
profile = unless custom_url.blank?
|
84
|
+
self.class.find custom_url
|
85
|
+
else
|
86
|
+
self.class.find :id => steam_id
|
87
|
+
end
|
88
|
+
|
89
|
+
@built_attributes = false
|
90
|
+
build_attributes profile.attributes
|
91
|
+
end
|
92
|
+
|
93
|
+
def to_s
|
94
|
+
@id
|
95
|
+
end
|
96
|
+
|
97
|
+
def == profile
|
98
|
+
steam_id == profile.steam_id
|
99
|
+
end
|
100
|
+
|
101
|
+
class << self
|
102
|
+
def find id, options = {}
|
103
|
+
if id.is_a? Hash
|
104
|
+
options = id
|
105
|
+
id = options.delete :id
|
106
|
+
base_uri PROFILE_URI
|
107
|
+
else
|
108
|
+
base_uri CUSTOM_URL_URI
|
109
|
+
end
|
110
|
+
|
111
|
+
data = get("/#{id}", options)['profile']
|
112
|
+
|
113
|
+
unless data.nil?
|
114
|
+
new(data)
|
115
|
+
else
|
116
|
+
raise ProfileNotFound.new(id)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def login username, password
|
121
|
+
request = HTTParty::Request.new Net::HTTP::Post, LOGIN_URL, :body => {:steamAccountName => username, :steamPassword => password, :action => 'doLogin'}, :format => :html
|
122
|
+
response = request.perform
|
123
|
+
|
124
|
+
cookies = HTTParty::CookieHash.new
|
125
|
+
cookies.add_cookies request.options[:headers]['Cookie'] if request.options[:headers] && request.options[:headers]['Cookie']
|
126
|
+
|
127
|
+
if cookies.has_key? :steamLogin
|
128
|
+
find(username, :cookies => cookies).tap do |profile|
|
129
|
+
profile.send :steam_login=, cookies[:steamLogin]
|
130
|
+
end
|
131
|
+
else
|
132
|
+
raise InvalidLogin.new("Invalid login for '#{username}'")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
private
|
138
|
+
def initialize data
|
139
|
+
@id = data.delete 'steamID'
|
140
|
+
@steam_id = data.delete 'steamID64'
|
141
|
+
|
142
|
+
build_attributes data
|
143
|
+
|
144
|
+
@friends = []
|
145
|
+
if !data['friends'].nil? and !data['friends']['friend'].nil?
|
146
|
+
data['friends']['friend'].each do |friend_data|
|
147
|
+
@friends << self.class.new(friend_data).tap do |friend|
|
148
|
+
friend.send :loaded=, false
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
@loaded = true
|
154
|
+
end
|
155
|
+
|
156
|
+
def loaded= value
|
157
|
+
@loaded = value
|
158
|
+
end
|
159
|
+
|
160
|
+
def steam_login= value
|
161
|
+
@steam_login = value
|
162
|
+
end
|
163
|
+
|
164
|
+
def cookies
|
165
|
+
@steam_login ? {'steamLogin' => @steam_login} : {}
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join('..', 'lib', 'steam.rb')
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: steam_community
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 9
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: "0.1"
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Marty Zalega
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-05 00:00:00 +10:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: active_support
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 19
|
29
|
+
segments:
|
30
|
+
- 2
|
31
|
+
- 3
|
32
|
+
- 8
|
33
|
+
version: 2.3.8
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: httparty
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 5
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
- 6
|
48
|
+
- 1
|
49
|
+
version: 0.6.1
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
52
|
+
description: Lookup steam player profile information such as games, achievements and friends.
|
53
|
+
email: evil.marty@gmail.com
|
54
|
+
executables: []
|
55
|
+
|
56
|
+
extensions: []
|
57
|
+
|
58
|
+
extra_rdoc_files:
|
59
|
+
- README.rdoc
|
60
|
+
files:
|
61
|
+
- lib/steam/achievement.rb
|
62
|
+
- lib/steam/base.rb
|
63
|
+
- lib/steam/game.rb
|
64
|
+
- lib/steam/profile.rb
|
65
|
+
- lib/steam.rb
|
66
|
+
- LICENSE
|
67
|
+
- rails/init.rb
|
68
|
+
- README.rdoc
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: https://github.com/evilmarty/steam
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.4.1
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Lookup steam player profile information such as games, achievements and friends.
|
103
|
+
test_files: []
|
104
|
+
|