steam-api 1.0.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +1 -0
- data/.travis.yml +24 -2
- data/Gemfile +0 -1
- data/README.md +35 -4
- data/Rakefile +4 -4
- data/lib/steam-api.rb +14 -15
- data/lib/steam-api/client.rb +7 -1
- data/lib/steam-api/exceptions.rb +8 -0
- data/lib/steam-api/helpers.rb +5 -2
- data/lib/steam-api/response.rb +10 -8
- data/lib/steam-api/ruby/hash.rb +3 -2
- data/lib/steam-api/steam.rb +7 -2
- data/lib/steam-api/steam/apps.rb +9 -12
- data/lib/steam-api/steam/economy.rb +21 -18
- data/lib/steam-api/steam/news.rb +12 -10
- data/lib/steam-api/steam/player.rb +13 -13
- data/lib/steam-api/steam/remote_storage.rb +0 -3
- data/lib/steam-api/steam/store.rb +20 -0
- data/lib/steam-api/steam/user.rb +1 -3
- data/lib/steam-api/steam/user_stats.rb +21 -11
- data/lib/steam-api/version.rb +1 -2
- data/spec/spec_helper.rb +0 -6
- data/spec/steam/apps_spec.rb +49 -30
- data/spec/steam/economy_spec.rb +22 -26
- data/spec/steam/news_spec.rb +6 -6
- data/spec/steam/player_spec.rb +61 -49
- data/spec/steam/store_spec.rb +18 -0
- data/spec/steam/users-stats_spec.rb +56 -45
- data/spec/steam/users_spec.rb +38 -44
- data/spec/steam_spec.rb +28 -23
- data/steam-api.gemspec +10 -15
- metadata +34 -72
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 96cb46113ba573dc3989af65e06477ca2692d66a511bbcf2071058282a12d6ee
|
4
|
+
data.tar.gz: ac26ffb8ba9b4644ffd8ada6b0ad16f017394356e23467ff422a956cff6189f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b7bb32f8b52c0b24c6328f7162f132d6b101e72062c47e2b7bdabb981578306dbbb52fb879076361198ca48a15b29f54ed64eac506a0582eeada4de71ff8d09
|
7
|
+
data.tar.gz: 936ad9ba4bae360237d2f3f3ec1847ad56b38fac1684f8f01d6cd09483b1b9d1d24e99456ea82a9201f5fa2b353034c5dd832436b8601354974d4ff5b6dd478c
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
-f d -c --warning
|
data/.travis.yml
CHANGED
@@ -1,6 +1,28 @@
|
|
1
|
+
addons:
|
2
|
+
code_climate:
|
3
|
+
repo_token: 5eb1ad424f83b5332cdb915736dc46e23cb24f7b335a063243f928be79d7a75b
|
1
4
|
language: ruby
|
2
|
-
|
3
|
-
-
|
5
|
+
before_install:
|
6
|
+
- gem update --system
|
7
|
+
- gem update bundler
|
4
8
|
env:
|
5
9
|
global:
|
6
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
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,12 +3,12 @@
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/steam-api.png)](http://badge.fury.io/rb/steam-api)
|
4
4
|
[![Dependency Status](https://gemnasium.com/bhaberer/steam-api.png)](https://gemnasium.com/bhaberer/steam-api)
|
5
5
|
[![Build Status](https://travis-ci.org/bhaberer/steam-api.png?branch=master)](https://travis-ci.org/bhaberer/steam-api)
|
6
|
-
[![
|
7
|
-
[![
|
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
8
|
|
9
9
|
`steam-api` is a simple gem to expose the Steam WebApi directly.
|
10
10
|
|
11
|
-
The Gem is not quite finished, but once it is, I will
|
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
12
|
|
13
13
|
## Installation
|
14
14
|
|
@@ -26,7 +26,38 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
## Usage
|
28
28
|
|
29
|
-
|
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
|
+
|
30
61
|
|
31
62
|
## Contributing
|
32
63
|
|
data/Rakefile
CHANGED
data/lib/steam-api.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'weary'
|
3
1
|
require 'faraday'
|
4
2
|
require 'json'
|
5
3
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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'
|
19
18
|
|
20
19
|
include Steam::Helpers
|
data/lib/steam-api/client.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
module Steam
|
3
2
|
# Client object used to communicate with the steam webapi
|
4
3
|
class Client
|
@@ -14,7 +13,14 @@ module Steam
|
|
14
13
|
params[:key] = key
|
15
14
|
response = @conn.get resource, params
|
16
15
|
JSON.parse(response.body)
|
16
|
+
# response
|
17
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
|
+
|
18
24
|
{ error: '500 Internal Server Error' }
|
19
25
|
end
|
20
26
|
end
|
data/lib/steam-api/exceptions.rb
CHANGED
@@ -6,6 +6,14 @@ module Steam
|
|
6
6
|
end
|
7
7
|
end
|
8
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
|
+
|
9
17
|
# Error returning the requested object from the Steam API
|
10
18
|
class JSONError < StandardError
|
11
19
|
def initialize(error = 'The API returned an unexpected JSON response')
|
data/lib/steam-api/helpers.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module Steam
|
2
|
+
# Helper Module
|
2
3
|
module Helpers
|
3
4
|
# Conveniance method to build clients
|
4
5
|
# @param [String] api The endpoint of the API
|
5
6
|
# @param [String] base_url the root uri for steam's API
|
6
7
|
# @return [Steam::Client] The Client
|
7
|
-
def build_client(api, base_url: '
|
8
|
+
def build_client(api, base_url: 'https://api.steampowered.com')
|
8
9
|
Steam::Client.new([base_url, api].join('/'))
|
9
10
|
end
|
11
|
+
|
12
|
+
|
13
|
+
STORE_API_BASE_URL = 'https://store.steampowered.com/api'
|
10
14
|
end
|
11
15
|
end
|
12
|
-
|
data/lib/steam-api/response.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Steam
|
2
2
|
# Since the steam responses are so randomly inconsistant we're making a new
|
3
3
|
# class to manage the responses.
|
4
|
-
# FIXME move all hash extensions here once the gem is finished and make
|
4
|
+
# FIXME: move all hash extensions here once the gem is finished and make
|
5
5
|
class Response < Hash
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
# def parse_key(key)
|
7
|
+
# fail Steam::JSONError unless self.key?(key)
|
8
|
+
# self[key]
|
9
|
+
# end
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
@@ -15,7 +15,8 @@ class Hash
|
|
15
15
|
# nesting their json a few levels on every request.
|
16
16
|
# @param [String] key The key to extract from the hash
|
17
17
|
def parse_key(key)
|
18
|
-
|
18
|
+
raise Steam::JSONError unless key?(key)
|
19
|
+
|
19
20
|
self[key]
|
20
21
|
end
|
21
22
|
|
@@ -24,8 +25,9 @@ class Hash
|
|
24
25
|
# @param [String] success_condition what the success condition should be
|
25
26
|
# @return [Boolean] Returns true or raises an exception.
|
26
27
|
def check_success(success_condition: true)
|
27
|
-
success =
|
28
|
-
|
28
|
+
success = parse_key('success')
|
29
|
+
raise Steam::SteamError unless success == success_condition
|
30
|
+
|
29
31
|
true
|
30
32
|
end
|
31
33
|
end
|
data/lib/steam-api/ruby/hash.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
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
|
2
|
+
# NOTE: this does not do any uri escaping at this point, since all args
|
3
|
+
# should be numeric.
|
3
4
|
# @param [Hash] params Hash of params you want broken up into a query string,
|
4
5
|
# escaped, and returned to you.
|
5
6
|
# @return [String] Escaped parameter string to append to a url.
|
6
7
|
class Hash
|
7
8
|
def to_params(params = {})
|
8
9
|
params[:format] = :json
|
9
|
-
|
10
|
+
"?#{params.each.map { |x| x.join('=') }.join('&')}"
|
10
11
|
end
|
11
12
|
end
|
data/lib/steam-api/steam.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
# Base class def
|
3
2
|
module Steam
|
4
3
|
@apikey = ENV['STEAM_API_KEY']
|
5
4
|
|
6
5
|
def self.apikey
|
7
|
-
|
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
|
8
13
|
@apikey
|
9
14
|
end
|
10
15
|
|
data/lib/steam-api/steam/apps.rb
CHANGED
@@ -1,17 +1,16 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
module Steam
|
3
2
|
# A Ruby DSL for communicating with the Apps portion of the Steam Web API.
|
4
3
|
# @see https://developer.valvesoftware.com/wiki/Steam_Web_API
|
5
4
|
# @since 1.0.0
|
6
5
|
module Apps
|
7
6
|
# Get Steam Applications
|
8
|
-
# @return [Hash] A list of objects containing the title and app ID of
|
9
|
-
# available in the store.
|
7
|
+
# @return [Hash] A list of objects containing the title and app ID of
|
8
|
+
# each program available in the store.
|
10
9
|
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetAppList
|
11
10
|
def self.get_all
|
12
11
|
response = client.get('GetApplist/v2')
|
13
|
-
|
14
|
-
|
12
|
+
.parse_key('applist')
|
13
|
+
.parse_key('apps')
|
15
14
|
response
|
16
15
|
end
|
17
16
|
|
@@ -19,9 +18,9 @@ module Steam
|
|
19
18
|
# @param [String] addr IP or IP:queryport to list
|
20
19
|
# @return [Hash] A hash containing the API response
|
21
20
|
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetServersAtAddress
|
22
|
-
def self.get_servers(addr: nil)
|
23
|
-
response = client.get
|
24
|
-
params: { addr:
|
21
|
+
def self.get_servers(addr: nil, api_version: 'v1')
|
22
|
+
response = client.get "GetServersAtAddress/#{api_version}",
|
23
|
+
params: { addr: ERB::Util.url_encode(addr) }
|
25
24
|
response = response.parse_key('response')
|
26
25
|
response.check_success
|
27
26
|
response.parse_key('servers')
|
@@ -32,8 +31,8 @@ module Steam
|
|
32
31
|
# @param [Fixnum] version The installed version of the game
|
33
32
|
# @return [Hash] A hash containing the API response
|
34
33
|
# @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck
|
35
|
-
def self.up_to_date(appid: nil, version:
|
36
|
-
response = client.get
|
34
|
+
def self.up_to_date(appid: nil, version: 'v1', api_version: 'v1')
|
35
|
+
response = client.get "UpToDateCheck/#{api_version}",
|
37
36
|
params: { appid: appid, version: version }
|
38
37
|
response = response.parse_key('response')
|
39
38
|
response.check_success
|
@@ -41,8 +40,6 @@ module Steam
|
|
41
40
|
response
|
42
41
|
end
|
43
42
|
|
44
|
-
private
|
45
|
-
|
46
43
|
def self.client
|
47
44
|
build_client 'ISteamApps'
|
48
45
|
end
|
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
module Steam
|
3
2
|
# A Ruby DSL for communicating with the Steam Web API.
|
4
3
|
# @see https://developer.valvesoftware.com/wiki/Steam_Web_API
|
@@ -7,29 +6,35 @@ module Steam
|
|
7
6
|
# Get Asset Class Info
|
8
7
|
# @param [String] appid The application ID for the Steam Game.
|
9
8
|
# @param [Hash] params Parameters to pass to the API
|
10
|
-
# @option params [Fixnum] :class_count The number of classids passed to
|
11
|
-
#
|
12
|
-
# @option params [Fixnum] :
|
13
|
-
#
|
14
|
-
#
|
15
|
-
#
|
16
|
-
#
|
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.
|
17
20
|
# @return [Hash] A hash containing the API response
|
18
21
|
# @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck
|
19
22
|
def self.asset_info(appid, params: {})
|
20
23
|
params[:appid] = appid
|
21
|
-
response = client.get 'GetAssetClassInfo/v1',
|
22
|
-
params: params
|
24
|
+
response = client.get 'GetAssetClassInfo/v1', params: params
|
23
25
|
parse_response(response)
|
24
26
|
end
|
25
27
|
|
26
28
|
# Get Asset Prices
|
27
29
|
# @param [String] appid The application ID for the Steam Game.
|
28
|
-
# @param [String] language The ISO639-1 language code for the language
|
29
|
-
# strings should be returned in. Not all strings have been
|
30
|
-
#
|
31
|
-
#
|
32
|
-
#
|
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)
|
33
38
|
# @return [Hash] A hash containing the API response
|
34
39
|
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetAssetPrices
|
35
40
|
def self.asset_prices(appid, language: nil, currency: nil)
|
@@ -37,12 +42,10 @@ module Steam
|
|
37
42
|
params[:language] = language unless language.nil?
|
38
43
|
params[:currency] = currency unless currency.nil?
|
39
44
|
response = client.get 'GetAssetPrices/v1',
|
40
|
-
|
45
|
+
params: params
|
41
46
|
parse_response(response)
|
42
47
|
end
|
43
48
|
|
44
|
-
private
|
45
|
-
|
46
49
|
def self.client
|
47
50
|
build_client 'ISteamEconomy'
|
48
51
|
end
|
data/lib/steam-api/steam/news.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
1
|
module Steam
|
3
2
|
# A Ruby DSL for communicating with the Steam Web API.
|
4
3
|
# @see https://developer.valvesoftware.com/wiki/Steam_Web_API
|
@@ -8,21 +7,24 @@ module Steam
|
|
8
7
|
# @param [Hash] params Parameters to pass to the API
|
9
8
|
# @option params [String] :appid The application ID for the Steam Game.
|
10
9
|
# @option params [String] :key Steam Api Key
|
11
|
-
# @option params [Fixnum] :count How many news enties you want to get
|
12
|
-
#
|
13
|
-
# @option params [Fixnum] :
|
14
|
-
#
|
15
|
-
# @
|
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.
|
16
20
|
# @see http://wiki.teamfortress.com/wiki/WebAPI/GetNewsForApp
|
17
21
|
def self.get(appid, params: {})
|
18
22
|
params[:appid] = appid
|
19
23
|
client.get('GetNewsForApp/v2', params: params)
|
20
|
-
|
21
|
-
|
24
|
+
.parse_key('appnews')
|
25
|
+
.parse_key('newsitems')
|
22
26
|
end
|
23
27
|
|
24
|
-
private
|
25
|
-
|
26
28
|
def self.client
|
27
29
|
build_client 'ISteamNews'
|
28
30
|
end
|