steam-api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9d350bed9837ca990cd5f05a491423b01c0bac68
4
+ data.tar.gz: f24dcce0a76752b2eeb62fe5f3428226a4756e50
5
+ SHA512:
6
+ metadata.gz: f3e780148ded110562c84ca841f9b3ebd3cbdd0faf9412290c3916ffef1e819080416290bd2de87cd71b9d960920450fa41281aa1f01ec1413cbddbf9039e257
7
+ data.tar.gz: fbf62a14354948567b72b39cbcbf2a822a79775f3de79cec7fccfc79f3dd8a73c9838b128195f391a2b740ebb5fe66b4dc7e754ba6a36eaca467a685d4a306b2
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ env:
5
+ global:
6
+ secure: P5IpEGYYbF0HcP9Mj9/zZAUXpUjkA2YkGLClvbVGsOD5zI9Jj1RZAlCC/fBKtfPUlfjlADp1hIN++n7qnqqmXPw4X/BC2V8Ios91NoFQeKfjQENSmjYykFTCp1CkBmCjq+lb/yE/JPQnVOoI/eEm5uaNSRc/XLjHwuSdKEFPv8M=
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+ ruby '2.0.0'
3
+
4
+ # Specify your gem's dependencies in simple-steam.gemspec
5
+ gemspec
@@ -0,0 +1,22 @@
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.
@@ -0,0 +1,37 @@
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
+ [![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)
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 tag v1, 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
+ TODO: Write usage instructions here
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1,7 @@
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
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'weary'
3
+ require 'faraday'
4
+ require 'json'
5
+
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'
19
+
20
+ include Steam::Helpers
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Steam
3
+ # Client object used to communicate with the steam webapi
4
+ class Client
5
+ def initialize(url)
6
+ @conn = Faraday.new(url: url)
7
+ end
8
+
9
+ # overriding the get method of Faraday to make things simpler.
10
+ # @param [String] resource the resource you're targeting
11
+ # @param [Hash] params Hash of parameters to pass to the resource
12
+ # @param [String] key Steam API key
13
+ def get(resource, params: {}, key: Steam.apikey)
14
+ params[:key] = key
15
+ response = @conn.get resource, params
16
+ JSON.parse(response.body)
17
+ rescue JSON::ParserError
18
+ { error: '500 Internal Server Error' }
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,15 @@
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 JSONError < StandardError
11
+ def initialize(error = 'The API returned an unexpected JSON response')
12
+ super(error)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module Steam
2
+ module Helpers
3
+ # Conveniance method to build clients
4
+ # @param [String] api The endpoint of the API
5
+ # @param [String] base_url the root uri for steam's API
6
+ # @return [Steam::Client] The Client
7
+ def build_client(api, base_url: 'http://api.steampowered.com')
8
+ Steam::Client.new([base_url, api].join('/'))
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,31 @@
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
+ fail Steam::JSONError unless self.key?(key)
19
+ self[key]
20
+ end
21
+
22
+ # Many responses from the apis (but not all) include a success
23
+ # field, so this allows us to check it wiht minimal fuss.
24
+ # @param [String] success_condition what the success condition should be
25
+ # @return [Boolean] Returns true or raises an exception.
26
+ def check_success(success_condition: true)
27
+ success = self.parse_key('success')
28
+ fail Steam::SteamError unless success == success_condition
29
+ true
30
+ end
31
+ end
@@ -0,0 +1,11 @@
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.
3
+ # @param [Hash] params Hash of params you want broken up into a query string,
4
+ # escaped, and returned to you.
5
+ # @return [String] Escaped parameter string to append to a url.
6
+ class Hash
7
+ def to_params(params = {})
8
+ params[:format] = :json
9
+ return "?#{params.each.map{ |x| x.join('=') }.join('&')}"
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # Base class def
3
+ module Steam
4
+ @apikey = ENV['STEAM_API_KEY']
5
+
6
+ def self.apikey
7
+ fail ArgumentError, 'Please set your Steam API key.' if @apikey.nil?
8
+ @apikey
9
+ end
10
+
11
+ def self.apikey=(key)
12
+ @apikey = key
13
+ end
14
+ end
@@ -0,0 +1,50 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Steam
3
+ # A Ruby DSL for communicating with the Apps portion of the Steam Web API.
4
+ # @see https://developer.valvesoftware.com/wiki/Steam_Web_API
5
+ # @since 1.0.0
6
+ module Apps
7
+ # Get Steam Applications
8
+ # @return [Hash] A list of objects containing the title and app ID of each program
9
+ # available in the store.
10
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetAppList
11
+ def self.get_all
12
+ response = client.get('GetApplist/v2')
13
+ .parse_key('applist')
14
+ .parse_key('apps')
15
+ response
16
+ end
17
+
18
+ # Get Servers at Address
19
+ # @param [String] addr IP or IP:queryport to list
20
+ # @return [Hash] A hash containing the API response
21
+ # @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) }
25
+ response = response.parse_key('response')
26
+ response.check_success
27
+ response.parse_key('servers')
28
+ end
29
+
30
+ # Check if a given version of an App is current
31
+ # @param [Fixnum] appid AppID of game
32
+ # @param [Fixnum] version The installed version of the game
33
+ # @return [Hash] A hash containing the API response
34
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck
35
+ def self.up_to_date(appid: nil, version: nil)
36
+ response = client.get 'UpToDateCheck/v1',
37
+ params: { appid: appid, version: version }
38
+ response = response.parse_key('response')
39
+ response.check_success
40
+ response.delete('success')
41
+ response
42
+ end
43
+
44
+ private
45
+
46
+ def self.client
47
+ build_client 'ISteamApps'
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,57 @@
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 Economy
7
+ # Get Asset Class Info
8
+ # @param [String] appid The application ID for the Steam Game.
9
+ # @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)
17
+ # @return [Hash] A hash containing the API response
18
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/UpToDateCheck
19
+ def self.asset_info(appid, params: {})
20
+ params[:appid] = appid
21
+ response = client.get 'GetAssetClassInfo/v1',
22
+ params: params
23
+ parse_response(response)
24
+ end
25
+
26
+ # Get Asset Prices
27
+ # @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)
33
+ # @return [Hash] A hash containing the API response
34
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetAssetPrices
35
+ def self.asset_prices(appid, language: nil, currency: nil)
36
+ params = { appid: appid }
37
+ params[:language] = language unless language.nil?
38
+ params[:currency] = currency unless currency.nil?
39
+ response = client.get 'GetAssetPrices/v1',
40
+ params: params
41
+ parse_response(response)
42
+ end
43
+
44
+ private
45
+
46
+ def self.client
47
+ build_client 'ISteamEconomy'
48
+ end
49
+
50
+ def self.parse_response(response)
51
+ response = response.parse_key('result')
52
+ response.check_success
53
+ response.delete('success')
54
+ response
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,30 @@
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 News
7
+ # Get News for App
8
+ # @param [Hash] params Parameters to pass to the API
9
+ # @option params [String] :appid The application ID for the Steam Game.
10
+ # @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.
16
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetNewsForApp
17
+ def self.get(appid, params: {})
18
+ params[:appid] = appid
19
+ client.get('GetNewsForApp/v2', params: params)
20
+ .parse_key('appnews')
21
+ .parse_key('newsitems')
22
+ end
23
+
24
+ private
25
+
26
+ def self.client
27
+ build_client 'ISteamNews'
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,73 @@
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 Player
7
+ # Get Owned Games
8
+ # @param [Hash] params Parameters to pass to the API
9
+ # @option params [Fixnum] :steamid The 64 bit ID of the player. (Optional)
10
+ # @option params [Boolean] :include_appinfo (false) Whether or not to include additional
11
+ # details of apps - name and images.
12
+ # @option params [Boolean] :include_played_free_games (false) Whether or not to list
13
+ # free-to-play games in the results.
14
+ # @option params [Array] :appids_filter You can optionally filter the list to a set of appids.
15
+ # Note that these cannot be passed as a URL parameter, instead you must use the JSON format
16
+ # described in Steam_Web_API#Calling_Service_interfaces. The expected input is an array of
17
+ # integers (in JSON: "appids_filter: [ 440, 500, 550 ]" )
18
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetOwnedGames
19
+ def self.owned_games(steamid, params: {})
20
+ params[:steamid] = steamid
21
+ response = client.get 'GetOwnedGames/v1', params: params
22
+ response.parse_key('response')
23
+ end
24
+
25
+ # Get Recently Played Games
26
+ # @param [Hash] params Parameters to pass to the API
27
+ # @option params [String] :steamid The SteamID of the account.
28
+ # @option params [String] :count Optionally limit to a certain number of games (the number of
29
+ # games a person has played in the last 2 weeks is typically very small)
30
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetRecentlyPlayedGames
31
+ def self.recently_played_games(steamid, params: {})
32
+ params[:steamid] = steamid
33
+ response = client.get 'GetRecentlyPlayedGames/v1',
34
+ params: params
35
+ response.parse_key('response')
36
+ end
37
+
38
+ # Get a player's Steam Level
39
+ # @param [Fixnum] steamid The SteamID of the account.
40
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetSteamLevel
41
+ def self.steam_level(steamid)
42
+ response = client.get 'GetSteamLevel/v1',
43
+ params: { steamid: steamid }
44
+ response.parse_key('response')
45
+ .parse_key('player_level')
46
+ end
47
+
48
+ # Get a player's Steam badges
49
+ # @param [Fixnum] steamid The SteamID of the account.
50
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetBadges
51
+ def self.badges(steamid)
52
+ response = client.get 'GetBadges/v1',
53
+ params: { steamid: steamid }
54
+ response.parse_key('response')
55
+ end
56
+
57
+ # Get a player's Steam Level
58
+ # @param [Fixnum] steamid The SteamID of the account.
59
+ # @see http://wiki.teamfortress.com/wiki/WebAPI/GetCommunityBadgeProgress
60
+ def self.community_badge_progress(steamid)
61
+ response = client.get 'GetCommunityBadgeProgress/v1',
62
+ params: { steamid: steamid }
63
+ response.parse_key('response')
64
+ .parse_key('quests')
65
+ end
66
+
67
+ private
68
+
69
+ def self.client
70
+ build_client 'IPlayerService'
71
+ end
72
+ end
73
+ end