diff --git a/components/webapi.js b/components/webapi.js index ab6dac4..a54d62e 100644 --- a/components/webapi.js +++ b/components/webapi.js @@ -1,5 +1,43 @@ var SteamCommunity = require('../index.js'); +SteamCommunity.prototype.getWebApiKey = function(domain, callback) { + var self = this; + this.request({ + "uri": "https://steamcommunity.com/dev/apikey", + "followRedirect": false + }, function(err, response, body) { + if(self._checkHttpError(err, response, callback)) { + return; + } + + if(body.match(/
Key: ([0-9A-F]+)<\/p>/); + if(match) { + // We already have an API key registered + callback(null, match[1]); + } else { + // We need to register a new API key + self.request.post('https://steamcommunity.com/dev/registerkey', { + "form": { + "domain": domain, + "agreeToTerms": "agreed", + "sessionid": self.getSessionID(), + "Submit": "Register" + } + }, function(err, response, body) { + if(self._checkHttpError(err, response, callback)) { + return; + } + + self.getWebApiKey(domain, callback); + }); + } + }); +}; + SteamCommunity.prototype.getWebApiOauthToken = function(callback) { var self = this; diff --git a/index.js b/index.js index e737006..c6f2bb5 100644 --- a/index.js +++ b/index.js @@ -174,44 +174,6 @@ function generateSessionID() { return Math.floor(Math.random() * 1000000000); } -SteamCommunity.prototype.getWebApiKey = function(domain, callback) { - var self = this; - this.request({ - "uri": "https://steamcommunity.com/dev/apikey", - "followRedirect": false - }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { - return; - } - - if(body.match(/
Key: ([0-9A-F]+)<\/p>/); - if(match) { - // We already have an API key registered - callback(null, match[1]); - } else { - // We need to register a new API key - self.request.post('https://steamcommunity.com/dev/registerkey', { - "form": { - "domain": domain, - "agreeToTerms": "agreed", - "sessionid": self.getSessionID(), - "Submit": "Register" - } - }, function(err, response, body) { - if(self._checkHttpError(err, response, callback)) { - return; - } - - self.getWebApiKey(domain, callback); - }); - } - }); -}; - SteamCommunity.prototype.parentalUnlock = function(pin, callback) { this.request.post("https://steamcommunity.com/parental/ajaxunlock", { "json": true,