-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
69c29a6
commit fa0c75c
Showing
4 changed files
with
55 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters