steam-market-pricing
Advanced tools
Comparing version 1.0.4 to 2.0.0
95
index.js
@@ -1,2 +0,3 @@ | ||
var request = require('request'); | ||
const got = require('got'); | ||
const map = require('p-map'); | ||
@@ -8,82 +9,38 @@ /** | ||
* @param {String} name - Item name, market hashed | ||
* @param {Function} callback - Callback function(err, data) | ||
* @param {number} [currency=1] - Currency code number, default USD (https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696) | ||
*/ | ||
exports.getItemPrice = function(appid, name, callback, currency) { | ||
if (typeof callback !== 'function') { | ||
throw new Error('No callback supplied'); | ||
async function getItemPrice(appid, name, currency = 1) { | ||
const response = await got('http://steamcommunity.com//market/priceoverview', { | ||
json: true, | ||
query: { | ||
currency: currency, | ||
appid: appid, | ||
market_hash_name: name | ||
} | ||
}); | ||
if (typeof currency !== 'number') { | ||
currency = 1; | ||
} | ||
return { ...response.body, market_hash_name: name }; | ||
} | ||
request({ | ||
uri: '/market/priceoverview', | ||
baseUrl: 'http://steamcommunity.com/', | ||
json: true, | ||
qs: { | ||
currency: currency, | ||
appid: appid, | ||
market_hash_name: name | ||
} | ||
}, function(err, response, body) { | ||
if (!err && response.statusCode === 200) { | ||
body.market_hash_name = name; | ||
callback(null, body); | ||
} else { | ||
callback(err); | ||
} | ||
}); | ||
}; | ||
/** | ||
* Retrieve price for list of items. | ||
* Retrieve prices for list of items. | ||
* | ||
* @param {number} appid - Steam application id | ||
* @param {Object} names - Item name, market hashed | ||
* @param {Function} callback - Callback function(err, data) | ||
* @param {Array} names - List of item names, market hashed | ||
* @param {number} [currency=1] - Currency code number, default USD (https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696) | ||
* @param {number} [concurrency=1] - Number of concurrently running requests | ||
*/ | ||
exports.getItemsPrice = function(appid, names, callback, currency) { | ||
if (typeof callback !== 'function') { | ||
throw new Error('No callback supplied'); | ||
} | ||
async function getItemsPrices(appid, names, currency = 1, concurrency = 1) { | ||
if (!Array.isArray(names)) { | ||
if (typeof names === 'string') return getItemsPrices(appid, [names], currency); | ||
throw new Error(`Invalid argument names, expected array got ${typeof names}`); | ||
} | ||
if (typeof currency !== 'number') { | ||
currency = 1; | ||
} | ||
const result = {}; | ||
const items = await map(names, name => getItemPrice(appid, name, currency).catch(err => ({ success: false, market_hash_name: name, err })), { concurrency }); | ||
items.forEach(item => result[item.market_hash_name] = item); | ||
if (typeof names !== 'object') { | ||
if (typeof names === 'string') { | ||
names = [names]; | ||
} else { | ||
throw new Error('Non-object supplied'); | ||
} | ||
} | ||
return result; | ||
} | ||
var result = {}; | ||
names.forEach(function(name) { | ||
request({ | ||
uri: '/market/priceoverview', | ||
baseUrl: 'http://steamcommunity.com/', | ||
json: true, | ||
qs: { | ||
currency: currency, | ||
appid: appid, | ||
market_hash_name: name | ||
} | ||
}, function(err, response, body) { | ||
if (!err && response.statusCode === 200) { | ||
result[name] = body; | ||
} else { | ||
result[name] = {'success': false}; | ||
} | ||
if(Object.keys(result).length === names.length) { | ||
callback(result); | ||
} | ||
}); | ||
}); | ||
}; | ||
module.exports = { getItemPrice, getItemsPrices }; |
{ | ||
"name": "steam-market-pricing", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "Simple module that checks steam market prices", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "ava" | ||
}, | ||
"repository": { | ||
@@ -34,4 +37,11 @@ "type": "git", | ||
"dependencies": { | ||
"request": "^2.65.0" | ||
"got": "^8.0.1", | ||
"p-map": "^1.2.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^0.24.0" | ||
}, | ||
"engines": { | ||
"node": ">= 7.6" | ||
} | ||
} |
@@ -12,2 +12,4 @@ # Steam market price checker for Node.js | ||
**Note** Latest release requires `async/await` (node >= 7.6) support to run to run, install 1.0.3 if your environment does not support it | ||
## Usage | ||
@@ -18,9 +20,5 @@ | ||
```js | ||
var market = require('steam-market-pricing'); | ||
const market = require('steam-market-pricing'); | ||
market.getItemPrice(730, 'MP9 | Storm (Minimal Wear)', function(err, data) { | ||
if(!err) { | ||
console.log(data); | ||
} | ||
}); | ||
market.getItemPrice(730, 'MP9 | Storm (Minimal Wear)').then(item => console.log(item)); | ||
``` | ||
@@ -32,5 +30,5 @@ | ||
"success": true, | ||
"lowest_price": "$0.06", | ||
"volume": "237", | ||
"median_price": "$0.04", | ||
"lowest_price": "$0.05", | ||
"volume": "108", | ||
"median_price": "$0.03", | ||
"market_hash_name": "MP9 | Storm (Minimal Wear)" | ||
@@ -43,15 +41,10 @@ } | ||
```js | ||
var market = require('steam-market-pricing'); | ||
const market = require('steam-market-pricing'); | ||
var names = [ | ||
'MP9 | Storm (Minimal Wear)', | ||
'Sawed-Off | Origami (Well-Worn)' | ||
const names = [ | ||
'MP9 | Storm (Minimal Wear)', | ||
'Sawed-Off | Origami (Well-Worn)' | ||
]; | ||
market.getItemsPrice(730, names, function(data) { | ||
//console.log(data); | ||
for(var i in names) { | ||
console.log(names[i] + ' median price: ' + data[names[i]]['median_price']); | ||
} | ||
}); | ||
market.getItemsPrices(730, names).then(items => names.forEach(name => console.log(`${name}: ${items[name].median_price}`))); | ||
``` | ||
@@ -61,3 +54,3 @@ | ||
``` | ||
MP9 | Storm (Minimal Wear) median price: $0.05 | ||
MP9 | Storm (Minimal Wear) median price: $0.03 | ||
Sawed-Off | Origami (Well-Worn) median price: $0.09 | ||
@@ -69,7 +62,5 @@ ``` | ||
```js | ||
var market = require('steam-market-pricing'); | ||
const market = require('steam-market-pricing'); | ||
market.getItemsPrice(730, 'MP9 | Storm (Minimal Wear)', function(data) { | ||
console.log(data); | ||
}); | ||
market.getItemsPrices(730, 'Sawed-Off | Origami (Well-Worn)').then(items => console.log(items)); | ||
``` | ||
@@ -82,5 +73,5 @@ | ||
"success": true, | ||
"lowest_price": "$0.09", | ||
"volume": "160", | ||
"median_price": "$0.07" | ||
"lowest_price": "$0.12", | ||
"volume": "18", | ||
"median_price": "$0.09" | ||
} | ||
@@ -90,27 +81,50 @@ } | ||
**Note:** You can't handle response errors using getItemsPrice() method, any error will show as `success`: `false`. | ||
Use with `await` for the best experience, check `test.js` for examples | ||
## Methods | ||
### getItemPrice(appid, name, callback, [currency]) | ||
### getItemPrice(appid, name, [currency = 1]) | ||
- `appid` - Steam application id | ||
- `name` - Item name, market hashed | ||
- `callback` - Callback function, called on response | ||
- `err` - Request error, null if none | ||
- `data` - JSON response data | ||
- `currency` - Optional. Currency code (see: https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696) | ||
- `currency` - Optional. Currency code | ||
Requests steam item market details | ||
Requests steam item market details. Returns promise. | ||
### getItemsPrice(appid, names, callback, [currency]) | ||
### getItemsPrices(appid, names[, currency = 1][, concurrency = 1]) | ||
- `appid` - Steam application id | ||
- `names` - Array with item names, market hashed | ||
- `callback` - Callback function, called on response | ||
- `data` - JSON response data | ||
- `currency` - Optional. Currency code (see: https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd#L696) | ||
- `currency` - Optional. Currency code | ||
- `currency` - Optional. Number of concurrent requests | ||
Requests multiple steam items market details. Any error will be shown as `success`: `false`. | ||
Requests multiple steam items market details. Returns promise. | ||
**Note:** `getItemsPrices` will not throw, instead, it will attach the error into response object: `{ "success": false, "err": HTTPError }` check [GOT errors](https://www.npmjs.com/package/got#errors) for error descriptions | ||
Currency codes can be found [here](https://github.com/SteamRE/SteamKit/blob/master/Resources/SteamLanguage/enums.steamd) | ||
## License | ||
MIT | ||
``` | ||
The MIT License (MIT) | ||
Copyright (c) 2015-2018 Arkadiusz Sygulski <arkadiusz@sygulski.pl> | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
``` | ||
Sorry, the diff of this file is not supported yet
10062
7
106
123
2
1
+ Addedgot@^8.0.1
+ Addedp-map@^1.2.0
+ Added@sindresorhus/is@0.7.0(transitive)
+ Addedcacheable-request@2.1.4(transitive)
+ Addedclone-response@1.0.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addedduplexer3@0.1.5(transitive)
+ Addedfrom2@2.3.0(transitive)
+ Addedget-stream@3.0.0(transitive)
+ Addedgot@8.3.2(transitive)
+ Addedhas-symbol-support-x@1.4.2(transitive)
+ Addedhas-to-string-tag-x@1.4.1(transitive)
+ Addedhttp-cache-semantics@3.8.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinto-stream@3.1.0(transitive)
+ Addedis-object@1.0.2(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedis-retry-allowed@1.2.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisurl@1.0.0(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.0.0(transitive)
+ Addedlowercase-keys@1.0.01.0.1(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addednormalize-url@2.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedp-cancelable@0.4.1(transitive)
+ Addedp-finally@1.0.0(transitive)
+ Addedp-is-promise@1.1.0(transitive)
+ Addedp-map@1.2.0(transitive)
+ Addedp-timeout@2.0.1(transitive)
+ Addedpify@3.0.0(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedquery-string@5.1.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsort-keys@2.0.0(transitive)
+ Addedstrict-uri-encode@1.1.0(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedtimed-out@4.0.1(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
+ Addedurl-to-options@1.0.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedrequest@^2.65.0
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)