From 0cb5eef1f8c82d4036b60273c05c9437b13e5529 Mon Sep 17 00:00:00 2001 From: Alexander Corn Date: Wed, 17 Dec 2014 03:07:49 -0500 Subject: [PATCH] Added _myProfile helper to make calls to the user's profile URL --- index.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/index.js b/index.js index 30c7718..de6c650 100644 --- a/index.js +++ b/index.js @@ -130,4 +130,22 @@ SteamCommunity.prototype._checkCommunityError = function(html, callback) { return false; }; +SteamCommunity.prototype._myProfile = function(endpoint, form, callback) { + var self = this; + this._request("https://steamcommunity.com/my", {"followRedirect": false}, function(err, response, body) { + if(err || response.statusCode != 302) { + callback(err || "HTTP error " + response.statusCode); + return; + } + + var match = response.headers.location.match(/steamcommunity\.com(\/(id|profiles)\/[^\/]+)\/?/); + if(!match) { + callback("Can't get profile URL"); + return; + } + + (form ? self._request.post : self._request)("https://steamcommunity.com" + match[1] + "/" + endpoint, form ? {"form": form} : {}, callback); + }); +}; + require('./classes/CSteamGroup.js');