Compare commits

...

15 Commits

Author SHA1 Message Date
Alexander Corn
e789d07833 2.0.0 2015-05-30 23:53:59 -04:00
Alexander Corn
88059596b3 Use a string for the steamguard value instead of an object 2015-05-30 23:45:46 -04:00
Alexander Corn
399cc5ee84 1.0.8 2015-05-29 01:03:22 -04:00
Alexander Corn
a24bb9d4ad Fixed API key registration not working 2015-05-29 01:03:07 -04:00
Alexander Corn
81eb26b30d 1.0.7 2015-05-25 13:43:38 -04:00
Alexander Corn
0c95e75e39 Added getNotifications method 2015-05-25 13:37:01 -04:00
Alexander Corn
2eaa5b057d Added resetItemNotifications method 2015-05-25 13:20:47 -04:00
Alexander Corn
d5592246cf 1.0.6 2015-05-16 00:44:42 -04:00
Alexander Corn
22ab86434a Fixed repository URL 2015-05-16 00:44:33 -04:00
Alexander Corn
d367ceb2a6 1.0.5 2015-05-11 15:56:57 -04:00
Alexander Corn
5ab5a6d401 Made callback optional for parentalUnlock 2015-05-11 15:56:41 -04:00
Alexander Corn
a88a39c62c 1.0.4 2015-05-11 15:48:13 -04:00
Alexander Corn
5f4f4a03a4 Added parentalUnlock method 2015-05-11 15:48:00 -04:00
Alexander Corn
079db4b7bf 1.0.3 2015-05-11 01:09:58 -04:00
Alexander Corn
22ba30f5da Added getWebApiKey method 2015-05-11 01:07:14 -04:00
2 changed files with 117 additions and 5 deletions

118
index.js
View File

@@ -13,8 +13,9 @@ function SteamCommunity() {
}
SteamCommunity.prototype.login = function(details, callback) {
if(details.steamID && details.sentry) {
this._jar.setCookie(Request.cookie('steamMachineAuth' + details.steamID.getSteamID64() + '=' + encodeURIComponent(details.sentry)), 'https://steamcommunity.com');
if(details.steamguard) {
var parts = details.steamguard.split('||');
this._jar.setCookie(Request.cookie('steamMachineAuth' + parts[0] + '=' + encodeURIComponent(parts[1])), 'https://steamcommunity.com');
}
var self = this;
@@ -80,7 +81,7 @@ SteamCommunity.prototype.login = function(details, callback) {
for(var i = 0; i < cookies.length; i++) {
var parts = cookies[i].split('=');
if(parts[0] == 'steamMachineAuth' + self.steamID) {
steamguard = {"steamID": self.steamID, "sentry": decodeURIComponent(parts[1])};
steamguard = self.steamID.toString() + '||' + decodeURIComponent(parts[1]);
break;
}
}
@@ -121,6 +122,117 @@ function generateSessionID() {
return Math.floor(Math.random() * 1000000000);
};
SteamCommunity.prototype.getWebApiKey = function(domain, callback) {
var self = this;
this._request("https://steamcommunity.com/dev/apikey", function(err, response, body) {
if(err || response.statusCode != 200) {
return callback(err.message || "HTTP error " + response.statusCode);
}
if(body.match(/<h2>Access Denied<\/h2>/)) {
return callback("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(err || response.statusCode >= 400) {
return callback(err.message || "HTTP error " + response.statusCode);
}
self.getWebApiKey(domain, callback);
});
}
});
};
SteamCommunity.prototype.parentalUnlock = function(pin, callback) {
this._request.post("https://steamcommunity.com/parental/ajaxunlock", {
"json": true,
"form": {
"pin": pin
}
}, function(err, response, body) {
if(!callback) {
return;
}
if(err || response.statusCode != 200) {
return callback(err.message || "HTTP error " + response.statusCode);
}
if(!body || typeof body.success !== 'boolean') {
return callback("Invalid response");
}
if(!body.success) {
return callback("Incorrect PIN");
}
callback();
}.bind(this));
};
SteamCommunity.prototype.getNotifications = function(callback) {
this._request.get("https://steamcommunity.com/actions/RefreshNotificationArea", function(err, response, body) {
if(err || response.statusCode != 200) {
return callback(err.message || "HTTP error " + response.statusCode);
}
var notifications = {
"comments": 0,
"items": 0,
"invites": 0,
"gifts": 0,
"chat": 0,
"trades": 0
};
var items = {
"comments": /(\d+) new comments?/,
"items": /(\d+) new items? in your inventory/,
"invites": /(\d+) new invites?/,
"gifts": /(\d+) new gifts?/,
"chat": /(\d+) unread chat messages?/,
"trades": /(\d+) new trade notifications?/
};
var match;
for(var i in items) {
if(match = body.match(items[i])) {
notifications[i] = parseInt(match[1], 10);
}
}
callback(null, notifications);
});
};
SteamCommunity.prototype.resetItemNotifications = function(callback) {
this._request.get("https://steamcommunity.com/my/inventory", function(err, response, body) {
if(!callback) {
return;
}
if(err || response.statusCode != 200) {
callback(err.message || "HTTP error " + response.statusCode);
} else {
callback();
}
});
};
SteamCommunity.prototype._checkCommunityError = function(html, callback) {
if(html.match(/<h1>Sorry!<\/h1>/)) {
var match = html.match(/<h3>(.+)<\/h3>/);

View File

@@ -1,6 +1,6 @@
{
"name": "steamcommunity",
"version": "1.0.2",
"version": "2.0.0",
"description": "Provides an interface for logging into and interacting with the Steam Community website",
"keywords": ["steam", "steam community"],
"homepage": "https://github.com/DoctorMcKay/node-steamcommunity",
@@ -10,7 +10,7 @@
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Doctor_McKay/node-steamcommunity.git"
"url": "https://github.com/DoctorMcKay/node-steamcommunity.git"
},
"dependencies": {
"request": "2.51.x",