Skip to content

Commit

Permalink
Added addFreeLicense method
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Jan 21, 2019
1 parent 69c29a6 commit fa0c75c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,12 @@ redeemable, the callback will be invoked with an `Error` passed as the first par
**v1.5.0 or later is required to use this method**

Updates your account's display languages for the Steam store.

### addFreeLicense(subID[, callback])
- `subID` - The ID of the free-on-demand package you would like to claim
- `callback` - Optional. Called when the request completes.
- `err` - An `Error` object on failure, or `null` on success

**v2.0.0 or later is required to use this method**

Request to add an eligible free-on-demand package to your Steam account.
37 changes: 37 additions & 0 deletions components/licenses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const StdLib = require('@doctormckay/stdlib');

const SteamStore = require('../index.js');

/**
* Add an eligible free-on-demand license to your Steam account.
* @param {int} subID - The ID of the free-on-demand sub you want to claim
* @param {function} [callback]
* @returns {Promise}
*/
SteamStore.prototype.addFreeLicense = function(subID, callback) {
return StdLib.Promises.callbackPromise(null, callback, true, (accept, reject) => {
this.request.post({
"uri": "https://store.steampowered.com/checkout/addfreelicense",
"form": {
"action": "add_to_cart",
"sessionid": this.getSessionID(),
"subid": subID
}
}, (err, response, body) => {
if (this._checkHttpError(err, response, reject)) {
return;
}

let match = body.match(/<span class="error">([^<]+)<\/span>/);
if (match) {
return reject(new Error(match[1]));
}

if (!body.includes('<h2>Success!</h2>')) {
return reject(new Error('Malformed response'));
}

return accept();
});
});
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ SteamStore.prototype._checkHttpError = function(err, response, callback) {

require('./components/account.js');
require('./components/gifts.js');
require('./components/licenses.js');
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "steamstore",
"version": "1.7.4",
"version": "2.0.0",
"private": true,
"description": "Interacts with the store.steampowered.com site for account management",
"keywords": [
"steam",
Expand All @@ -23,8 +24,12 @@
"url": "https://github.com/DoctorMcKay/node-steamstore.git"
},
"dependencies": {
"@doctormckay/stdlib": "^1.7.0",
"cheerio": "^0.22.0",
"request": "^2.87.0",
"steamid": "^1.0.0"
"request": "^2.88.0",
"steamid": "^1.1.0"
},
"engines": {
"node": ">=8.0.0"
}
}

0 comments on commit fa0c75c

Please sign in to comment.