Comparing version 1.3.3 to 1.4.0
@@ -26,13 +26,8 @@ 'use strict'; | ||
const accounts = response.map(function (account) { | ||
const accountIdentity = account.careerLink.match(options.accountIdentityRegex); | ||
if (!accountIdentity) { | ||
throw new Error('Could not parse careerLink in response'); | ||
} | ||
return { | ||
level: account.level, | ||
portrait: account.portrait, | ||
portrait: portraitUrl(account.portrait, options), | ||
displayName: account.platformDisplayName, | ||
platform: accountIdentity[1] | ||
platform: account.platform, | ||
public: account.isPublic | ||
}; | ||
@@ -52,9 +47,11 @@ }); | ||
// Scrapes the playoverwatch website for details on a players' career, for | ||
// a given region and platform. | ||
// Converts a portrait identifier (really just a filename as far as we care) | ||
// into a full url for the portrait image | ||
// Scrapes the playoverwatch website for details on a players' career, for | ||
// a given platform. | ||
let findPlayerStats = (() => { | ||
var _ref2 = _asyncToGenerator(function* (req, options, platform, region, name) { | ||
const scrapePath = (0, _urlJoin2.default)('/career', platform, region, name); | ||
var _ref2 = _asyncToGenerator(function* (req, options, platform, name) { | ||
const scrapePath = (0, _urlJoin2.default)('/career', platform, name); | ||
log('findPlayerStats/http get', scrapePath); | ||
@@ -67,6 +64,6 @@ | ||
const stats = (0, _scraper.scrapePlayerStats)(options, html); | ||
return { name, region, platform, stats }; | ||
return { name, platform, stats }; | ||
}); | ||
return function findPlayerStats(_x4, _x5, _x6, _x7, _x8) { | ||
return function findPlayerStats(_x4, _x5, _x6, _x7) { | ||
return _ref2.apply(this, arguments); | ||
@@ -94,2 +91,6 @@ }; | ||
var _util = require('util'); | ||
var _util2 = _interopRequireDefault(_util); | ||
var _scraper = require('./scraper'); | ||
@@ -108,5 +109,4 @@ | ||
percentsToInts: true, | ||
defaultRegion: 'us', | ||
defaultPlatform: 'pc', | ||
accountIdentityRegex: /^\/career\/([\w]+)\/.+$/, | ||
portraitUrlTemplate: 'https://d1u1mce87gyfbn.cloudfront.net/game/unlocks/%s.png', | ||
requestOptions: { | ||
@@ -122,4 +122,6 @@ baseUrl: 'https://playoverwatch.com/en-us', | ||
// the players' career - display names, levels, and portraits, for each | ||
// platform/region the player participated in. | ||
};function main(callerOptions = {}) { | ||
// platform the player participated in. | ||
};function portraitUrl(portraitId, options) { | ||
return _util2.default.format(options.portraitUrlTemplate, portraitId); | ||
}function main(callerOptions = {}) { | ||
const sharedOptions = _extends({}, defaultOptions, callerOptions); | ||
@@ -133,3 +135,2 @@ | ||
// This will blow-up if the caller overrides callerOptions in weird ways | ||
const defaultRegion = sharedOptions.defaultRegion; | ||
const defaultPlatform = sharedOptions.defaultPlatform; | ||
@@ -141,3 +142,2 @@ | ||
log('default region', defaultRegion); | ||
log('default platform', defaultPlatform); | ||
@@ -152,5 +152,5 @@ | ||
playerStats(name, region = defaultRegion, platform = defaultPlatform) { | ||
playerStats(name, platform = defaultPlatform) { | ||
return _asyncToGenerator(function* () { | ||
return findPlayerStats(req, sharedOptions, platform, region, name); | ||
return findPlayerStats(req, sharedOptions, platform, name); | ||
})(); | ||
@@ -157,0 +157,0 @@ } |
@@ -43,3 +43,4 @@ 'use strict'; | ||
'soldier: 76': 'soldier76', | ||
'all heroes': 'all' | ||
'all heroes': 'all', | ||
'wrecking ball': 'wreckingball' | ||
@@ -60,7 +61,7 @@ // Very lazy diacritics replacement map for the few cases where | ||
heroList(careerType) { | ||
return `#${careerType} .career-stats-section select[data-js=career-select] option`; | ||
return `#${careerType} select[data-js=career-select] option`; | ||
}, | ||
heroCards(careerType) { | ||
return `#${careerType} .career-stats-section div[data-group-id=stats]`; | ||
return `#${careerType} div[data-group-id=stats]`; | ||
} | ||
@@ -96,3 +97,6 @@ }; | ||
if (options.normalizeValues) { | ||
if (value.indexOf('%') !== -1 && !options.percentsToInts || value.indexOf(':') !== -1) { | ||
if (isNaN(value)) { | ||
// NaN becomes null for clarity | ||
return null; | ||
} else if (value.indexOf('%') !== -1 && !options.percentsToInts || value.indexOf(':') !== -1) { | ||
// If percentsToInts is not true, don't convert percentages | ||
@@ -129,2 +133,3 @@ // to integers - just pass the value through | ||
const elem = p(e); | ||
heroes[elem.attr('value')] = elem.text(); | ||
@@ -139,3 +144,3 @@ }); | ||
group.find('tbody tr').each((i, e) => { | ||
group.find('.DataTable-tableRow').each((i, e) => { | ||
const elems = p(e).find('td'); | ||
@@ -153,3 +158,3 @@ groupStats[normalizeKeyName(options, elems.first().text())] = normalizeValue(options, elems.last().text()); | ||
container.find('.data-table').each((i, e) => { | ||
container.find('.DataTable').each((i, e) => { | ||
const elem = p(e); | ||
@@ -156,0 +161,0 @@ let groupName = elem.find('.stat-title').text(); |
@@ -0,1 +1,8 @@ | ||
# 1.4.0 (May 14th 2019) | ||
- Fixes support for player portraits | ||
- Removes region-related code | ||
- Adds missing fields to player profile | ||
- Fixes errors in player stats scraping | ||
# 1.3.2 (December 29th 2017) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "oversmash", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/filp/oversmash", |
@@ -14,3 +14,3 @@ # oversmash [![npm version](https://badge.fury.io/js/oversmash.svg)](https://badge.fury.io/js/oversmash) | ||
- Ability to retrieve basic user information, such as name, portrait, level and accounts | ||
- Correctly identifies the platform and region for each account | ||
- Correctly identifies the platform for each account | ||
- Ability to retrieve detailed stats for a player, for a given region and platform | ||
@@ -42,3 +42,3 @@ - Includes **all** stats available on playoverwatch.com | ||
// Get basic details about a user, including their platform/region accounts. | ||
// Get basic details about a user, including their platform accounts. | ||
// | ||
@@ -57,6 +57,6 @@ ow.player('bob-12345').then(player => { | ||
// Get detailed stats about a user (for a specific region), including | ||
// Get detailed stats about a user, including | ||
// achievements unlocked, per-career and per-hero stats, and their | ||
// current competitive rank | ||
ow.playerStats('bob-12345', 'us', 'pc').then(player => { | ||
ow.playerStats('bob-12345', 'pc').then(player => { | ||
console.log(player) | ||
@@ -121,11 +121,11 @@ }) | ||
// Default values to use if platform & region are not passed to the playerStats | ||
// method. | ||
defaultRegion: 'us', | ||
// The url template used to build the full portrait url, where the player's Overwatch | ||
// career icon/profile image is available. | ||
// | ||
// %s is replaced with the value from the player's profile. | ||
portraitUrlTemplate: 'https://d1u1mce87gyfbn.cloudfront.net/game/unlocks/%s.png', | ||
// Default platform if none is specified in the options | ||
defaultPlatform: 'pc', | ||
// Used to extract account details from the career link returned from the | ||
// playoverwatch API | ||
accountIdentityRegex: /^\/career\/([\w]+)\/.+$/, | ||
requestOptions: { | ||
@@ -132,0 +132,0 @@ baseURL: 'https://playoverwatch.com/en-us', |
@@ -8,5 +8,5 @@ import assert from 'assert' | ||
async function testPlayerProfile (ow) { | ||
const p = await ow.player('HaventMetYou-2451') | ||
const p = await ow.player('BOB-29739') | ||
assert.equal(p.name, 'HaventMetYou-2451') | ||
assert.equal(p.name, 'BOB-29739') | ||
assert.equal(p.accounts.length, 1) | ||
@@ -16,13 +16,10 @@ } | ||
async function testPlayerStats (ow) { | ||
const p = await ow.playerStats('HaventMetYou-2451', 'us', 'pc') | ||
const p = await ow.playerStats('BOB-29739', 'pc') | ||
assert.equal(p.name, 'HaventMetYou-2451') | ||
assert.equal(p.region, 'us') | ||
assert.equal(p.name, 'BOB-29739') | ||
assert.equal(p.platform, 'pc') | ||
// Make sure we successfully extracted the competitive rank | ||
// Make sure diacritics replacement is working as intended: | ||
assert(p.stats.competitiveRank > 0) | ||
// Make sure diacritics replacement is working as intended: | ||
assert(p.stats.competitive.lucio.combat.all_damage_done) | ||
assert(p.stats.quickplay.lucio.combat.all_damage_done > 0) | ||
} | ||
@@ -29,0 +26,0 @@ |
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
20655
317