From 458d7b6db12844c9e4774292b5d9be49b57dc3d0 Mon Sep 17 00:00:00 2001 From: Alex Corn Date: Tue, 10 Jul 2018 23:28:26 -0400 Subject: [PATCH] Renamed getProfileBackground to getUserProfileBackground and added it to CSteamUser --- classes/CSteamUser.js | 34 +++++++++++++++++++++------------- components/users.js | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index 18f743b..9ca4564 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -7,29 +7,29 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) { if(typeof id !== 'string' && !Helpers.isSteamID(id)) { throw new Error("id parameter should be a user URL string or a SteamID object"); } - + if(typeof id === 'object' && (id.universe != SteamID.Universe.PUBLIC || id.type != SteamID.Type.INDIVIDUAL)) { throw new Error("SteamID must stand for an individual account in the public universe"); } - + var self = this; this.httpRequest("http://steamcommunity.com/" + (typeof id === 'string' ? "id/" + id : "profiles/" + id.toString()) + "/?xml=1", function(err, response, body) { if (err) { callback(err); return; } - + xml2js.parseString(body, function(err, result) { if(err || (!result.response && !result.profile)) { callback(err || new Error("No valid response")); return; } - + if(result.response && result.response.error && result.response.error.length) { callback(new Error(result.response.error[0])); return; } - + // Try and find custom URL from redirect var customurl = null; if(response.request.redirects && response.request.redirects.length) { @@ -43,7 +43,7 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) { callback(new Error("No valid response")); return; } - + callback(null, new CSteamUser(self, result.profile, customurl)); }); }, "steamcommunity"); @@ -51,7 +51,7 @@ SteamCommunity.prototype.getSteamUser = function(id, callback) { function CSteamUser(community, userData, customurl) { this._community = community; - + this.steamID = new SteamID(userData.steamID64[0]); this.name = processItem('steamID'); this.onlineState = processItem('onlineState'); @@ -67,7 +67,7 @@ function CSteamUser(community, userData, customurl) { this.tradeBanState = processItem('tradeBanState', 'None'); this.isLimitedAccount = processItem('isLimitedAccount') == 1; this.customURL = processItem('customURL', customurl); - + if(this.visibilityState == 3) { this.memberSince = new Date(processItem('memberSince', '0').replace(/(\d{1,2})(st|nd|th)/, "$1")); this.location = processItem('location'); @@ -79,19 +79,19 @@ function CSteamUser(community, userData, customurl) { this.realName = null; this.summary = null; } - + // Maybe handle mostPlayedGames? - + this.groups = null; this.primaryGroup = null; - + var self = this; if(userData.groups && userData.groups[0] && userData.groups[0].group) { this.groups = userData.groups[0].group.map(function(group) { if(group['$'] && group['$'].isPrimary === "1") { self.primaryGroup = new SteamID(group.groupID64[0]); } - + return new SteamID(group.groupID64[0]); }); } @@ -110,7 +110,7 @@ CSteamUser.getAvatarURL = function(hash, size, protocol) { protocol = protocol || 'http://'; hash = hash || "72f78b4c8cc1f62323f8a33f6d53e27db57c2252"; // The default "?" avatar - + var url = protocol + "steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/" + hash.substring(0, 2) + "/" + hash; if(size == 'full' || size == 'medium') { return url + "_" + size + ".jpg"; @@ -182,3 +182,11 @@ CSteamUser.prototype.getInventory = function(appID, contextID, tradableOnly, cal CSteamUser.prototype.getInventoryContents = function(appID, contextID, tradableOnly, callback) { this._community.getUserInventoryContents(this.steamID, appID, contextID, tradableOnly, callback); }; + +/** + * Get the background URL of user's profile. + * @param {function} callback + */ +CSteamUser.prototype.getProfileBackground = function(callback) { + this._community.getUserProfileBackground(this.steamID, callback); +}; diff --git a/components/users.js b/components/users.js index 2ab7807..946ecd7 100644 --- a/components/users.js +++ b/components/users.js @@ -225,7 +225,7 @@ SteamCommunity.prototype.getUserAliases = function(userID, callback) { * @param {SteamID|string} userID - The user's SteamID as a SteamID object or a string which can parse into one * @param {function} callback */ -SteamCommunity.prototype.getProfileBackground = function(userID, callback) { +SteamCommunity.prototype.getUserProfileBackground = function(userID, callback) { if (typeof userID === 'string') { userID = new SteamID(userID); }