Moved getWebApiKey to webapi.js component

This commit is contained in:
Alexander Corn 2015-12-02 21:35:35 -05:00
parent 49d2bb4252
commit 5624611421
2 changed files with 38 additions and 38 deletions

View File

@ -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(/<h2>Access Denied<\/h2>/)) {
return callback(new Error("Access Denied"));
}
var match = body.match(/<p>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;

View File

@ -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(/<h2>Access Denied<\/h2>/)) {
return callback(new Error("Access Denied"));
}
var match = body.match(/<p>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,