Skip to content

Commit

Permalink
Added sendGift
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorMcKay committed Feb 27, 2016
1 parent d5dde8f commit 442f04b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,21 @@ Checks whether your account has a phone number linked or not.
- `ignoredApps` - An array containing the AppID of each app which you've clicked "Not Interested" on
- `tags` - An object containing the tags which are suggested for you. Keys are TagIDs, values are the tag names.

**v1.1.0 or later is required to use this method**

Gets information about products that your account owns, ignores, wants, or is recommended.

### sendGift(giftID, recipient, recipientName, message, closing, signature[, callback])
- `giftID` - The gift's ID (also known as the asset ID of the item in your Steam gift inventory)
- `recipient` - Either the recipient's email address (to send it over email) or the recipient's SteamID (as a `SteamID` object or string) to send it over Steam. If using a SteamID, you need to be friends with the user.
- `recipientName` - The name of the recipient to put in the gift email/popup
- `message` - The message to include in the email/popup
- `closing` - The closing to include in the email/popup
- `signature` - Your name to include in the email/popup
- `callback` - Optional. Called when the request completes.
- `err` - An `Error` object on failure, or `null` on success

**v1.4.0 or later is required to use this method**

Sends a Steam gift in your inventory to another user. The gift will remain in your inventory until the recipient accepts it.
You can re-send a gift which you've already sent. Gifts don't have to be tradable in order to be sent.
52 changes: 52 additions & 0 deletions components/gifts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
var SteamStore = require('../index.js');
var SteamID = require('steamid');

SteamStore.prototype.sendGift = function(giftID, recipient, recipientName, message, closing, signature, callback) {
var self = this;

var accountid = 0;
var email = "";

if (typeof recipient === 'string' && recipient.match(/@/)) {
// It's an email address
email = recipient;
} else if (!recipient.accountid) {
// Recipient is not a SteamID object. Might be a string, might be a BigNumber object, etc.
accountid = new SteamID(recipient.toString()).accountid;
} else {
// Recipient is a SteamID object.
accountid = recipient.accountid;
}

this.request.post({
"uri": "https://store.steampowered.com/checkout/sendgiftsubmit/",
"headers": {
"Referer": "https://store.steampowered.com/checkout/sendgift/" + giftID
},
"form": {
"GifteeAccountID": accountid,
"GifteeEmail": email,
"GifteeName": recipientName,
"GiftMessage": message,
"GiftSentiment": closing,
"GiftSignature": signature,
"GiftGID": giftID,
"SessionID": this.getSessionID()
},
"json": true
}, function(err, response, body) {
if (!callback) {
return;
}

if (self._checkHttpError(err, response, callback)) {
return;
}

if (body.success == 1) {
callback(null);
} else {
callback(new Error("EResult " + body.success));
}
});
};
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,4 @@ SteamStore.prototype._checkHttpError = function(err, response, callback) {
};

require('./components/account.js');
require('./components/gifts.js');

0 comments on commit 442f04b

Please sign in to comment.