Added ability to get gem value for an item and to turn items into gems

This commit is contained in:
Alex Corn
2018-04-01 03:22:00 -04:00
parent f6c7c74ab6
commit e97e63fe6d
2 changed files with 78 additions and 4 deletions

View File

@@ -29,3 +29,75 @@ SteamCommunity.prototype.getMarketApps = function(callback) {
} }
}, "steamcommunity"); }, "steamcommunity");
}; };
/**
*
* @param {int} appid
* @param {int|string} assetid
* @param {function} callback
*/
SteamCommunity.prototype.getGemValue = function(appid, assetid, callback) {
this._myProfile({
"endpoint": "ajaxgetgoovalue/",
"qs": {
"sessionid": this.getSessionID(),
"appid": appid,
"contextid": 6,
"assetid": assetid
},
"checkHttpError": false,
"json": true
}, null, (err, res, body) => {
if (err) {
callback(err);
return;
}
if (body.success && body.success != 1) {
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
err.eresult = err.code = body.success;
callback(err);
return;
}
if (!body.goo_value || !body.strTitle) {
callback(new Error("Malformed response"));
return;
}
callback(null, {"promptTitle": body.strTitle, "gemValue": parseInt(body.goo_value, 10)});
});
};
SteamCommunity.prototype.turnItemIntoGems = function(appid, assetid, expectedGemsValue, callback) {
this._myProfile({
"endpoint": "ajaxgrindintogoo/",
"json": true,
"checkHttpError": false
}, {
"appid": appid,
"contextid": 6,
"assetid": assetid,
"goo_value_expected": expectedGemsValue,
"sessionid": this.getSessionID()
}, (err, res, body) => {
if (err) {
callback(err);
return;
}
if (body.success && body.success != 1) {
let err = new Error(body.message || SteamCommunity.EResult[body.success]);
err.eresult = err.code = body.success;
callback(err);
return;
}
if (!body['goo_value_received '] || !body.goo_value_total) { // lol valve
callback(new Error("Malformed response"));
return;
}
callback(null, {"gemsReceived": parseInt(body['goo_value_received '], 10), "totalGems": parseInt(body.goo_value_total, 10)});
})
};

View File

@@ -458,10 +458,12 @@ SteamCommunity.prototype._myProfile = function(endpoint, form, callback) {
} }
function completeRequest(url) { function completeRequest(url) {
var options = { var options = {};
"uri": "https://steamcommunity.com" + url + "/" + endpoint, if (endpoint.endpoint) {
"method": "GET" options = endpoint;
}; options.uri = "https://steamcommunity.com" + url + "/" + endpoint.endpoint;
options.method = "GET";
}
if (form) { if (form) {
options.method = "POST"; options.method = "POST";