Comparing version 1.5.1 to 1.5.2
@@ -9,12 +9,15 @@ 'use strict'; | ||
// Uses an internal Blizzard API to retrieve basic details about a player, | ||
// through their Blizzard account ID. The API returns basic details about | ||
// the players' career - display names, levels, and portraits, for each | ||
// platform the player participated in. | ||
let findPlayer = (() => { | ||
var _ref = _asyncToGenerator(function* (req, options, name) { | ||
// Turn the last dash, or pound sign, into a URL-encoded pound sign, so we can get | ||
checkValidName(name); | ||
// Turn the pound sign into a URL-encoded pound sign, so we can get | ||
// a positive match including the account ID | ||
const nameEscaped = name.replace(/[-#](\d+)$/, '%23$1'); // # == %23 | ||
const nameEscapedUrl = name.replace('#', '%23'); | ||
const searchPath = (0, _urlJoin2.default)('/search/account-by-name', nameEscapedUrl); | ||
// Note that the pound sign here is ignored, we keep it in just to make | ||
// debug logs clearer, and because it doesn't cause any harm: | ||
const searchPath = (0, _urlJoin2.default)('/search/account-by-name', nameEscaped); | ||
log('findPlayer/http get', searchPath); | ||
@@ -37,3 +40,5 @@ | ||
return { | ||
name: name.replace('#', '-'), | ||
name: name, | ||
nameEscaped: name.replace('#', '-'), | ||
nameEscapedUrl, | ||
accounts | ||
@@ -56,3 +61,6 @@ }; | ||
var _ref2 = _asyncToGenerator(function* (req, options, platform, name) { | ||
const scrapePath = (0, _urlJoin2.default)('/career', platform, name); | ||
checkValidName(name); | ||
const nameEscaped = name.replace('#', '-'); | ||
const scrapePath = (0, _urlJoin2.default)('/career', platform, nameEscaped); | ||
log('findPlayerStats/http get', scrapePath); | ||
@@ -65,3 +73,3 @@ | ||
const stats = (0, _scraper.scrapePlayerStats)(options, html); | ||
return { name, platform, stats }; | ||
return { name, nameEscaped, platform, stats }; | ||
}); | ||
@@ -117,8 +125,9 @@ | ||
} | ||
}; | ||
// Uses an internal Blizzard API to retrieve basic details about a player, | ||
// through their Blizzard account ID. The API returns basic details about | ||
// the players' career - display names, levels, and portraits, for each | ||
// platform the player participated in. | ||
};function portraitUrl(portraitId, options) { | ||
function checkValidName(name) { | ||
if (name.indexOf('#') === -1) { | ||
throw new Error(`Invalid player name, could not find a # sign`); | ||
} | ||
}function portraitUrl(portraitId, options) { | ||
return _util2.default.format(options.portraitUrlTemplate, portraitId); | ||
@@ -125,0 +134,0 @@ }function main(callerOptions = {}) { |
@@ -0,1 +1,15 @@ | ||
# 1.5.2 | ||
1.5.2 | ||
- Normalizes name handling on all methods, making the `#` sign mandatory | ||
- Adds `nameEscaped` and `nameEscapedUrl` to method return values as appropriate, with the escaped values used internally | ||
# 1.5.1 | ||
1.5.1 | ||
- Fixes issue with some hero stat values being `null` incorrectly, due to an error in value normalization in the scraper | ||
- Reshuffled debug logging around. New `DEBUG=` values are `oversmash:*` for all logs, or `oversmash:scraper`, `oversmash:main`, and `oversmash:snapshot` respectively. | ||
# 1.5.0 | ||
@@ -2,0 +16,0 @@ |
{ | ||
"name": "oversmash", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/filp/oversmash", |
@@ -5,7 +5,7 @@ import { promisify } from 'util' | ||
const account = 'FATCOTTON420-2476' | ||
const account = 'FATCOTTON420#2476' | ||
const writeFileAsync = promisify(writeFile) | ||
async function captureSnapshots (ow) { | ||
await writeFileAsync('./tests/snapshots/profile.json', JSON.stringify(await ow.player(account.replace('-', '#')))) | ||
await writeFileAsync('./tests/snapshots/profile.json', JSON.stringify(await ow.player(account))) | ||
await writeFileAsync('./tests/snapshots/stats.json', JSON.stringify(await ow.playerStats(account, 'pc'))) | ||
@@ -12,0 +12,0 @@ } |
@@ -1,1 +0,1 @@ | ||
{"name":"FATCOTTON420-2476","accounts":[{"level":973,"portrait":"https://d1u1mce87gyfbn.cloudfront.net/game/unlocks/0x02500000000017AE.png","platform":"pc","public":true}]} | ||
{"name":"FATCOTTON420#2476","nameEscaped":"FATCOTTON420-2476","nameEscapedUrl":"FATCOTTON420%232476","accounts":[{"level":973,"portrait":"https://d1u1mce87gyfbn.cloudfront.net/game/unlocks/0x02500000000017AE.png","platform":"pc","public":true}]} |
@@ -43,3 +43,5 @@ import assert from 'assert' | ||
assert.equal(p.name, 'FATCOTTON420-2476') | ||
assert.equal(p.name, 'FATCOTTON420#2476') | ||
assert.equal(p.nameEscaped, 'FATCOTTON420-2476') | ||
assert.equal(p.nameEscapedUrl, 'FATCOTTON420%232476') | ||
assert.equal(p.accounts.length, 1) | ||
@@ -51,5 +53,6 @@ | ||
async function testPlayerStats (ow, snapshot) { | ||
const p = await ow.playerStats('FATCOTTON420-2476', 'pc') | ||
const p = await ow.playerStats('FATCOTTON420#2476', 'pc') | ||
assert.equal(p.name, 'FATCOTTON420-2476') | ||
assert.equal(p.name, 'FATCOTTON420#2476') | ||
assert.equal(p.nameEscaped, 'FATCOTTON420-2476') | ||
assert.equal(p.platform, 'pc') | ||
@@ -56,0 +59,0 @@ |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131463
395