├── .rspec ├── lib ├── steam-api │ ├── version.rb │ ├── steam.rb │ ├── helpers.rb │ ├── ruby │ │ └── hash.rb │ ├── steam │ │ ├── store.rb │ │ ├── news.rb │ │ ├── remote_storage.rb │ │ ├── apps.rb │ │ ├── economy.rb │ │ ├── player.rb │ │ ├── user.rb │ │ └── user_stats.rb │ ├── exceptions.rb │ ├── client.rb │ └── response.rb └── steam-api.rb ├── Gemfile ├── Rakefile ├── spec ├── spec_helper.rb ├── steam │ ├── remote-storage_spec.rb │ ├── news_spec.rb │ ├── store_spec.rb │ ├── economy_spec.rb │ ├── apps_spec.rb │ ├── users_spec.rb │ ├── users-stats_spec.rb │ └── player_spec.rb └── steam_spec.rb ├── .gitignore ├── .travis.yml ├── steam-api.gemspec ├── LICENSE.txt └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | -f d -c --warning 2 | -------------------------------------------------------------------------------- /lib/steam-api/version.rb: -------------------------------------------------------------------------------- 1 | # Versioning Info 2 | module Steam 3 | VERSION = '1.2.0'.freeze 4 | end 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in simple-steam.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | require 'rspec/core/rake_task' 3 | 4 | RSpec::Core::RakeTask.new 5 | 6 | task default: :spec 7 | task test: :spec 8 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'simplecov' 2 | SimpleCov.start 3 | 4 | if File::exist? File.join(File.dirname(__FILE__), "secret.rb") 5 | require 'secret' 6 | end 7 | 8 | require 'steam-api' 9 | -------------------------------------------------------------------------------- /spec/steam/remote-storage_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::RemoteStorage do 4 | describe '.published_file' do 5 | end 6 | 7 | describe '.ugc_file' do 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .yardoc 6 | Gemfile.lock 7 | InstalledFiles 8 | _yardoc 9 | coverage 10 | doc/ 11 | lib/bundler/man 12 | pkg 13 | rdoc 14 | spec/reports 15 | spec/secret.rb 16 | test/tmp 17 | test/version_tmp 18 | tmp 19 | -------------------------------------------------------------------------------- /spec/steam/news_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::News do 4 | describe '.get' do 5 | let(:result) { Steam::News.get(440) } 6 | 7 | it 'allow users to look up a news list' do 8 | expect(result).to_not be_nil 9 | end 10 | 11 | it 'returns the first 20 articles' do 12 | expect(result.count).to eq(20) 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/steam-api/steam.rb: -------------------------------------------------------------------------------- 1 | # Base class def 2 | module Steam 3 | @apikey = ENV['STEAM_API_KEY'] 4 | 5 | def self.apikey 6 | if @apikey.nil? 7 | unless ENV.key?('STEAM_API_KEY') 8 | raise ArgumentError, 'Please set your Steam API key.' 9 | end 10 | 11 | @apikey = ENV['STEAM_API_KEY'] 12 | end 13 | @apikey 14 | end 15 | 16 | def self.apikey=(key) 17 | @apikey = key 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /spec/steam/store_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | 4 | describe Steam::Store do 5 | let(:appid) { 976730 } 6 | 7 | describe '.app_details' do 8 | let (:result) { Steam::Store.app_details(appid) } 9 | 10 | it 'returns the details of an application' do 11 | expect(result).to_not be_nil 12 | end 13 | 14 | it 'returns a JSON structure containing details of the returned app' do 15 | expect(result).to include("976730") 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/steam-api/helpers.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # Helper Module 3 | module Helpers 4 | # Conveniance method to build clients 5 | # @param [String] api The endpoint of the API 6 | # @param [String] base_url the root uri for steam's API 7 | # @return [Steam::Client] The Client 8 | def build_client(api, base_url: 'https://api.steampowered.com') 9 | Steam::Client.new([base_url, api].join('/')) 10 | end 11 | 12 | 13 | STORE_API_BASE_URL = 'https://store.steampowered.com/api' 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /lib/steam-api/ruby/hash.rb: -------------------------------------------------------------------------------- 1 | # Takes a hash and converts it into a URL encoded parameter string. 2 | # NOTE: this does not do any uri escaping at this point, since all args 3 | # should be numeric. 4 | # @param [Hash] params Hash of params you want broken up into a query string, 5 | # escaped, and returned to you. 6 | # @return [String] Escaped parameter string to append to a url. 7 | class Hash 8 | def to_params(params = {}) 9 | params[:format] = :json 10 | "?#{params.each.map { |x| x.join('=') }.join('&')}" 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /lib/steam-api/steam/store.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | module Store 6 | # Get App Details 7 | # @param String appid The UUID of the Steam Application 8 | # @see https://wiki.teamfortress.com/wiki/User:RJackson/StorefrontAPI#appdetails 9 | def self.app_details(appid) 10 | response = client.get 'appdetails', params: { appids: appid } 11 | response 12 | end 13 | 14 | private 15 | 16 | def self.client 17 | build_client '', base_url: Steam::Helpers::STORE_API_BASE_URL 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/steam-api.rb: -------------------------------------------------------------------------------- 1 | require 'faraday' 2 | require 'json' 3 | 4 | require_relative 'steam-api/version' 5 | require_relative 'steam-api/steam' 6 | require_relative 'steam-api/client' 7 | require_relative 'steam-api/exceptions' 8 | require_relative 'steam-api/response' 9 | require_relative 'steam-api/helpers' 10 | require_relative 'steam-api/steam/apps' 11 | require_relative 'steam-api/steam/economy' 12 | require_relative 'steam-api/steam/news' 13 | require_relative 'steam-api/steam/player' 14 | require_relative 'steam-api/steam/remote_storage' 15 | require_relative 'steam-api/steam/store' 16 | require_relative 'steam-api/steam/user' 17 | require_relative 'steam-api/steam/user_stats' 18 | 19 | include Steam::Helpers 20 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | addons: 2 | code_climate: 3 | repo_token: 5eb1ad424f83b5332cdb915736dc46e23cb24f7b335a063243f928be79d7a75b 4 | language: ruby 5 | before_install: 6 | - gem update --system 7 | - gem update bundler 8 | env: 9 | global: 10 | secure: P5IpEGYYbF0HcP9Mj9/zZAUXpUjkA2YkGLClvbVGsOD5zI9Jj1RZAlCC/fBKtfPUlfjlADp1hIN++n7qnqqmXPw4X/BC2V8Ios91NoFQeKfjQENSmjYykFTCp1CkBmCjq+lb/yE/JPQnVOoI/eEm5uaNSRc/XLjHwuSdKEFPv8M= 11 | after_success: 12 | bundle exec codeclimate-test-reporter 13 | rvm: 14 | - 2.4 15 | - 2.5 16 | - 2.6 17 | - 2.7 18 | - jruby-19mode 19 | - ruby-head 20 | - jruby-head 21 | - ree 22 | matrix: 23 | allow_failures: 24 | - rvm: ree 25 | - rvm: jruby-19mode 26 | - rvm: jruby-head 27 | - rvm: ruby-head 28 | fast_finish: true 29 | -------------------------------------------------------------------------------- /lib/steam-api/exceptions.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # Error returning the requested object from the Steam API 3 | class SteamError < StandardError 4 | def initialize(error = 'The API request has failed') 5 | super(error) 6 | end 7 | end 8 | 9 | # Error returning the requested object from the Steam API 10 | class UnavailableError < StandardError 11 | def initialize(error = 'The server is temporarily unable to service \ 12 | your request. Please try again later.') 13 | super(error) 14 | end 15 | end 16 | 17 | # Error returning the requested object from the Steam API 18 | class JSONError < StandardError 19 | def initialize(error = 'The API returned an unexpected JSON response') 20 | super(error) 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /lib/steam-api/client.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # Client object used to communicate with the steam webapi 3 | class Client 4 | def initialize(url) 5 | @conn = Faraday.new(url: url) 6 | end 7 | 8 | # overriding the get method of Faraday to make things simpler. 9 | # @param [String] resource the resource you're targeting 10 | # @param [Hash] params Hash of parameters to pass to the resource 11 | # @param [String] key Steam API key 12 | def get(resource, params: {}, key: Steam.apikey) 13 | params[:key] = key 14 | response = @conn.get resource, params 15 | JSON.parse(response.body) 16 | # response 17 | rescue JSON::ParserError 18 | puts response.body 19 | # If the steam web api returns an error it's virtually never in json, so 20 | # lets pretend that we're getting some sort of consistant response 21 | # for errors. 22 | raise Steam::UnavailableError if response.status == '503' 23 | 24 | { error: '500 Internal Server Error' } 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /steam-api.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path('lib', __dir__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | require 'steam-api/version' 4 | 5 | Gem::Specification.new do |gem| 6 | gem.name = 'steam-api' 7 | gem.version = Steam::VERSION 8 | gem.authors = ['Brian Haberer'] 9 | gem.email = ['bhaberer@gmail.com'] 10 | gem.description = 'Simple Steam Gem' 11 | gem.summary = 'Simple Gem to interact with the Steam Web API' 12 | gem.homepage = 'https://github.com/bhaberer/steam-api' 13 | gem.license = 'MIT' 14 | 15 | gem.files = `git ls-files`.split($RS) 16 | gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) } 17 | gem.test_files = gem.files.grep(%r{^(test|spec|features)/}) 18 | gem.require_paths = ['lib'] 19 | 20 | gem.add_development_dependency 'codeclimate-test-reporter', '~> 1.0' 21 | gem.add_development_dependency 'rake', '~> 13.0' 22 | gem.add_development_dependency 'rspec', '~> 3.9' 23 | 24 | gem.add_dependency 'faraday', '~> 1.0' 25 | end 26 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Brian Haberer 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /spec/steam_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam do 4 | describe '.apikey' do 5 | before(:all) do 6 | @apikey = Steam.apikey 7 | end 8 | 9 | after(:each) do 10 | Steam.apikey = @apikey 11 | end 12 | 13 | it 'returns a Steam API key if one is defined' do 14 | expect(Steam.apikey).to_not be_nil 15 | end 16 | 17 | it 'returns an error if the Steam Key is missing' do 18 | Steam.apikey = nil 19 | ENV['STEAM_API_KEY'] = nil 20 | expect { Steam.apikey }.to raise_error(ArgumentError, /Please set your Steam API key/) 21 | end 22 | 23 | it 'returns a new value if set to a different API key' do 24 | old = Steam.apikey 25 | Steam.apikey = 'blah' 26 | expect(Steam.apikey).to_not eq(old) 27 | expect(Steam.apikey).to eq('blah') 28 | end 29 | 30 | it 'allows users to set the apikey post init using ENV' do 31 | Steam.apikey = nil 32 | ENV['STEAM_API_KEY'] = nil 33 | expect { Steam.apikey }.to raise_error(ArgumentError, /Please set your Steam API key/) 34 | ENV['STEAM_API_KEY'] = @apikey 35 | expect(Steam.apikey).to eq(@apikey) 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/steam-api/response.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # Since the steam responses are so randomly inconsistant we're making a new 3 | # class to manage the responses. 4 | # FIXME: move all hash extensions here once the gem is finished and make 5 | class Response < Hash 6 | # def parse_key(key) 7 | # fail Steam::JSONError unless self.key?(key) 8 | # self[key] 9 | # end 10 | end 11 | end 12 | 13 | class Hash 14 | # Simple method to access a nested field, since Valve seems to like 15 | # nesting their json a few levels on every request. 16 | # @param [String] key The key to extract from the hash 17 | def parse_key(key) 18 | raise Steam::JSONError unless key?(key) 19 | 20 | self[key] 21 | end 22 | 23 | # Many responses from the apis (but not all) include a success 24 | # field, so this allows us to check it wiht minimal fuss. 25 | # @param [String] success_condition what the success condition should be 26 | # @return [Boolean] Returns true or raises an exception. 27 | def check_success(success_condition: true) 28 | success = parse_key('success') 29 | raise Steam::SteamError unless success == success_condition 30 | 31 | true 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /spec/steam/economy_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::Economy do 4 | describe '.asset_info' do 5 | let(:result) { Steam::Economy.asset_info(440, 6 | params: { class_count: 2, 7 | classid0: 195151, 8 | classid1: 16891096 })} 9 | 10 | it 'returns data' do 11 | expect(result).to_not be_nil 12 | end 13 | 14 | it 'requires class params' do 15 | expect { Steam::Economy.asset_info(440) }.to raise_error(Steam::JSONError) 16 | end 17 | 18 | it 'allows users to query asset info' do 19 | expect(result).to have_key('195151') 20 | expect(result).to have_key('16891096') 21 | end 22 | end 23 | 24 | describe '.asset_prices' do 25 | let(:result) { Steam::Economy.asset_prices(440) } 26 | 27 | it 'allows users to look up a list asset prices' do 28 | expect(result).to_not be_nil 29 | end 30 | 31 | it 'returns a list of assets' do 32 | expect(result).to have_key('assets') 33 | end 34 | 35 | it 'returns a list of asset tags' do 36 | expect(result).to have_key('tags') 37 | end 38 | 39 | it 'returns a list of asset tag ids' do 40 | expect(result).to have_key('tag_ids') 41 | end 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/steam-api/steam/news.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | module News 6 | # Get News for App 7 | # @param [Hash] params Parameters to pass to the API 8 | # @option params [String] :appid The application ID for the Steam Game. 9 | # @option params [String] :key Steam Api Key 10 | # @option params [Fixnum] :count How many news enties you want to get 11 | # returned. (Optional) 12 | # @option params [Fixnum] :maxlength Maximum length of each news 13 | # entry. (Optional) 14 | # @option params [Fixnum] :enddate Unix timestamp, returns posts before 15 | # this date. (Optional) 16 | # @option params [String] :feeds Commma-seperated list of feed names to 17 | # return news for. (Optional) 18 | # @return [Hash] A hash object of the latest news items for a game 19 | # specified by its appID. 20 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetNewsForApp 21 | def self.get(appid, params: {}) 22 | params[:appid] = appid 23 | client.get('GetNewsForApp/v2', params: params) 24 | .parse_key('appnews') 25 | .parse_key('newsitems') 26 | end 27 | 28 | def self.client 29 | build_client 'ISteamNews' 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/steam-api/steam/remote_storage.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | class RemoteStorage 6 | # Get Published File Details 7 | # @param [Hash] params Parameters to pass to the API 8 | # @option params [Fixnum] :itemcount Number of items being requested 9 | # @option params [Fixnum] :publishedfileids Published file id to look up 10 | # @return [Hash] A hash containing the API response 11 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetPublishedFileDetails 12 | def self.published_file(params: {}) 13 | response = client.get 'GetPublishedFileDetails/v1', params: params 14 | response 15 | end 16 | 17 | # Get UGC File Details 18 | # @param [Hash] params Parameters to pass to the API 19 | # @option params [String] :key Steam Api Key 20 | # @option params [Fixnum] :steamid If specified, only returns details 21 | # if the file is owned by the SteamID specified 22 | # @option params [Fixnum] :ugcid ID of UGC file to get info for 23 | # @option params [Fixnum] :appid appID of product 24 | # @return [Hash] A hash containing the API response 25 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetUGCFileDetails 26 | def self.ugc_file(params: {}) 27 | response = client.get 'GetUGCFileDetails/v1', params: params 28 | response 29 | end 30 | 31 | def self.client 32 | build_client 'ISteamRemoteStorage' 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/steam-api/steam/apps.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Apps portion of the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | module Apps 6 | # Get Steam Applications 7 | # @return [Hash] A hash of objects containing the title and app ID of 8 | # each program available in the store. 9 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetAppList 10 | def self.get_all 11 | app_list = {} 12 | response = client.get('GetApplist/v2') 13 | .parse_key('applist') 14 | .parse_key('apps') 15 | 16 | # Render the list of hashes into one large hash 17 | response.collect do |app| 18 | app_list[app.dig('appid')] = app.dig('name') 19 | end 20 | 21 | app_list 22 | end 23 | 24 | # Get Servers at Address 25 | # @param [String] addr IP or IP:queryport to list 26 | # @return [Hash] A hash containing the API response 27 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetServersAtAddress 28 | def self.get_servers(addr: nil, api_version: 'v1') 29 | response = client.get "GetServersAtAddress/#{api_version}", 30 | params: { addr: ERB::Util.url_encode(addr) } 31 | response = response.parse_key('response') 32 | response.check_success 33 | response.parse_key('servers') 34 | end 35 | 36 | # Check if a given version of an App is current 37 | # @param [Fixnum] appid AppID of game 38 | # @param [Fixnum] version The installed version of the game 39 | # @return [Hash] A hash containing the API response 40 | # @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck 41 | def self.up_to_date(appid: nil, version: 'v1', api_version: 'v1') 42 | response = client.get "UpToDateCheck/#{api_version}", 43 | params: { appid: appid, version: version } 44 | response = response.parse_key('response') 45 | response.check_success 46 | response.delete('success') 47 | response 48 | end 49 | 50 | def self.client 51 | build_client 'ISteamApps' 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /spec/steam/apps_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::Apps do 4 | describe '.get_all' do 5 | let(:result) { Steam::Apps.get_all } 6 | 7 | it 'returns a list of apps' do 8 | expect(result).to_not be_nil 9 | end 10 | 11 | it 'returns an appid for each game' do 12 | expect(result.first).to have_key 'appid' 13 | end 14 | 15 | it 'returns a name for each game' do 16 | expect(result.first).to have_key 'name' 17 | end 18 | end 19 | 20 | describe '.get_servers' do 21 | let(:result) { Steam::Apps.get_servers(addr: '192.168.1.1') } 22 | 23 | it 'returns a valid response' do 24 | expect(result).to_not be_nil 25 | end 26 | 27 | it 'returns an empty array for an ip with no servers' do 28 | expect(result).to eq([]) 29 | end 30 | end 31 | 32 | describe '.up_to_date' do 33 | context 'when looking up out of date version info' do 34 | let(:result) { Steam::Apps.up_to_date(appid: 440, version: 10) } 35 | 36 | it 'does not return a nil response' do 37 | expect(result).to_not be_nil 38 | end 39 | 40 | it "returns a false value for 'up_to_date'" do 41 | expect(result['up_to_date']).to be_falsey 42 | end 43 | 44 | it "returns a false value for 'version_is_listable'" do 45 | expect(result['version_is_listable']).to be_falsey 46 | end 47 | 48 | it 'returns a required_version' do 49 | expect(result).to have_key('required_version') 50 | end 51 | 52 | it 'returns an error message' do 53 | expect(result['message']).to eq('Your server is out of date, please upgrade') 54 | end 55 | end 56 | 57 | context 'when looking up current version info' do 58 | let(:current) { Steam::Apps.up_to_date(appid: 440, version: 10)['required_version'] } 59 | let(:check) { Steam::Apps.up_to_date(appid: 440, version: current) } 60 | 61 | it 'returns a positive up to date value' do 62 | expect(check['up_to_date']).to be_truthy 63 | end 64 | 65 | it 'returns a positive version_is_listable value' do 66 | expect(check['version_is_listable']).to be_truthy 67 | end 68 | end 69 | 70 | it 'should capture json errors' do 71 | expect { Steam::Apps.up_to_date(appid: nil, version: 'foo') }.to raise_error(Steam::JSONError) 72 | end 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /spec/steam/users_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::User do 4 | let(:playerid) { 76561197993276293 } 5 | let(:playerid2) { 76561197969622382 } 6 | 7 | describe '.friends' do 8 | let(:result) { Steam::User.friends(playerid) } 9 | 10 | it 'allows users to check a friends for a user' do 11 | expect(result).to_not be_nil 12 | end 13 | 14 | it 'returns a list of friends of a user' do 15 | expect(result.map { |friend| friend.first.last }).to include(playerid2.to_s) 16 | end 17 | 18 | it 'raises an error on a bad friend id' do 19 | expect { Steam::User.friends('765611') }.to raise_error(Steam::JSONError) 20 | end 21 | 22 | it 'returns the same content for :friends and :all' do 23 | friends = Steam::User.friends(playerid2, relationship: :friend) 24 | all_friends = Steam::User.friends(playerid2, relationship: :all) 25 | expect(friends).to eq(all_friends) 26 | end 27 | 28 | it 'returns an error on a bad friend relationship' do 29 | expect { Steam::User.friends(playerid2, relationship: :sadsad) }.to raise_error(Steam::JSONError) 30 | end 31 | end 32 | 33 | describe '.bans' do 34 | it 'allows users to check bans for a user' do 35 | expect(Steam::User.bans(playerid)).to_not be_nil 36 | end 37 | 38 | it 'returns a blank list for bad ids' do 39 | expect(Steam::User.bans(7993276293)).to eq({ 'players' => [] }) 40 | end 41 | 42 | it 'allow users to check bans for multiple steamids' do 43 | expect(Steam::User.bans([playerid, playerid2])).to_not be_nil 44 | end 45 | end 46 | 47 | describe '.summary' do 48 | it 'allows users to get a summary for a user' do 49 | expect(Steam::User.summary(playerid)).to_not be_nil 50 | end 51 | 52 | it 'allows users to check summaries for multiple accounts' do 53 | expect(Steam::User.summaries([playerid, playerid2])).to_not be_nil 54 | end 55 | end 56 | 57 | describe '.vanity_to_steamid' do 58 | let(:result) { Steam::User.vanity_to_steamid('theasmer') } 59 | 60 | it 'return values when they look up vanity urls' do 61 | expect(result).to_not be_nil 62 | end 63 | 64 | it 'returns the correct id when users look up vanity urls' do 65 | expect(result).to eq(playerid.to_s) 66 | end 67 | end 68 | 69 | describe '.groups' do 70 | let(:result) { Steam::User.groups(playerid) } 71 | 72 | it 'allow users to look up a users groups' do 73 | expect(result).to_not be_nil 74 | end 75 | 76 | it 'returns an accurate list of groups a player is a member of' do 77 | expect(result.map { |g| g.values.first }).to include('3640974') 78 | end 79 | end 80 | end 81 | -------------------------------------------------------------------------------- /lib/steam-api/steam/economy.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | module Economy 6 | # Get Asset Class Info 7 | # @param [String] appid The application ID for the Steam Game. 8 | # @param [Hash] params Parameters to pass to the API 9 | # @option params [Fixnum] :class_count The number of classids passed to 10 | # the request. 11 | # @option params [Fixnum] :classidN Where N can be a series of sequential 12 | # numbers to form a list of class IDs. [1] [2] 13 | # @option params [Fixnum] :instanceidN Instance ID of the nth class. 14 | # @option params [String] :language The ISO639-1 language code for the 15 | # language all localized strings should be returned in. Not all strings 16 | # have been translated to every language. 17 | # If a language does not have a string, the English string will be 18 | # returned instead. If this parameter is omitted the string token will 19 | # be returned for the strings. 20 | # @return [Hash] A hash containing the API response 21 | # @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck 22 | def self.asset_info(appid, params: {}) 23 | params[:appid] = appid 24 | response = client.get 'GetAssetClassInfo/v1', params: params 25 | parse_response(response) 26 | end 27 | 28 | # Get Asset Prices 29 | # @param [String] appid The application ID for the Steam Game. 30 | # @param [String] language The ISO639-1 language code for the language 31 | # all localized strings should be returned in. Not all strings have been 32 | # translated to every language. 33 | # If a language does not have a string, the English string will be 34 | # returned instead. If this parameter is omitted the string token will 35 | # be returned for the strings. (Optional) 36 | # @param [String] currency The ISO 4217 code for currency specific 37 | # filtering. (Optional) 38 | # @return [Hash] A hash containing the API response 39 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetAssetPrices 40 | def self.asset_prices(appid, language: nil, currency: nil) 41 | params = { appid: appid } 42 | params[:language] = language unless language.nil? 43 | params[:currency] = currency unless currency.nil? 44 | response = client.get 'GetAssetPrices/v1', 45 | params: params 46 | parse_response(response) 47 | end 48 | 49 | def self.client 50 | build_client 'ISteamEconomy' 51 | end 52 | 53 | def self.parse_response(response) 54 | response = response.parse_key('result') 55 | response.check_success 56 | response.delete('success') 57 | response 58 | end 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /spec/steam/users-stats_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::UserStats do 4 | describe '.achievement_percentages' do 5 | let(:result) { Steam::UserStats.achievement_percentages(440) } 6 | 7 | it 'returns achievement information' do 8 | expect(result).to_not be_nil 9 | end 10 | 11 | it 'returns all achievements for a game' do 12 | expect(result.first).to have_key('name') 13 | expect(result.first).to have_key('percent') 14 | end 15 | end 16 | 17 | describe '.game_schema' do 18 | let(:result) { Steam::UserStats.game_schema(440) } 19 | 20 | it 'returns global game stats' do 21 | expect(result).to_not be_nil 22 | end 23 | 24 | it 'returns global game stats with a gameName' do 25 | expect(result).to have_key('gameName') 26 | end 27 | 28 | it 'returns global game stats with a gameVersion' do 29 | expect(result).to have_key('gameVersion') 30 | end 31 | 32 | it 'returns global game stats with availableGameStats' do 33 | expect(result).to have_key('availableGameStats') 34 | end 35 | end 36 | 37 | describe '.global_for_game' do 38 | it 'returns global game stats' do 39 | Steam::UserStats.global_for_game(201830, params: { 'name[0]' => 'totalDeaths', count: 10 }) 40 | end 41 | end 42 | 43 | describe '.player_count' do 44 | it 'returns a player count' do 45 | expect(Steam::UserStats.player_count(440)).to be_a(Integer) 46 | end 47 | end 48 | 49 | describe '.get_player_achievements' do 50 | let(:achs) { Steam::UserStats.player_achievements(440, 76561197993276293) } 51 | 52 | it 'returns a list of player achievements' do 53 | expect(achs).to have_key('achievements') 54 | end 55 | 56 | it 'returns a gameName' do 57 | expect(achs).to have_key('gameName') 58 | end 59 | 60 | it 'returns correct gameName' do 61 | expect(achs['gameName']).to eq('Team Fortress 2') 62 | end 63 | 64 | it 'returns a steamID' do 65 | expect(achs).to have_key('steamID') 66 | end 67 | 68 | it 'returns the correct steamID' do 69 | expect(achs['steamID']).to eq('76561197993276293') 70 | end 71 | end 72 | 73 | describe '.player_stats' do 74 | let(:stats) { Steam::UserStats.player_stats(440, 76561197993276293) } 75 | 76 | it 'returns player stats' do 77 | expect(stats).to have_key('stats') 78 | end 79 | 80 | it 'returns a gameName' do 81 | expect(stats).to have_key('gameName') 82 | end 83 | 84 | it 'returns the correct gameName' do 85 | expect(stats['gameName']).to eq('Team Fortress 2') 86 | end 87 | 88 | it 'returns a steamID' do 89 | expect(stats).to have_key('steamID') 90 | end 91 | 92 | it 'returns a correct steamID' do 93 | expect(stats['steamID']).to eq('76561197993276293') 94 | end 95 | end 96 | end 97 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SteamAPI 2 | 3 | [![Gem Version](https://badge.fury.io/rb/steam-api.png)](http://badge.fury.io/rb/steam-api) 4 | [![Dependency Status](https://gemnasium.com/bhaberer/steam-api.png)](https://gemnasium.com/bhaberer/steam-api) 5 | [![Build Status](https://travis-ci.org/bhaberer/steam-api.png?branch=master)](https://travis-ci.org/bhaberer/steam-api) 6 | [![Maintainability](https://api.codeclimate.com/v1/badges/e3100c4ed420e839a6cc/maintainability)](https://codeclimate.com/github/bhaberer/steam-api/maintainability) 7 | [![Test Coverage](https://api.codeclimate.com/v1/badges/e3100c4ed420e839a6cc/test_coverage)](https://codeclimate.com/github/bhaberer/steam-api/test_coverage) 8 | 9 | `steam-api` is a simple gem to expose the Steam WebApi directly. 10 | 11 | The Gem is not quite finished, but once it is, I will note that here, I still have a lot of work to do (especially on the docs). 12 | 13 | ## Installation 14 | 15 | Add this line to your application's Gemfile: 16 | 17 | gem 'steam-api' 18 | 19 | And then execute: 20 | 21 | $ bundle 22 | 23 | Or install it yourself as: 24 | 25 | $ gem install steam-api 26 | 27 | ## Usage 28 | 29 | First you will need to set your Steam API Key you can get this at http://steamcommunity.com/dev/apikey 30 | 31 | Once you get it, go ahead and set it. (You can also pass it as the `STEAM_API_KEY` env variable) 32 | 33 | ```2.1.1 :001 > Steam.apikey = 'YOURAPIKEY'``` 34 | 35 | Once you've done that you can use any of the API functions in the various modules, for a list of all available commands please see the docs here: http://rubydoc.info/gems/steam-api/ Of note, all the commands use the numerical Steam ID, if you need to convert from the vanity name you can use the following method: 36 | 37 | ``` 38 | 2.1.1 :012 > Steam::User.vanity_to_steamid("asmeroth") 39 | 40 | => "76561197993276293" 41 | ``` 42 | 43 | ### Examples 44 | 45 | Get the Steam level for a user: 46 | 47 | ``` 48 | 2.1.1 :014 > Steam::Player.steam_level(76561197993276293) 49 | 50 | => 34 51 | ``` 52 | 53 | Get the Borderlands Achievements for a given player: 54 | 55 | ``` 56 | 2.1.1 :005 > Steam::UserStats.player_achievements(8980, 76561197969622382) 57 | 58 | => {"steamID"=>"76561197969622382", "gameName"=>"Borderlands", "achievements"=>[{"apiname"=>"Achievement_1", "achieved"=>0}, {"apiname"=>"Achievement_2", "achieved"=>0}, {"apiname"=>"Achievement_3", "achieved"=>0}, {"apiname"=>"Achievement_4", "achieved"=>0}, {"apiname"=>"Achievement_5", "achieved"=>0}, {"apiname"=>"Achievement_6", "achieved"=>0}, {"apiname"=>"Achievement_7", "achieved"=>0}, {"apiname"=>"Achievement_8", "achieved"=>0}, {"apiname"=>"Achievement_9", "achieved"=>0}, {"apiname"=>"Achievement_10", ... ]} 59 | ``` 60 | 61 | 62 | ## Contributing 63 | 64 | 1. Fork it 65 | 2. Create your feature branch (`git checkout -b my-new-feature`) 66 | 3. Commit your changes (`git commit -am 'Add some feature'`) 67 | 4. Push to the branch (`git push origin my-new-feature`) 68 | 5. Create new Pull Request 69 | -------------------------------------------------------------------------------- /spec/steam/player_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Steam::Player do 4 | let(:playerid) { 76561197993276293 } 5 | 6 | describe '.owned_games' do 7 | let(:result) { Steam::Player.owned_games(playerid) } 8 | 9 | it 'allows users to retrieve a list of games' do 10 | expect(result).to_not be_nil 11 | end 12 | 13 | it 'returns a game_count' do 14 | expect(result).to have_key('game_count') 15 | end 16 | 17 | it 'returns a list of games' do 18 | expect(result).to have_key('games') 19 | end 20 | end 21 | 22 | describe '.recently_played_games' do 23 | let(:result) { Steam::Player.recently_played_games(playerid) } 24 | 25 | it 'allows users to list a players recent games' do 26 | expect(result).to_not be_nil 27 | end 28 | 29 | it 'returns total_count' do 30 | expect(result).to have_key('total_count') 31 | end 32 | 33 | it 'returns the list of games' do 34 | expect(result).to have_key('games') 35 | end 36 | 37 | it 'returns the recent playtime for games' do 38 | expect(result['games'].first).to have_key('playtime_2weeks') 39 | end 40 | 41 | it 'returns the full playtime for games' do 42 | expect(result['games'].first).to have_key('playtime_forever') 43 | end 44 | end 45 | 46 | describe '.steam_level' do 47 | let(:result) { Steam::Player.steam_level(playerid) } 48 | 49 | it 'allows users to retrieve a users steam level' do 50 | expect(result).to_not be_nil 51 | end 52 | 53 | it 'returns the level number' do 54 | expect(result).to be_a(Integer) 55 | end 56 | end 57 | 58 | describe '.badges' do 59 | let(:result) { Steam::Player.badges(playerid) } 60 | 61 | it 'allows a user to retrieve badges for a player' do 62 | expect(result).to_not be_nil 63 | end 64 | 65 | it 'returns a list of badges' do 66 | expect(result).to have_key('badges') 67 | end 68 | 69 | it 'returns the player level' do 70 | expect(result).to have_key('player_level') 71 | end 72 | 73 | it 'returns the player level as a number' do 74 | expect(result['player_level']).to be_a(Integer) 75 | end 76 | 77 | it 'returns the players current xp' do 78 | expect(result).to have_key('player_xp') 79 | end 80 | 81 | it 'returns the xp a player needed to reach thier current level' do 82 | expect(result).to have_key('player_xp_needed_current_level') 83 | end 84 | 85 | it 'returns the xp a player needs to reach next level' do 86 | expect(result).to have_key('player_xp_needed_to_level_up') 87 | end 88 | end 89 | 90 | describe '.community_badge_progress' do 91 | let(:result) { Steam::Player.community_badge_progress(playerid) } 92 | 93 | it 'allows a user to retrieve community badge info for a player' do 94 | expect(result).to_not be_nil 95 | end 96 | 97 | it 'returns a list of quests' do 98 | expect(result).to be_a(Array) 99 | end 100 | 101 | it 'returns a list of quests with ids and completion status' do 102 | expect(result.first).to have_key('questid') 103 | expect(result.first).to have_key('completed') 104 | end 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /lib/steam-api/steam/player.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | module Player 6 | # Get Owned Games 7 | # @param [Hash] params Parameters to pass to the API 8 | # @option params [Fixnum] :steamid The 64 bit ID of the player. (Optional) 9 | # @option params [Integer] :include_appinfo (0) Whether or not to include 10 | # additional details of apps - name and images. 11 | # @option params [Boolean] :include_played_free_games (false) Whether or 12 | # not to list free-to-play games in the results. 13 | # @option params [Array] :appids_filter You can optionally filter the list 14 | # to a set of appids. 15 | # Note that these cannot be passed as a URL parameter, instead you must 16 | # use the JSON format described in 17 | # Steam_Web_API#Calling_Service_interfaces. The expected input is an 18 | # array of integers (in JSON: "appids_filter: [ 440, 500, 550 ]" ) 19 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetOwnedGames 20 | def self.owned_games(steamid, params: {}) 21 | params[:steamid] = steamid 22 | response = client.get 'GetOwnedGames/v1', params: params 23 | response.parse_key('response') 24 | end 25 | 26 | # Get Recently Played Games 27 | # @param [Hash] params Parameters to pass to the API 28 | # @option params [String] :steamid The SteamID of the account. 29 | # @option params [String] :count Optionally limit to a certain number of 30 | # games (the number of games a person has played in the last 2 weeks is 31 | # typically very small) 32 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetRecentlyPlayedGames 33 | def self.recently_played_games(steamid, params: {}) 34 | params[:steamid] = steamid 35 | response = client.get 'GetRecentlyPlayedGames/v1', 36 | params: params 37 | response.parse_key('response') 38 | end 39 | 40 | # Get a player's Steam Level 41 | # @param [Fixnum] steamid The SteamID of the account. 42 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetSteamLevel 43 | def self.steam_level(steamid) 44 | response = client.get 'GetSteamLevel/v1', 45 | params: { steamid: steamid } 46 | response.parse_key('response') 47 | .parse_key('player_level') 48 | end 49 | 50 | # Get a player's Steam badges 51 | # @param [Fixnum] steamid The SteamID of the account. 52 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetBadges 53 | def self.badges(steamid) 54 | response = client.get 'GetBadges/v1', 55 | params: { steamid: steamid } 56 | response.parse_key('response') 57 | end 58 | 59 | # Get a player's Steam Level 60 | # @param [Fixnum] steamid The SteamID of the account. 61 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetCommunityBadgeProgress 62 | def self.community_badge_progress(steamid) 63 | response = client.get 'GetCommunityBadgeProgress/v1', 64 | params: { steamid: steamid } 65 | response.parse_key('response') 66 | .parse_key('quests') 67 | end 68 | 69 | def self.client 70 | build_client 'IPlayerService' 71 | end 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /lib/steam-api/steam/user.rb: -------------------------------------------------------------------------------- 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 | def self.client 85 | build_client 'ISteamUser' 86 | end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /lib/steam-api/steam/user_stats.rb: -------------------------------------------------------------------------------- 1 | module Steam 2 | # A Ruby DSL for communicating with the Steam Web API. 3 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API 4 | # @since 1.0.0 5 | module UserStats 6 | # Get Global Achievement Percentages for App 7 | # @param [Fixnum] appid The ID of the game or application 8 | # @return [Hash] The hash object of information on the global achievements 9 | # overview of a specific game in percentages. 10 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetGlobalAchievementPercentagesForApp 11 | def self.achievement_percentages(appid) 12 | response = client.get 'GetGlobalAchievementPercentagesForApp/v2', 13 | params: { gameid: appid } 14 | response = response.parse_key('achievementpercentages') 15 | .parse_key('achievements') 16 | response 17 | end 18 | 19 | # Get Global Stats for Game 20 | # @param [Fixnum] appid The ID of the game or application 21 | # @param [Hash] params Parameters to pass to the API 22 | # @option params [Fixnum] :count Number of stats to get data for. 23 | # @option params [String] :name[0] Names of the stats to get. For more than 24 | # one value, use a parameter for each request. (name[0], name[1], ...) 25 | # Not all stats are globally aggregated. The developer of the game must 26 | # 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 30 | # timestamp). (Optional) 31 | # @return [Hash] A hash containing the API response 32 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetGlobalStatsForGame 33 | def self.global_for_game(appid, params: {}) 34 | params[:appid] = appid 35 | response = client.get 'GetGlobalStatsForGame/v1', params: params 36 | response.parse_key('response') 37 | end 38 | 39 | # Get stat schema 40 | # @param [Fixnum] appid The application ID for the Steam Game. 41 | # @param [String] language (Optional) Language 42 | # @return [Hash] A hash containing the API response 43 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetSchemaForGame 44 | def self.game_schema(appid, language: nil) 45 | params = { appid: appid } 46 | params[:l] = language unless language.nil? 47 | response = client.get 'GetSchemaForGame/v2', params: params 48 | response.parse_key('game') 49 | end 50 | 51 | # Get Number of Current Players 52 | # @param [Fixnum] appid to pass to the API 53 | # @return [Hash] A hash containing the API response 54 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetNumberOfCurrentPlayers 55 | def self.player_count(appid) 56 | response = client.get 'GetNumberOfCurrentPlayers/v1', 57 | params: { appid: appid } 58 | response.parse_key('response') 59 | .parse_key('player_count') 60 | end 61 | 62 | # Get Player Achievements 63 | # @param [Fixnum] steamid 64 bit Steam ID to return Achievements list for. 64 | # @param [Fixnum] appid AppID to get achievements for 65 | # @param [String] language Language. If specified, it will return language 66 | # data for the requested language. (Optional) 67 | # @return [Hash] A hash containing the API response 68 | # @see http://wiki.teamfortress.com/wiki/WebAPI/GetPlayerAchievements 69 | def self.player_achievements(appid, steamid, language: nil) 70 | params = { appid: appid, steamid: steamid } 71 | params[:l] = language unless language.nil? 72 | response = client.get 'GetPlayerAchievements/v1', params: params 73 | response = response.parse_key('playerstats') 74 | response.check_success 75 | response.delete('success') 76 | response 77 | end 78 | 79 | # Get User Stats for Game 80 | # @param [Fixnum] appid AppID to get stats for. 81 | # @param [Fixnum] steamid 64 bit Steam ID to return stats for. 82 | # @return [Hash] A hash containing the API response. 83 | # @see https://developer.valvesoftware.com/wiki/Steam_Web_API#GetUserStatsForGame_.28v0002.29 84 | def self.player_stats(appid, steamid) 85 | params = { appid: appid, steamid: steamid } 86 | response = client.get 'GetUserStatsForGame/v2', params: params 87 | response.parse_key('playerstats') 88 | end 89 | 90 | def self.client 91 | build_client('ISteamUserStats') 92 | end 93 | end 94 | end 95 | --------------------------------------------------------------------------------