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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9d350bed9837ca990cd5f05a491423b01c0bac68
4
- data.tar.gz: f24dcce0a76752b2eeb62fe5f3428226a4756e50
2
+ SHA256:
3
+ metadata.gz: 96cb46113ba573dc3989af65e06477ca2692d66a511bbcf2071058282a12d6ee
4
+ data.tar.gz: ac26ffb8ba9b4644ffd8ada6b0ad16f017394356e23467ff422a956cff6189f9
5
5
  SHA512:
6
- metadata.gz: f3e780148ded110562c84ca841f9b3ebd3cbdd0faf9412290c3916ffef1e819080416290bd2de87cd71b9d960920450fa41281aa1f01ec1413cbddbf9039e257
7
- data.tar.gz: fbf62a14354948567b72b39cbcbf2a822a79775f3de79cec7fccfc79f3dd8a73c9838b128195f391a2b740ebb5fe66b4dc7e754ba6a36eaca467a685d4a306b2
6
+ metadata.gz: 7b7bb32f8b52c0b24c6328f7162f132d6b101e72062c47e2b7bdabb981578306dbbb52fb879076361198ca48a15b29f54ed64eac506a0582eeada4de71ff8d09
7
+ data.tar.gz: 936ad9ba4bae360237d2f3f3ec1847ad56b38fac1684f8f01d6cd09483b1b9d1d24e99456ea82a9201f5fa2b353034c5dd832436b8601354974d4ff5b6dd478c
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ -f d -c --warning
@@ -1,6 +1,28 @@
1
+ addons:
2
+ code_climate:
3
+ repo_token: 5eb1ad424f83b5332cdb915736dc46e23cb24f7b335a063243f928be79d7a75b
1
4
  language: ruby
2
- rvm:
3
- - 2.0.0
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
@@ -1,5 +1,4 @@
1
1
  source 'https://rubygems.org'
2
- ruby '2.0.0'
3
2
 
4
3
  # Specify your gem's dependencies in simple-steam.gemspec
5
4
  gemspec
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
- [![Coverage Status](https://coveralls.io/repos/bhaberer/steam-api/badge.png?branch=master)](https://coveralls.io/r/bhaberer/steam-api?branch=master)
7
- [![Code Climate](https://codeclimate.com/github/bhaberer/steam-api.png)](https://codeclimate.com/github/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
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 tag v1, still have a lot of work to do (especially on the docs).
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
- TODO: Write usage instructions here
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
@@ -1,7 +1,7 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new
5
5
 
6
- task :default => :spec
7
- task :test => :spec
6
+ task default: :spec
7
+ task test: :spec
@@ -1,20 +1,19 @@
1
- # -*- encoding: utf-8 -*-
2
- require 'weary'
3
1
  require 'faraday'
4
2
  require 'json'
5
3
 
6
- require 'steam-api/version'
7
- require 'steam-api/steam'
8
- require 'steam-api/client'
9
- require 'steam-api/exceptions'
10
- require 'steam-api/response'
11
- require 'steam-api/helpers'
12
- require 'steam-api/steam/apps'
13
- require 'steam-api/steam/economy'
14
- require 'steam-api/steam/news'
15
- require 'steam-api/steam/player'
16
- require 'steam-api/steam/remote_storage'
17
- require 'steam-api/steam/user'
18
- require 'steam-api/steam/user_stats'
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
@@ -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
@@ -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')
@@ -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: 'http://api.steampowered.com')
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
-
@@ -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
- # def parse_key(key)
7
- # fail Steam::JSONError unless self.key?(key)
8
- # self[key]
9
- # end
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
- fail Steam::JSONError unless self.key?(key)
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 = self.parse_key('success')
28
- fail Steam::SteamError unless success == success_condition
28
+ success = parse_key('success')
29
+ raise Steam::SteamError unless success == success_condition
30
+
29
31
  true
30
32
  end
31
33
  end
@@ -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 should be numeric.
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
- return "?#{params.each.map{ |x| x.join('=') }.join('&')}"
10
+ "?#{params.each.map { |x| x.join('=') }.join('&')}"
10
11
  end
11
12
  end
@@ -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
- fail ArgumentError, 'Please set your Steam API key.' if @apikey.nil?
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
 
@@ -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 each program
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
- .parse_key('applist')
14
- .parse_key('apps')
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 'GetServersAtAddress/v1',
24
- params: { addr: URI.escape(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: nil)
36
- response = client.get 'UpToDateCheck/v1',
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 the request.
11
- # @option params [Fixnum] :classidN Where N can be a series of sequential numbers to form a list of class IDs. [1] [2]
12
- # @option params [Fixnum] :instanceidN Instance ID of the nth class. (Optional)
13
- # @option params [String] :language The ISO639-1 language code for the language all localized
14
- # strings should be returned in. Not all strings have been translated to every language.
15
- # If a language does not have a string, the English string will be returned instead. If this
16
- # parameter is omitted the string token will be returned for the strings. (Optional)
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 all localized
29
- # strings should be returned in. Not all strings have been translated to every language.
30
- # If a language does not have a string, the English string will be returned instead. If this
31
- # parameter is omitted the string token will be returned for the strings. (Optional)
32
- # @param [String] currency The ISO 4217 code for currency specific filtering. (Optional)
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
- params: params
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
@@ -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 returned. (Optional)
12
- # @option params [Fixnum] :maxlength Maximum length of each news entry. (Optional)
13
- # @option params [Fixnum] :enddate Unix timestamp, returns posts before this date. (Optional)
14
- # @option params [String] :feeds Commma-seperated list of feed names to return news for. (Optional)
15
- # @return [Hash] A hash object of the latest news items for a game specified by its appID.
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
- .parse_key('appnews')
21
- .parse_key('newsitems')
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