├── .gitignore ├── LICENSE ├── README.md ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Nikolai Vavilov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Steam Web API for Node.js and io.js 2 | 3 | This is an extremely simple node wrapper for Steam Web API. It's very experimental and the API will likely change. 4 | 5 | # Installation 6 | 7 | `npm install steam-web-api` 8 | 9 | # Usage 10 | 11 | The module exports a single `getInterface` function. 12 | 13 | ```js 14 | var getInterface = require('steam-web-api'); 15 | ``` 16 | 17 | Call it with a Web API interface name and an optional API key. 18 | 19 | ```js 20 | var steamRemoteStorage = getInterface('ISteamRemoteStorage'); 21 | // or 22 | var steamRemoteStorage = getInterface('ISteamRemoteStorage', 'API KEY'); 23 | ``` 24 | 25 | It returns an object with two properties: `get` and `post`. Both are functions that accept the following arguments: 26 | 27 | * Method name, e.g. `'GetCollectionDetails'`. 28 | * Method version, e.g. `1`. 29 | * Object with the parameters which will be serialized into a query string. Multiple values (e.g. for "publishedfileids") can be passed as arrays. Unlike other query string modules, this supports binary data (as Buffers) used in AuthenticateUser. 30 | * Callback. The first argument is status code, the second argument is the parsed JSON response if status code is 200. 31 | 32 | `get` sends a GET request, `post` sends a POST request. It retries automatically on network errors. 33 | 34 | ```js 35 | steamRemoteStorage.get('GetUGCFileDetails', 1, { 36 | ugcid: '534000675759633498', 37 | appid: 767 38 | }, function(statusCode, response) { 39 | if (statusCode == 200) 40 | console.log(response); 41 | }); 42 | 43 | steamRemoteStorage.post('GetPublishedFileDetails', 1, { 44 | itemcount: 2, 45 | publishedfileids: ['406121458', '425876040'] 46 | }, function(statusCode, response) { 47 | if (statusCode == 200) 48 | console.log(response); 49 | }); 50 | ``` 51 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | module.exports = function getInterface(iface, apiKey) { 2 | function request(httpmethod, method, version, args, callback) { 3 | if (apiKey) 4 | args.key = apiKey; 5 | 6 | var data = Object.keys(args).map(function(key) { 7 | var value = args[key]; 8 | if (Array.isArray(value)) 9 | return value.map(function(value, index) { 10 | return key + '[' + index + ']=' + value; 11 | }).join('&'); 12 | else if (Buffer.isBuffer(value)) 13 | return key + '=' + value.toString('hex').replace(/../g, '%$&'); 14 | else 15 | return key + '=' + encodeURIComponent(value); 16 | }).join('&'); 17 | 18 | var options = { 19 | hostname: 'api.steampowered.com', 20 | path: '/' + iface + '/' + method + '/v' + version, 21 | method: httpmethod 22 | }; 23 | 24 | if (httpmethod == 'GET') 25 | options.path += '/?' + data; 26 | else 27 | options.headers = { 28 | 'Content-Type': 'application/x-www-form-urlencoded', 29 | 'Content-Length': data.length 30 | }; 31 | 32 | var req = require('https').request(options, function(res) { 33 | if (res.statusCode != 200) { 34 | callback(res.statusCode); 35 | return; 36 | } 37 | var data = ''; 38 | res.on('data', function(chunk) { 39 | data += chunk; 40 | }); 41 | res.on('end', function() { 42 | callback(res.statusCode, JSON.parse(data)); 43 | }); 44 | }); 45 | 46 | req.on('error', function() { 47 | request(httpmethod, method, version, args, callback); 48 | }); 49 | 50 | if (httpmethod == 'POST') 51 | req.end(data); 52 | else 53 | req.end(); 54 | } 55 | 56 | return { 57 | get: request.bind(null, 'GET'), 58 | post: request.bind(null, 'POST') 59 | }; 60 | }; 61 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "steam-web-api", 3 | "version": "0.0.1", 4 | "description": "Steam Web API for Node.js", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/seishun/node-steam-web-api" 8 | }, 9 | "keywords": [ 10 | "steam" 11 | ], 12 | "author": "Nikolai Vavilov ", 13 | "license": "MIT" 14 | } 15 | --------------------------------------------------------------------------------