Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 32 additions & 33 deletions lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Bitskins {
return this.makeRequest('get_account_balance', body => body.data);
}

getAllItemPrices(simple) {
getAllItemPrices(simple, appId) {
function arrayToObject(object, item) {
object[item.market_hash_name] = item.price;
return object;
}

return this.makeRequest('get_all_item_prices', (body) => {
return this.makeRequest('get_all_item_prices', { appId: appId ? appId : this.appId }, (body) => {
if (simple) {
body.prices = body.prices.reduce(arrayToObject, {});
}
Expand All @@ -33,24 +33,24 @@ class Bitskins {
});
}

getMarketData(names) {
return this.makeRequest('get_price_data_for_items_on_sale', { names }, body => body.data.items);
getMarketData(names, appId) {
return this.makeRequest('get_price_data_for_items_on_sale', { names, appId: appId ? appId : this.appId }, body => body.data.items);
}

getAccountInventory(page) {
return this.makeRequest('get_my_inventory', body => body.data);
getAccountInventory(page, appId) {
return this.makeRequest('get_my_inventory', { appId: appId ? appId : this.appId }, body => body.data);
}

getInventoryOnSale(options) {
return this.makeRequest('get_inventory_on_sale', options, body => body.data);
getInventoryOnSale(options, appId) {
return this.makeRequest('get_inventory_on_sale', { appId: appId ? appId : this.appId }, options, body => body.data);
}

getSpecificItemsOnSale(item_ids) {
return this.makeRequest('get_specific_items_on_sale', { item_ids }, body => body);
return this.makeRequest('get_specific_items_on_sale', { item_ids, appId: appId ? appId : this.appId }, body => body);
}

getResetPriceItems(page) {
return this.makeRequest('get_reset_price_items', { page }, body => body.data);
return this.makeRequest('get_reset_price_items', { page, appId: appId ? appId : this.appId }, body => body.data);
}

getMoneyEvents(page) {
Expand All @@ -61,7 +61,7 @@ class Bitskins {
return this.makeRequest('request_withdrawal', { amount, withdrawal_method }, body => body.data);
}

buyItem(item_ids, prices) {
buyItem(item_ids, prices, appId) {
// if just one argument, allow { itemID: price }
if (arguments.length === 1) {
const entries = Object.entries(item_ids);
Expand All @@ -72,10 +72,10 @@ class Bitskins {
item_ids = item_ids.join(',');
prices = prices.join(',');

return this.makeRequest('buy_item', { item_ids, prices }, body => body.data);
return this.makeRequest('buy_item', { item_ids, prices, appId: appId ? appId : this.appId }, body => body.data);
}

sellItem(item_ids, prices) {
sellItem(item_ids, prices, appId) {
// if just one argument, allow { itemID: price }
if (arguments.length === 1) {
const entries = Object.entries(item_ids);
Expand All @@ -86,10 +86,10 @@ class Bitskins {
item_ids = item_ids.join(',');
prices = prices.join(',');

return this.makeRequest('list_item_for_sale', { item_ids, prices }, body => body.data);
return this.makeRequest('list_item_for_sale', { item_ids, prices, appId: appId ? appId : this.appId }, body => body.data);
}

modifySale(item_ids, prices) {
modifySale(item_ids, prices, appId) {
// if just one argument, allow { itemID: price }
if (arguments.length === 1) {
const entries = Object.entries(item_ids);
Expand All @@ -100,41 +100,41 @@ class Bitskins {
item_ids = item_ids.join(',');
prices = prices.join(',');

return this.makeRequest('modify_sale_item', { item_ids, prices }, body => body.data);
return this.makeRequest('modify_sale_item', { item_ids, prices, appId: appId ? appId : this.appId }, body => body.data);
}

withdrawItem(item_ids) {
withdrawItem(item_ids, appId) {
item_ids = item_ids.join(',');
return this.makeRequest('withdraw_item', { item_ids }, body => body.data);
return this.makeRequest('withdraw_item', { item_ids, appId: appId ? appId : this.appId }, body => body.data);
}

bumpItem(item_ids) {
bumpItem(item_ids, appId) {
item_ids = item_ids.join(',');
return this.makeRequest('bump_item', { item_ids }, body => body.data);
return this.makeRequest('bump_item', { item_ids, appId: appId ? appId : this.appId }, body => body.data);
}

getBuyHistory(page) {
return this.makeRequest('get_buy_history', { page }, body => body.data);
getBuyHistory(page, appId) {
return this.makeRequest('get_buy_history', { page, appId: appId ? appId : this.appId }, body => body.data);
}

getSellHistory(page) {
return this.makeRequest('get_sell_history', { page }, body => body.data);
getSellHistory(page, appId) {
return this.makeRequest('get_sell_history', { page, appId: appId ? appId : this.appId }, body => body.data);
}

getItemHistory(page, names, delimiter) {
return this.makeRequest('get_item_history', { page, names, delimiter }, body => body.data);
getItemHistory(page, names, delimiter, appId) {
return this.makeRequest('get_item_history', { page, names, delimiter, appId: appId ? appId : this.appId }, body => body.data);
}

getTradeDetails(trade_token, trade_id) {
return this.makeRequest('get_trade_details', { trade_token, trade_id }, body => body.data);
}

getRecentSaleInfo(market_hash_name, page) {
return this.makeRequest('get_sales_info', { market_hash_name, page }, body => body.data);
getRecentSaleInfo(market_hash_name, page, appId) {
return this.makeRequest('get_sales_info', { market_hash_name, page, appId: appId ? appId : this.appId }, body => body.data);
}

getRawPriceData(market_hash_name) {
return this.makeRequest('get_steam_price_data', { market_hash_name }, body => body.data);
getRawPriceData(market_hash_name, appId) {
return this.makeRequest('get_steam_price_data', { market_hash_name, appId: appId ? appId : this.appId }, body => body.data);
}

makeRequest(endpoint, params = {}, manipulator) {
Expand All @@ -145,8 +145,7 @@ class Bitskins {

const query = Object.assign(params, {
api_key: this.apiKey,
code: this.getCode(),
app_id: this.appId
code: this.getCode()
});

return new Promise((resolve, reject) => {
Expand All @@ -171,4 +170,4 @@ class Bitskins {
}
}

module.exports = Bitskins;
module.exports = Bitskins;