steam_web_api 0.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.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rspec +2 -0
- data/.travis.yml +15 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +22 -0
- data/README.html +1134 -0
- data/README.md +356 -0
- data/Rakefile +11 -0
- data/lib/steam_web_api/base.rb +39 -0
- data/lib/steam_web_api/configuration.rb +9 -0
- data/lib/steam_web_api/game.rb +37 -0
- data/lib/steam_web_api/player.rb +108 -0
- data/lib/steam_web_api/version.rb +3 -0
- data/lib/steam_web_api.rb +29 -0
- data/spec/fixtures/vcr/game_achievement_percentages.yml +624 -0
- data/spec/fixtures/vcr/game_achievement_percentages_error.yml +37 -0
- data/spec/fixtures/vcr/game_news_error.yml +37 -0
- data/spec/fixtures/vcr/game_news_success.yml +96 -0
- data/spec/fixtures/vcr/game_schema.yml +3538 -0
- data/spec/fixtures/vcr/player_achievements.yml +91 -0
- data/spec/fixtures/vcr/player_achievements_empty.yml +35 -0
- data/spec/fixtures/vcr/player_bans.yml +38 -0
- data/spec/fixtures/vcr/player_bans_error.yml +37 -0
- data/spec/fixtures/vcr/player_friends.yml +51 -0
- data/spec/fixtures/vcr/player_friends_error.yml +44 -0
- data/spec/fixtures/vcr/player_owned_games.yml +82 -0
- data/spec/fixtures/vcr/player_owned_games_appinfo.yml +291 -0
- data/spec/fixtures/vcr/player_playing_shared_game.yml +36 -0
- data/spec/fixtures/vcr/player_playing_shared_game_error.yml +44 -0
- data/spec/fixtures/vcr/player_recently_played_games.yml +48 -0
- data/spec/fixtures/vcr/player_recently_played_games_error.yml +44 -0
- data/spec/fixtures/vcr/player_recently_played_games_with_count.yml +42 -0
- data/spec/fixtures/vcr/player_single_bans.yml +36 -0
- data/spec/fixtures/vcr/player_single_bans_error.yml +37 -0
- data/spec/fixtures/vcr/player_single_summary.yml +43 -0
- data/spec/fixtures/vcr/player_single_summary_error.yml +37 -0
- data/spec/fixtures/vcr/player_summary.yml +51 -0
- data/spec/fixtures/vcr/player_summary_error.yml +37 -0
- data/spec/fixtures/vcr/stats_for_game.yml +321 -0
- data/spec/fixtures/vcr/stats_for_game_empty.yml +37 -0
- data/spec/spec_helper.rb +45 -0
- data/spec/steam_web_api/base_spec.rb +94 -0
- data/spec/steam_web_api/configuration_spec.rb +16 -0
- data/spec/steam_web_api/game_spec.rb +137 -0
- data/spec/steam_web_api/player_spec.rb +362 -0
- data/spec/steam_web_api_spec.rb +18 -0
- data/steam_web_api.gemspec +30 -0
- metadata +235 -0
data/README.md
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# SteamWebApi
|
|
2
|
+
|
|
3
|
+
[](https://api.travis-ci.org/Olgagr/steam-web-api.svg?branch=master) [](https://codeclimate.com/github/Olgagr/steam-web-api) [](https://codeclimate.com/github/Olgagr/steam-web-api)
|
|
4
|
+
|
|
5
|
+
This is a gem that makes trivial interacting with the Steam Web API. It supports all methods listed here: https://developer.valvesoftware.com/wiki/Steam_Web_API and [one more](#get-list-of-all-games).
|
|
6
|
+
|
|
7
|
+
## Supported Ruby version
|
|
8
|
+
|
|
9
|
+
Gem supports Ruby: 2.0, 2.1, 2.2
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
Add this line to your application's Gemfile:
|
|
14
|
+
|
|
15
|
+
```ruby
|
|
16
|
+
gem 'steam_web_api', git: 'https://github.com/Olgagr/steam-web-api.git'
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
### Configuration
|
|
26
|
+
|
|
27
|
+
Some Steam Web API methods return publicly accessible data and do not require authorization when called. Other methods may require clients to register for an API key and pass that in using the key parameter. There are also methods that return sensitive data or perform a protected action and require special access permissions. To retrieve API key for your application, you'll need log in to your Steam account and fill [this form](http://steamcommunity.com/dev/apikey)
|
|
28
|
+
|
|
29
|
+
When you have your API key, you can configure the gem:
|
|
30
|
+
|
|
31
|
+
```ruby
|
|
32
|
+
# for Rails, you can put this code in initializer: config/initializers/steam_web_api.rb
|
|
33
|
+
SteamWebApi.configure do |config|
|
|
34
|
+
config.api_key = 'your api key'
|
|
35
|
+
end
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
This is better not to include API key as plain text in you repository. For better solution, please check [dotenv gem](https://github.com/bkeepers/dotenv).
|
|
39
|
+
|
|
40
|
+
### Player
|
|
41
|
+
|
|
42
|
+
#### Get list of owned games
|
|
43
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetOwnedGames_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
44
|
+
|
|
45
|
+
```ruby
|
|
46
|
+
# player_steam_id - this is a Steam identifier for user
|
|
47
|
+
player = SteamWebApi::Player(player_steam_id)
|
|
48
|
+
data = player.owned_games
|
|
49
|
+
data.count # how many games user posses (integer)
|
|
50
|
+
data.games # list of user's games
|
|
51
|
+
data.success # boolean value indicates if response was succesful
|
|
52
|
+
|
|
53
|
+
# game datails
|
|
54
|
+
game = data.games.first
|
|
55
|
+
game['appid'] # identifier for game (integer)
|
|
56
|
+
game['playtime_forever'] # total playtime for game (integer)
|
|
57
|
+
|
|
58
|
+
# additional options
|
|
59
|
+
# 1. include_played_free_games - include free games in results
|
|
60
|
+
# 2. include_appinfo - include game name and logo information in the output. The default is to return appids only.
|
|
61
|
+
data = player.owned_games(include_played_free_games: true, include_appinfo: true)
|
|
62
|
+
|
|
63
|
+
# if include_appinfo is set to true
|
|
64
|
+
game = data.games.first
|
|
65
|
+
game['name'] # game's name
|
|
66
|
+
game['playtime_2weeks'] # total number of minutes played in the last 2 weeks
|
|
67
|
+
game['img_icon_url'] # filename of game's icon
|
|
68
|
+
game['img_logo_url'] # filename of game logo
|
|
69
|
+
game['has_community_visible_stats'] # indicates there is a stats page with achievements or other game stats available for this game
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### Get user stats for game
|
|
73
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetUserStatsForGame_.28v0002.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
74
|
+
|
|
75
|
+
```ruby
|
|
76
|
+
player = SteamWebApi::Player(player_steam_id)
|
|
77
|
+
data = player.stats_for_game(game_id)
|
|
78
|
+
|
|
79
|
+
data.steam_id # user steam identifier
|
|
80
|
+
data.game_name # game name
|
|
81
|
+
data.achievements # list of achievements
|
|
82
|
+
data.stats # list of stats
|
|
83
|
+
data.success # boolean value indicates if response was succesful. If false, probably the game doesn't have stats and Steam returns 400 status
|
|
84
|
+
|
|
85
|
+
achievement = data.achievements.first
|
|
86
|
+
achievement['name'] # achievement identifier
|
|
87
|
+
achievement['achieved'] # integer (0 or 1)
|
|
88
|
+
|
|
89
|
+
stat = data.stats.first
|
|
90
|
+
stat['name']
|
|
91
|
+
stat['value'] # integer
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
#### Get user achievements for game
|
|
95
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerAchievements_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
96
|
+
|
|
97
|
+
```ruby
|
|
98
|
+
player = SteamWebApi::Player(player_steam_id)
|
|
99
|
+
data = player.achievements(game_id)
|
|
100
|
+
|
|
101
|
+
data.steam_id # user steam identifier
|
|
102
|
+
data.game_name # game name
|
|
103
|
+
data.achievements # list of achievements
|
|
104
|
+
data.success # boolean value indicates if response was succesful. If false, probably the game doesn't have stats and Steam returns 400 status
|
|
105
|
+
|
|
106
|
+
achievement = data.achievements.first
|
|
107
|
+
achievement['apiname'] # achievement name
|
|
108
|
+
achievement['achieved'] # integer (0 or 1)
|
|
109
|
+
|
|
110
|
+
# additional options
|
|
111
|
+
# 1. l - Language. If specified, it will return language data (name, description) for the requested language.
|
|
112
|
+
data = player.achievements(game_id, l: 'en')
|
|
113
|
+
achievement = data.achievements.first
|
|
114
|
+
achievement['name'] # achievement name
|
|
115
|
+
achievement['description'] # achievement description
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Get accounts summaries for list of players
|
|
119
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
120
|
+
|
|
121
|
+
```ruby
|
|
122
|
+
data = SteamWebApi::Player.summary(player.steam_id, player_2.steam_id)
|
|
123
|
+
data.players # list of account summeries
|
|
124
|
+
data.success # boolean value indicates if response was succesful
|
|
125
|
+
|
|
126
|
+
first_player = data.players.first
|
|
127
|
+
first_player['steamid']
|
|
128
|
+
first_player['communityvisibilitystate']
|
|
129
|
+
first_player['profilestate']
|
|
130
|
+
first_player['personaname']
|
|
131
|
+
first_player['lastlogoff']
|
|
132
|
+
first_player['profileurl']
|
|
133
|
+
first_player['avatar']
|
|
134
|
+
first_player['avatarmedium']
|
|
135
|
+
first_player['avatarfull']
|
|
136
|
+
first_player['personastate']
|
|
137
|
+
first_player['realname']
|
|
138
|
+
first_player['primaryclanid']
|
|
139
|
+
first_player['timecreated']
|
|
140
|
+
first_player['personastateflags']
|
|
141
|
+
first_player['gameextrainfo']
|
|
142
|
+
first_player['gameid']
|
|
143
|
+
first_player['loccountrycode']
|
|
144
|
+
first_player['locstatecode']
|
|
145
|
+
first_player['loccityid']
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Get account summary for single player
|
|
149
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerSummaries_.28v0002.29). This is just more convinient method to get account summary if you already have player instance. To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
150
|
+
|
|
151
|
+
```ruby
|
|
152
|
+
player = SteamWebApi::Player.new(steam_id)
|
|
153
|
+
data = player.summary
|
|
154
|
+
data.profile # account summery
|
|
155
|
+
data.success # boolean value indicates if response was succesful
|
|
156
|
+
|
|
157
|
+
data.profile['steamid']
|
|
158
|
+
data.profile['communityvisibilitystate']
|
|
159
|
+
data.profile['profilestate']
|
|
160
|
+
data.profile['personaname']
|
|
161
|
+
data.profile['lastlogoff']
|
|
162
|
+
data.profile['profileurl']
|
|
163
|
+
data.profile['avatar']
|
|
164
|
+
data.profile['avatarmedium']
|
|
165
|
+
data.profile['avatarfull']
|
|
166
|
+
data.profile['personastate']
|
|
167
|
+
data.profile['realname']
|
|
168
|
+
data.profile['primaryclanid']
|
|
169
|
+
data.profile['timecreated']
|
|
170
|
+
data.profile['personastateflags']
|
|
171
|
+
data.profile['gameextrainfo']
|
|
172
|
+
data.profile['gameid']
|
|
173
|
+
data.profile['loccountrycode']
|
|
174
|
+
data.profile['locstatecode']
|
|
175
|
+
data.profile['loccityid']
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### Get player friends list
|
|
179
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetFriendList_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
180
|
+
|
|
181
|
+
```ruby
|
|
182
|
+
player = SteamWebApi::Player.new(steam_id)
|
|
183
|
+
data = player.friends
|
|
184
|
+
data.friends # list of friends
|
|
185
|
+
data.success # boolean value indicates if response was succesful
|
|
186
|
+
|
|
187
|
+
friend = data.friends.first
|
|
188
|
+
friend['steamid']
|
|
189
|
+
friend['relationship']
|
|
190
|
+
friend['friend_since'] # integer
|
|
191
|
+
|
|
192
|
+
# additional options
|
|
193
|
+
# relationship: all/friend. Default is 'all'
|
|
194
|
+
player.friends('friend')
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**Get list of recently played games** (https://developer.valvesoftware.com/wiki/Steam_Web_API#GetRecentlyPlayedGames_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
198
|
+
|
|
199
|
+
```ruby
|
|
200
|
+
player = SteamWebApi::Player.new(steam_id)
|
|
201
|
+
data = player.recently_played_games
|
|
202
|
+
data.games # list of games
|
|
203
|
+
data.total_count
|
|
204
|
+
data.success # boolean value indicates if response was succesful
|
|
205
|
+
|
|
206
|
+
game = data.games.first
|
|
207
|
+
game['appid']
|
|
208
|
+
game['name']
|
|
209
|
+
game['playtime_2weeks'] # integer, number of minutes
|
|
210
|
+
game['playtime_forever'] # integer, number of minutes
|
|
211
|
+
game['img_icon_url']
|
|
212
|
+
game['img_logo_url']
|
|
213
|
+
|
|
214
|
+
# additional options
|
|
215
|
+
# count: it limits returned number of games. It's nil by default
|
|
216
|
+
player.recently_played_games(2)
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
**Check if player is playing shared game** (https://developer.valvesoftware.com/wiki/Steam_Web_API#IsPlayingSharedGame_.28v0001.29). To make this API call, you need to have API key for your app and steam identifier of the Steam user.
|
|
220
|
+
|
|
221
|
+
```ruby
|
|
222
|
+
player = SteamWebApi::Player.new(steam_id)
|
|
223
|
+
data = player.playing_shared_game(game_id)
|
|
224
|
+
data.lender_steamid # string, steam id of game owner
|
|
225
|
+
data.success # boolean value indicates if response was succesful
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
#### Get list of bans for list of players
|
|
229
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerBans_.28v1.29). To make this API call, you need to have API key.
|
|
230
|
+
|
|
231
|
+
```ruby
|
|
232
|
+
data = SteamWebApi::Player.bans(player_1.steam_id, player_2.steam_id)
|
|
233
|
+
data.players # list of bans info for given players
|
|
234
|
+
data.success # boolean value indicates if response was succesful
|
|
235
|
+
|
|
236
|
+
bans = data.players.first
|
|
237
|
+
bans['SteamId']
|
|
238
|
+
bans['CommunityBanned'] # boolean
|
|
239
|
+
bans['VACBanned'] # boolean
|
|
240
|
+
bans['NumberOfVACBans'] # integer
|
|
241
|
+
bans['DaysSinceLastBan'] # integer
|
|
242
|
+
bans['EconomyBan'] # string, for example 'none'
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
#### Get list of bans for single player
|
|
246
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetPlayerBans_.28v1.29). This is just more convinient method to get player bans if you already have player instance. To make this API call, you need to have API key.
|
|
247
|
+
|
|
248
|
+
```ruby
|
|
249
|
+
player = SteamWebApi::Player.new(steam_id)
|
|
250
|
+
data = player.bans
|
|
251
|
+
data.success # boolean value indicates if response was succesful
|
|
252
|
+
data.bans['SteamId']
|
|
253
|
+
data.bans['CommunityBanned'] # boolean
|
|
254
|
+
data.bans['VACBanned'] # boolean
|
|
255
|
+
data.bans['NumberOfVACBans'] # integer
|
|
256
|
+
data.bans['DaysSinceLastBan'] # integer
|
|
257
|
+
data.bans['EconomyBan'] # string, for example 'none'
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
### Game
|
|
263
|
+
|
|
264
|
+
#### Get list of all games
|
|
265
|
+
This end-point is not described in official documentation.
|
|
266
|
+
|
|
267
|
+
```ruby
|
|
268
|
+
data = SteamWebApi::Game.all
|
|
269
|
+
data.games
|
|
270
|
+
data.success # boolean value indicates if response was succesful
|
|
271
|
+
|
|
272
|
+
game = data.games.first
|
|
273
|
+
game['appid'] # game id
|
|
274
|
+
game['name']
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### Get game schema
|
|
278
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetSchemaForGame_.28v2.29). To make this API call, you need to have API key for your app.
|
|
279
|
+
|
|
280
|
+
```ruby
|
|
281
|
+
game = SteamWebApi::Game(game_id)
|
|
282
|
+
schema = game.schema
|
|
283
|
+
|
|
284
|
+
schema.name # game name
|
|
285
|
+
schema.version # game version
|
|
286
|
+
schema.achievements # lists of achievements
|
|
287
|
+
schema.stats # list of stats
|
|
288
|
+
schema.success # boolean value indicates if response was succesful
|
|
289
|
+
|
|
290
|
+
achievement = schema.achievements.first
|
|
291
|
+
achievement['name']
|
|
292
|
+
achievement['defaultvalue']
|
|
293
|
+
achievement['displayName']
|
|
294
|
+
achievement['hidden'] # integer
|
|
295
|
+
achievement['description']
|
|
296
|
+
achievement['icon']
|
|
297
|
+
achievement['icongray']
|
|
298
|
+
|
|
299
|
+
stats = schema.stats.first
|
|
300
|
+
stats['name']
|
|
301
|
+
stats['defaultvalue']
|
|
302
|
+
stats['displayName']
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### Get list of global game achievements in percentage
|
|
306
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetGlobalAchievementPercentagesForApp_.28v0002.29)
|
|
307
|
+
|
|
308
|
+
```ruby
|
|
309
|
+
game = SteamWebApi::Game(game_id)
|
|
310
|
+
data = game.achievement_percentages
|
|
311
|
+
|
|
312
|
+
data.achievements # list of achievements
|
|
313
|
+
data.success # boolean value indicates if response was succesful
|
|
314
|
+
|
|
315
|
+
achievement = data.achievements.first
|
|
316
|
+
achievement['name']
|
|
317
|
+
achievement['percent']
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
#### Get list of news
|
|
321
|
+
(https://developer.valvesoftware.com/wiki/Steam_Web_API#GetNewsForApp_.28v0002.29)
|
|
322
|
+
|
|
323
|
+
```ruby
|
|
324
|
+
game = SteamWebApi::Game(game_id)
|
|
325
|
+
news = game.news
|
|
326
|
+
|
|
327
|
+
news.app_id # game id
|
|
328
|
+
news.news_items # news list
|
|
329
|
+
news.success # boolean value indicates if response was succesful
|
|
330
|
+
|
|
331
|
+
first_news = news.news_items.first
|
|
332
|
+
first_news['gid'] # string
|
|
333
|
+
first_news['title']
|
|
334
|
+
first_news['url']
|
|
335
|
+
first_news['is_external_url']
|
|
336
|
+
first_news['author']
|
|
337
|
+
first_news['contents']
|
|
338
|
+
first_news['feedlabel']
|
|
339
|
+
first_news['date']
|
|
340
|
+
first_news['feedname']
|
|
341
|
+
|
|
342
|
+
# additional options
|
|
343
|
+
# 1. count - default 3, how many news should be retured
|
|
344
|
+
# 2. max_length - default 300, how many characters news content should contain
|
|
345
|
+
data = game.news(count: 10, max_length: 1000)
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
## Contributing
|
|
351
|
+
|
|
352
|
+
1. Fork it ( https://github.com/[my-github-username]/steam_web_api/fork )
|
|
353
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
354
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
355
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
356
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require "faraday"
|
|
2
|
+
|
|
3
|
+
module SteamWebApi
|
|
4
|
+
|
|
5
|
+
class Base
|
|
6
|
+
|
|
7
|
+
BASE_URI = 'http://api.steampowered.com'
|
|
8
|
+
|
|
9
|
+
attr_accessor :response
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
|
|
13
|
+
def build_response(response, main_key)
|
|
14
|
+
if response.status == 200
|
|
15
|
+
parsed_response = JSON.parse(response.body)[main_key]
|
|
16
|
+
OpenStruct.new yield(parsed_response).merge!(success: true)
|
|
17
|
+
else
|
|
18
|
+
OpenStruct.new(success: false)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def get(path, search_params={})
|
|
25
|
+
Faraday.get("#{BASE_URI}#{path}", search_params.merge!(format: :json))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def parse_response
|
|
29
|
+
JSON.parse(response.body)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def build_response(main_key, &block)
|
|
33
|
+
self.class.build_response(response, main_key, &block)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
module SteamWebApi
|
|
2
|
+
|
|
3
|
+
class Game < Base
|
|
4
|
+
|
|
5
|
+
attr_reader :game_id
|
|
6
|
+
|
|
7
|
+
def initialize(game_id)
|
|
8
|
+
@game_id = game_id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
|
|
13
|
+
def all
|
|
14
|
+
response = Faraday.get('http://api.steampowered.com/ISteamApps/GetAppList/v0002/')
|
|
15
|
+
build_response(response, 'applist') { |data| { games: data['apps'] } }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def schema
|
|
21
|
+
@response = get('/ISteamUserStats/GetSchemaForGame/v2', appid: game_id, key: SteamWebApi.config.api_key)
|
|
22
|
+
build_response('game') { |data| { name: data['gameName'], version: data['gameVersion'], achievements: data['availableGameStats']['achievements'], stats: data['availableGameStats']['stats'] } }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def achievement_percentages
|
|
26
|
+
@response = get('/ISteamUserStats/GetGlobalAchievementPercentagesForApp/v0002', gameid: game_id)
|
|
27
|
+
build_response('achievementpercentages') { |data| { achievements: data['achievements'] } }
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def news(count: 3, max_length: 300)
|
|
31
|
+
@response = get('/ISteamNews/GetNewsForApp/v0002', appid: game_id, count: count, maxlength: max_length)
|
|
32
|
+
build_response('appnews') { |data|{ app_id: data['appid'], news_items: data['newsitems'] } }
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
module SteamWebApi
|
|
2
|
+
|
|
3
|
+
class Player < Base
|
|
4
|
+
|
|
5
|
+
attr_accessor :steam_id
|
|
6
|
+
|
|
7
|
+
def initialize(steam_id)
|
|
8
|
+
@steam_id = steam_id
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class << self
|
|
12
|
+
|
|
13
|
+
def summary(*ids)
|
|
14
|
+
response = Faraday.get('http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002', options(ids))
|
|
15
|
+
build_response(response, 'response') { |data| { players: data['players'] } }
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def bans(*ids)
|
|
19
|
+
response = Faraday.get('http://api.steampowered.com/ISteamUser/GetPlayerBans/v1', options(ids))
|
|
20
|
+
build_response(response, 'players') { |data| { players: data } }
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def options(*ids)
|
|
26
|
+
{ key: SteamWebApi.config.api_key, steamids: ids.join(',') }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def owned_games(options={})
|
|
32
|
+
@response = get('/IPlayerService/GetOwnedGames/v0001', owned_games_options(options))
|
|
33
|
+
build_response('response') { |data| { count: data['game_count'], games: data['games'] } }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def stats_for_game(app_id)
|
|
37
|
+
@response = get('/ISteamUserStats/GetUserStatsForGame/v0002', stats_for_game_options(app_id))
|
|
38
|
+
build_response('playerstats') { |data| { steam_id: data['steamID'], game_name: data['gameName'], achievements: data['achievements'], stats: data['stats'] } }
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def achievements(app_id, options={})
|
|
42
|
+
@response = get('/ISteamUserStats/GetPlayerAchievements/v0001', achievements_options(app_id, options))
|
|
43
|
+
build_response('playerstats') { |data| { steam_id: data['steamID'], game_name: data['gameName'], achievements: data['achievements'] } }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def summary
|
|
47
|
+
data = self.class.summary(steam_id)
|
|
48
|
+
get_first_data(data) { |data| { profile: data.players.first } }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def friends(relationship='all')
|
|
52
|
+
@response = get('/ISteamUser/GetFriendList/v0001', friends_list_options(relationship))
|
|
53
|
+
build_response('friendslist') { |data| { friends: data['friends'] } }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def recently_played_games(count=nil)
|
|
57
|
+
@response = get('/IPlayerService/GetRecentlyPlayedGames/v0001', recent_games_options(count))
|
|
58
|
+
build_response('response') { |data| { games: data['games'], total_count: data['total_count'] } }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def playing_shared_game(app_id)
|
|
62
|
+
@response = get('/IPlayerService/IsPlayingSharedGame/v0001', shared_game_options(app_id))
|
|
63
|
+
build_response('response') { |data| { lender_steamid: data['lender_steamid'] } }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def bans
|
|
67
|
+
data = self.class.bans(steam_id)
|
|
68
|
+
get_first_data(data) { |data| { bans: data.players.first } }
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def get_first_data(data)
|
|
74
|
+
if data.success && data.players.size > 0
|
|
75
|
+
OpenStruct.new yield(data).merge!(success: true)
|
|
76
|
+
else
|
|
77
|
+
OpenStruct.new(success: false)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def owned_games_options(options)
|
|
82
|
+
options.each { |k, v| options[k] = v ? 1 : 0 }
|
|
83
|
+
{ key: SteamWebApi.config.api_key, steamid: steam_id }.merge!(options)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def stats_for_game_options(game_id)
|
|
87
|
+
{ appid: game_id, key: SteamWebApi.config.api_key, steamid: steam_id }
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def achievements_options(game_id, options)
|
|
91
|
+
{ appid: game_id, key: SteamWebApi.config.api_key, steamid: steam_id }.merge!(options)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def friends_list_options(relationship)
|
|
95
|
+
{ key: SteamWebApi.config.api_key, steamid: steam_id, relationship: relationship }
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def recent_games_options(count)
|
|
99
|
+
{ key: SteamWebApi.config.api_key, steamid: steam_id, count: count }
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
def shared_game_options(app_id)
|
|
103
|
+
{ key: SteamWebApi.config.api_key, steamid: steam_id, appid_playing: app_id }
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
require "steam_web_api/version"
|
|
3
|
+
require "steam_web_api/configuration"
|
|
4
|
+
require "steam_web_api/base"
|
|
5
|
+
require "steam_web_api/player"
|
|
6
|
+
require "steam_web_api/game"
|
|
7
|
+
|
|
8
|
+
begin
|
|
9
|
+
require "byebug"
|
|
10
|
+
rescue LoadError
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
module SteamWebApi
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
|
|
17
|
+
attr_writer :config
|
|
18
|
+
|
|
19
|
+
def config
|
|
20
|
+
@configuration ||= SteamWebApi::Configuration.new
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def configure
|
|
24
|
+
yield config
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|