Skip to content

Commit

Permalink
Updated deprecated loadPartnerInventory method to use the /partnerinv…
Browse files Browse the repository at this point in the history
…entory/ endpoint
  • Loading branch information
DoctorMcKay committed Nov 2, 2024
1 parent 906cf8d commit 1db1747
Showing 1 changed file with 67 additions and 1 deletion.
68 changes: 67 additions & 1 deletion lib/classes/TradeOffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,73 @@ TradeOffer.prototype.data = function(key, value) {
* @param {function} callback
*/
TradeOffer.prototype.loadPartnerInventory = function(appid, contextid, callback) {
this.manager.loadUserInventory(this.partner, appid, contextid, true, callback);
let items = [];

let req = (start) => {
let qs = {
sessionid: this.manager._community.getSessionID(),
partner: this.partner.toString(),
appid,
contextid
};

if (start) {
qs.start = start;
}

let refererUrl = 'https://steamcommunity.com/tradeoffer/new/?partner=' + this.partner.accountid;
if (this._token) {
refererUrl += '&token=' + this._token;
}

this.manager._community.httpRequest({
method: 'GET',
uri: 'https://steamcommunity.com/tradeoffer/new/partnerinventory/',
qs,
headers: {
Referer: refererUrl
},
json: true
}, (err, response, body) => {
if (err) {
callback(err);
return;
}

if (response.statusCode != 200) {
callback(new Error('HTTP error ' + response.statusCode));
return;
}

if (!body || !body.success) {
callback(new Error('Malformed response'));
return;
}

for (let i in (body.rgInventory || {})) {
let item = body.rgInventory[i];
let descKey = [item.classid, item.instanceid || 0].join('_');
let description = (body.rgDescriptions || {})[descKey];

for (let j in description) {
item[j] = description[j];
}

item.appid = appid;
item.contextid = contextid;

items.push(new EconItem(item));
}

if (body.more) {
req(body.more_start);
} else {
callback(null, items);
}
});
};

req();
};

/**
Expand Down

0 comments on commit 1db1747

Please sign in to comment.