steam-api 1.0.0
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 +18 -0
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +37 -0
- data/Rakefile +7 -0
- data/lib/steam-api.rb +20 -0
- data/lib/steam-api/client.rb +21 -0
- data/lib/steam-api/exceptions.rb +15 -0
- data/lib/steam-api/helpers.rb +12 -0
- data/lib/steam-api/response.rb +31 -0
- data/lib/steam-api/ruby/hash.rb +11 -0
- data/lib/steam-api/steam.rb +14 -0
- data/lib/steam-api/steam/apps.rb +50 -0
- data/lib/steam-api/steam/economy.rb +57 -0
- data/lib/steam-api/steam/news.rb +30 -0
- data/lib/steam-api/steam/player.rb +73 -0
- data/lib/steam-api/steam/remote_storage.rb +38 -0
- data/lib/steam-api/steam/user.rb +90 -0
- data/lib/steam-api/steam/user_stats.rb +84 -0
- data/lib/steam-api/version.rb +5 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/steam/apps_spec.rb +55 -0
- data/spec/steam/economy_spec.rb +47 -0
- data/spec/steam/news_spec.rb +15 -0
- data/spec/steam/player_spec.rb +94 -0
- data/spec/steam/remote-storage_spec.rb +9 -0
- data/spec/steam/users-stats_spec.rb +85 -0
- data/spec/steam/users_spec.rb +86 -0
- data/spec/steam_spec.rb +33 -0
- data/steam-api.gemspec +30 -0
- metadata +182 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Steam
|
3
|
+
# A Ruby DSL for communicating with the Steam Web API.
|
4
|
+
# @see https://developer.valvesoftware.com/wiki/Steam_Web_API
|
5
|
+
# @since 1.0.0
|
6
|
+
class RemoteStorage
|
7
|
+
# Get Published File Details
|
8
|
+
# @param [Hash] params Parameters to pass to the API
|
9
|
+
# @option params [Fixnum] :itemcount Number of items being requested
|
10
|
+
# @option params [Fixnum] :publishedfileids Published file id to look up
|
11
|
+
# @return [Hash] A hash containing the API response
|
12
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetPublishedFileDetails
|
13
|
+
def self.published_file(params: {})
|
14
|
+
response = client.get 'GetPublishedFileDetails/v1', params: params
|
15
|
+
response
|
16
|
+
end
|
17
|
+
|
18
|
+
# Get UGC File Details
|
19
|
+
# @param [Hash] params Parameters to pass to the API
|
20
|
+
# @option params [String] :key Steam Api Key
|
21
|
+
# @option params [Fixnum] :steamid If specified, only returns details
|
22
|
+
# if the file is owned by the SteamID specified
|
23
|
+
# @option params [Fixnum] :ugcid ID of UGC file to get info for
|
24
|
+
# @option params [Fixnum] :appid appID of product
|
25
|
+
# @return [Hash] A hash containing the API response
|
26
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetUGCFileDetails
|
27
|
+
def self.ugc_file(params: {})
|
28
|
+
response = client.get 'GetUGCFileDetails/v1', params: params
|
29
|
+
response
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def self.client
|
35
|
+
build_client 'ISteamRemoteStorage'
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Steam
|
3
|
+
# A Ruby DSL for communicating with the Steam::User Web API.
|
4
|
+
# @see https://developer.valvesoftware.com/wiki/Steam_Web_API
|
5
|
+
# @since 1.0.0
|
6
|
+
module User
|
7
|
+
# Get User's Friend List
|
8
|
+
# @param [String] steamid
|
9
|
+
# @param [String] relationship Relationship filter.
|
10
|
+
# Possibles values: all, friend.
|
11
|
+
# @return [Hash] A hash object resulting from the API call; should
|
12
|
+
# returns the friend list of any Steam user, provided their Steam
|
13
|
+
# Community profile visibility is set to "Public".
|
14
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetFriendList
|
15
|
+
def self.friends(steamid, relationship: :all)
|
16
|
+
response = client.get 'GetFriendList/v1/',
|
17
|
+
params: { steamid: steamid,
|
18
|
+
relationship: relationship }
|
19
|
+
response = response.parse_key('friendslist')
|
20
|
+
.parse_key('friends')
|
21
|
+
response
|
22
|
+
end
|
23
|
+
|
24
|
+
# Get Multiple Player Bans
|
25
|
+
# @param [Array] steamids Array of SteamIDs
|
26
|
+
# @return [Hash] A hash containing the API response
|
27
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetPlayerBans
|
28
|
+
def self.bans(steamids)
|
29
|
+
steamids = [steamids] unless steamids.is_a?(Array)
|
30
|
+
response = client.get 'GetPlayerBans/v1/',
|
31
|
+
params: { steamids: steamids.join(',') }
|
32
|
+
response
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get Player Summaries
|
36
|
+
# @option params [Array] :steamids List of player's steamids
|
37
|
+
# @return [Hash] The hash object resulting from the API call. Some data
|
38
|
+
# associated with a Steam account may be hidden if the user has their
|
39
|
+
# profile visibility set to "Friends Only" or "Private". In that case,
|
40
|
+
# only public data will be returned.
|
41
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetPlayerSummaries
|
42
|
+
def self.summary(steamid)
|
43
|
+
summaries([steamid]).first
|
44
|
+
end
|
45
|
+
|
46
|
+
# Get Player Summaries
|
47
|
+
# @param [Array] steamids List of player's steamids
|
48
|
+
# @return [Hash] The hash object resulting from the API call. Some data
|
49
|
+
# associated with a Steam account may be hidden if the user has their
|
50
|
+
# profile visibility set to "Friends Only" or "Private". In that case,
|
51
|
+
# only public data will be returned.
|
52
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetPlayerSummaries
|
53
|
+
def self.summaries(steamids)
|
54
|
+
response = client.get 'GetPlayerSummaries/v2/',
|
55
|
+
params: { steamids: steamids.join(',') }
|
56
|
+
response.parse_key('response')
|
57
|
+
.parse_key('players')
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get User Groups
|
61
|
+
# @param [Fixnum] steamid 64bit Steam ID to return friend list.
|
62
|
+
# @return [Hash] A hash containing the API response
|
63
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetUserGroupList
|
64
|
+
def self.groups(steamid)
|
65
|
+
response = client.get 'GetUserGroupList/v1', params: { steamid: steamid }
|
66
|
+
response = response.parse_key('response')
|
67
|
+
response.check_success
|
68
|
+
response.parse_key('groups')
|
69
|
+
end
|
70
|
+
|
71
|
+
# Resolve Vanity URL
|
72
|
+
# @param [String] vanityurl The vanity URL part of a user's Steam
|
73
|
+
# profile URL. This is the basename of http://steamcommunity.com/id/ URLs
|
74
|
+
# @return [Hash] A hash containing the API response
|
75
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/ResolveVanityURL
|
76
|
+
def self.vanity_to_steamid(vanityurl)
|
77
|
+
response = client.get 'ResolveVanityURL/v1',
|
78
|
+
params: { vanityurl: vanityurl }
|
79
|
+
response = response.parse_key('response')
|
80
|
+
response.check_success(success_condition: 1)
|
81
|
+
response.parse_key('steamid')
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def self.client
|
87
|
+
build_client 'ISteamUser'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
module Steam
|
3
|
+
# A Ruby DSL for communicating with the Steam Web API.
|
4
|
+
# @see https://developer.valvesoftware.com/wiki/Steam_Web_API
|
5
|
+
# @since 1.0.0
|
6
|
+
module UserStats
|
7
|
+
# Get Global Achievement Percentages for App
|
8
|
+
# @param [Fixnum] appid The ID of the game or application
|
9
|
+
# @return [Hash] The hash object of information on the global achievements overview of
|
10
|
+
# a specific game in percentages.
|
11
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetGlobalAchievementPercentagesForApp
|
12
|
+
def self.achievement_percentages(appid)
|
13
|
+
response = client.get 'GetGlobalAchievementPercentagesForApp/v2',
|
14
|
+
params: { gameid: appid }
|
15
|
+
response = response.parse_key('achievementpercentages')
|
16
|
+
.parse_key('achievements')
|
17
|
+
response
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get Global Stats for Game
|
21
|
+
# @param [Fixnum] appid The ID of the game or application
|
22
|
+
# @param [Hash] params Parameters to pass to the API
|
23
|
+
# @option params [Fixnum] :count Number of stats to get data for.
|
24
|
+
# @option params [String] :name[0] Names of the stats to get. For more than one value, use
|
25
|
+
# a parameter for each request. (name[0], name[1], ...) Not all stats are globally
|
26
|
+
# aggregated. The developer of the game must mark the stat as globally aggregated.
|
27
|
+
# @option params [String] :startdate Start date for daily totals
|
28
|
+
# (unix epoch timestamp). (Optional)
|
29
|
+
# @option params [String] :enddate End date for daily totals (unix epoch timestamp). (Optional)
|
30
|
+
# @return [Hash] A hash containing the API response
|
31
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetGlobalStatsForGame
|
32
|
+
def self.global_for_game(appid, params: {})
|
33
|
+
params[:appid] = appid
|
34
|
+
response = client.get 'GetGlobalStatsForGame/v1', params: params
|
35
|
+
response.parse_key('response')
|
36
|
+
end
|
37
|
+
|
38
|
+
# Get stat schema
|
39
|
+
# @param [Fixnum] appid The application ID for the Steam Game.
|
40
|
+
# @param [String] language (Optional) Language
|
41
|
+
# @return [Hash] A hash containing the API response
|
42
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetSchemaForGame
|
43
|
+
def self.game_schema(appid, language: nil)
|
44
|
+
params = { appid: appid }
|
45
|
+
params[:l] = language unless language.nil?
|
46
|
+
response = client.get 'GetSchemaForGame/v2', params: params
|
47
|
+
response.parse_key('game')
|
48
|
+
end
|
49
|
+
|
50
|
+
# Get Number of Current Players
|
51
|
+
# @param [Fixnum] appid to pass to the API
|
52
|
+
# @return [Hash] A hash containing the API response
|
53
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetNumberOfCurrentPlayers
|
54
|
+
def self.player_count(appid)
|
55
|
+
response = client.get 'GetNumberOfCurrentPlayers/v1',
|
56
|
+
params: { appid: appid }
|
57
|
+
response.parse_key('response')
|
58
|
+
.parse_key('player_count')
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get Player Achievements
|
62
|
+
# @param [Fixnum] steamid 64 bit Steam ID to return Achievements list for.
|
63
|
+
# @param [Fixnum] appid AppID to get achievements for
|
64
|
+
# @param [String] language Language. If specified, it will return language data for
|
65
|
+
# the requested language. (Optional)
|
66
|
+
# @return [Hash] A hash containing the API response
|
67
|
+
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetPlayerAchievements
|
68
|
+
def self.player_achievements(appid, steamid, language: nil)
|
69
|
+
params = { appid: appid, steamid: steamid }
|
70
|
+
params[:l] = language unless language.nil?
|
71
|
+
response = client.get 'GetPlayerAchievements/v1', params: params
|
72
|
+
response = response.parse_key('playerstats')
|
73
|
+
response.check_success
|
74
|
+
response.delete('success')
|
75
|
+
response
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def self.client
|
81
|
+
build_client('ISteamUserStats')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'coveralls'
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
10
|
+
if File::exist? File.join(File.dirname(__FILE__), "secret.rb")
|
11
|
+
require 'secret'
|
12
|
+
end
|
13
|
+
|
14
|
+
require 'steam-api'
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Steam::Apps do
|
4
|
+
describe '.get_all' do
|
5
|
+
it 'should allow users to look up a list of all apps' do
|
6
|
+
Steam::Apps.get_all
|
7
|
+
.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should allow users to look up a list of all apps' do
|
11
|
+
game = Steam::Apps.get_all.first
|
12
|
+
game.should have_key 'appid'
|
13
|
+
game.should have_key 'name'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.get_servers' do
|
18
|
+
it 'should allow users to look up a list of servers at an ip' do
|
19
|
+
Steam::Apps.get_servers(addr: '192.168.1.1')
|
20
|
+
.should_not be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should allow users to look up a list of servers at an ip' do
|
24
|
+
Steam::Apps.get_servers(addr: '192.168.1.1')
|
25
|
+
.should == []
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.up_to_date' do
|
30
|
+
it 'should allow users to look up version info' do
|
31
|
+
Steam::Apps.up_to_date(appid: 440, version: 10)
|
32
|
+
.should_not be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should return a false up to date value if the verion is out of date' do
|
36
|
+
check = Steam::Apps.up_to_date(appid: 440, version: 10)
|
37
|
+
check['up_to_date'].should be_false
|
38
|
+
check['version_is_listable'].should be_false
|
39
|
+
check.should have_key('required_version')
|
40
|
+
check['message'].should == 'Your server is out of date, please upgrade'
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should return a positive up to date value if the version is correct' do
|
44
|
+
current = Steam::Apps.up_to_date(appid: 440, version: 10)['required_version']
|
45
|
+
check = Steam::Apps.up_to_date(appid: 440, version: current)
|
46
|
+
check['up_to_date'].should be_true
|
47
|
+
check['version_is_listable'].should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should capture json errors' do
|
51
|
+
lambda { Steam::Apps.up_to_date(appid: nil, version: 'foo') }
|
52
|
+
.should raise_error
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Steam::Economy do
|
4
|
+
describe '.asset_info' do
|
5
|
+
it 'should allow users to look up a list of all apps' do
|
6
|
+
Steam::Economy.asset_info(440, params: { class_count: 2,
|
7
|
+
classid0: 195151,
|
8
|
+
classid1: 16891096 })
|
9
|
+
.should_not be_nil
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should require class params' do
|
13
|
+
lambda { Steam::Economy.asset_info(440) }
|
14
|
+
.should raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should allow users to query asset info' do
|
18
|
+
result = Steam::Economy.asset_info(440, params: { class_count: 2,
|
19
|
+
classid0: 195151,
|
20
|
+
classid1: 16891096 })
|
21
|
+
result.should have_key('195151')
|
22
|
+
result.should have_key('16891096')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.asset_prices' do
|
27
|
+
it 'should allow users to look up a list asset prices' do
|
28
|
+
Steam::Economy.asset_prices(440)
|
29
|
+
.should_not be_nil
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should allow return a list of assets' do
|
33
|
+
Steam::Economy.asset_prices(440)
|
34
|
+
.should have_key('assets')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should allow return a list of asset tags' do
|
38
|
+
Steam::Economy.asset_prices(440)
|
39
|
+
.should have_key('tags')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should allow return a list of asset tag ids' do
|
43
|
+
Steam::Economy.asset_prices(440)
|
44
|
+
.should have_key('tag_ids')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Steam::News do
|
4
|
+
describe '.get' do
|
5
|
+
it 'should allow users to look up a list news for an app' do
|
6
|
+
Steam::News.get(440)
|
7
|
+
.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should allow users to look up a list news for an app' do
|
11
|
+
news = Steam::News.get(440)
|
12
|
+
news.count.should == 20
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Steam::Player do
|
4
|
+
describe '.owned_games' do
|
5
|
+
it 'should allow users to retrieve a list of games' do
|
6
|
+
Steam::Player.owned_games(76561197993276293)
|
7
|
+
.should_not be_nil
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should allow users to retrieve a list of games' do
|
11
|
+
Steam::Player.owned_games(76561197993276293)
|
12
|
+
.should have_key('game_count')
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should allow users to retrieve a list of games' do
|
16
|
+
Steam::Player.owned_games(76561197993276293)
|
17
|
+
.should have_key('games')
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.recently_played_games' do
|
22
|
+
it 'should allow users to list a players recent games' do
|
23
|
+
Steam::Player.recently_played_games(76561197993276293)
|
24
|
+
.should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should allow users to list a players recent games' do
|
28
|
+
Steam::Player.recently_played_games(76561197993276293)
|
29
|
+
.should have_key 'total_count'
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should allow users to list a players recent games' do
|
33
|
+
Steam::Player.recently_played_games(76561197993276293)
|
34
|
+
.should have_key 'games'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '.steam_level' do
|
39
|
+
it 'should allow users to retrieve a users steam level' do
|
40
|
+
Steam::Player.steam_level(76561197993276293)
|
41
|
+
.should_not be_nil
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should allow users to retrieve a users steam level' do
|
45
|
+
Steam::Player.steam_level(76561197993276293)
|
46
|
+
.should be_a(Fixnum)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe '.badges' do
|
51
|
+
it 'should allow a user to retrieve badges for a player' do
|
52
|
+
Steam::Player.badges(76561197993276293)
|
53
|
+
.should_not be_nil
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should allow a user to retrieve badges for a player' do
|
57
|
+
Steam::Player.badges(76561197993276293)
|
58
|
+
.should have_key 'badges'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should allow a user to retrieve badges for a player' do
|
62
|
+
Steam::Player.badges(76561197993276293)
|
63
|
+
.should have_key 'player_level'
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should allow a user to retrieve badges for a player' do
|
67
|
+
Steam::Player.badges(76561197993276293)
|
68
|
+
.should have_key 'player_xp'
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should allow a user to retrieve badges for a player' do
|
72
|
+
Steam::Player.badges(76561197993276293)
|
73
|
+
.should have_key 'player_xp_needed_current_level'
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should allow a user to retrieve badges for a player' do
|
77
|
+
Steam::Player.badges(76561197993276293)
|
78
|
+
.should have_key 'player_xp_needed_to_level_up'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '.community_badge_progress' do
|
83
|
+
it 'should allow a user to retrieve community badge info for a player' do
|
84
|
+
Steam::Player.community_badge_progress(76561197993276293)
|
85
|
+
.should_not be_nil
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'should allow a user to retrieve community badge info for a player' do
|
89
|
+
quest = Steam::Player.community_badge_progress(76561197993276293).first
|
90
|
+
quest.should have_key 'questid'
|
91
|
+
quest.should have_key 'completed'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|