diff --git a/classes/CSteamUser.js b/classes/CSteamUser.js index 7fa2746..5d493fe 100644 --- a/classes/CSteamUser.js +++ b/classes/CSteamUser.js @@ -107,124 +107,26 @@ CSteamUser.prototype.getAvatarURL = function(size, protocol) { }; CSteamUser.prototype.addFriend = function(callback) { - var self = this; - this._community.request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 0, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) { - if(!callback) { - return; - } - - if(self._community._checkHttpError(err, response, callback)) { - return; - } - - var json; - try { - json = JSON.parse(body); - } catch(e) { - callback(e); - return; - } - - if(json.success) { - callback(null); - } else { - callback(new Error("Unknown error")); - } - }); + this._community.addFriend(this.steamID, callback); }; CSteamUser.prototype.acceptFriendRequest = function(callback) { - var self = this; - this._community.request.post('https://steamcommunity.com/actions/AddFriendAjax', {"form": {"accept_invite": 1, "sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) { - if(!callback) { - return; - } - - if(self._community._checkHttpError(err, response, callback)) { - return; - } - - callback(null); - }); + this._community.acceptFriendRequest(this.steamID, callback); }; CSteamUser.prototype.removeFriend = function(callback) { - var self = this; - this._community.request.post('https://steamcommunity.com/actions/RemoveFriendAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) { - if(!callback) { - return; - } - - if(self._community._checkHttpError(err, response, callback)) { - return; - } - - callback(null); - }); + this._community.removeFriend(this.steamID, callback); + }; CSteamUser.prototype.blockCommunication = function(callback) { - var self = this; - this._community.request.post('https://steamcommunity.com/actions/BlockUserAjax', {"form": {"sessionID": this._community.getSessionID(), "steamid": this.steamID.toString()}}, function(err, response, body) { - if(!callback) { - return; - } - - if(self._community._checkHttpError(err, response, callback)) { - return; - } - - callback(null); - }); + this._community.blockCommunication(this.steamID, callback); }; CSteamUser.prototype.unblockCommunication = function(callback) { - var form = {"action": "unignore"}; - form['friends[' + this.steamID.toString() + ']'] = 1; - - this._community._myProfile('friends/blocked/', form, function(err, response, body) { - if(!callback) { - return; - } - - if(err || response.statusCode >= 400) { - callback(err || new Error("HTTP error " + response.statusCode)); - return; - } - - callback(null); - }); + this._community.unblockCommunication(this.steamID, callback); }; CSteamUser.prototype.comment = function(message, callback) { - this._community.request.post('https://steamcommunity.com/comment/Profile/post/' + this.steamID.toString() + '/-1/', {"form": { - "comment": message, - "count": 6, - "sessionid": this._community.getSessionID() - }}, function(err, response, body) { - if(!callback) { - return; - } - - if(err || response.statusCode != 200) { - callback(err || new Error("HTTP error " + response.statusCode)); - return; - } - - var json; - try { - json = JSON.parse(body); - } catch(e) { - callback(e); - return; - } - - if(json.success) { - callback(null); - } else if(json.error) { - callback(new Error(json.error)); - } else { - callback(new Error("Unknown error")); - } - }); + this._community.postUserComment(this.steamID, message, callback); }; diff --git a/components/users.js b/components/users.js new file mode 100644 index 0000000..01718aa --- /dev/null +++ b/components/users.js @@ -0,0 +1,139 @@ +var SteamCommunity = require('../index.js'); + +SteamCommunity.prototype.addFriend = function(userID, callback) { + var self = this; + this.request.post({ + "uri": "https://steamcommunity.com/actions/AddFriendAjax", + "form": { + "accept_invite": 0, + "sessionID": this.getSessionID(), + "steamid": userID.toString() + }, + "json": true + }, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + return; + } + + if(body.success) { + callback(null); + } else { + callback(new Error("Unknown error")); + } + }); +}; + +SteamCommunity.prototype.acceptFriendRequest = function(userID, callback) { + var self = this; + this.request.post({ + "uri": "https://steamcommunity.com/actions/AddFriendAjax", + "form": { + "accept_invite": 1, + "sessionID": this.getSessionID(), + "steamid": userID.toString() + } + }, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + return; + } + + callback(null); + }); +}; + +SteamCommunity.prototype.removeFriend = function(userID, callback) { + var self = this; + this.request.post({ + "uri": "https://steamcommunity.com/actions/RemoveFriendAjax", + "form": { + "sessionID": this.getSessionID(), + "steamid": userID.toString() + } + }, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + return; + } + + callback(null); + }); +}; + +SteamCommunity.prototype.blockCommunication = function(userID, callback) { + var self = this; + this.request.post({ + "uri": "https://steamcommunity.com/actions/BlockUserAjax", + "form": { + "sessionID": this.getSessionID(), + "steamid": userID.toString() + } + }, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + return; + } + + callback(null); + }); +}; + +SteamCommunity.prototype.unblockCommunication = function(userID, callback) { + var form = {"action": "unignore"}; + form['friends[' + userID.toString() + ']'] = 1; + + this._myProfile('friends/blocked/', form, function(err, response, body) { + if(!callback) { + return; + } + + if(err || response.statusCode >= 400) { + callback(err || new Error("HTTP error " + response.statusCode)); + return; + } + + callback(null); + }); +}; + +SteamCommunity.prototype.postUserComment = function(userID, message, callback) { + var self = this; + this.request.post({ + "uri": "https://steamcommunity.com/comment/Profile/post/" + userID.toString() + "/-1", + "form": { + "comment": message, + "count": 6, + "sessionid": this.getSessionID() + }, + "json": true + }, function(err, response, body) { + if(!callback) { + return; + } + + if(self._checkHttpError(err, response, callback)) { + return; + } + + if(body.success) { + callback(null); + } else if(bpdy.error) { + callback(new Error(body.error)); + } else { + callback(new Error("Unknown error")); + } + }); +}; \ No newline at end of file diff --git a/index.js b/index.js index a765b55..6926424 100644 --- a/index.js +++ b/index.js @@ -322,6 +322,7 @@ require('./components/chat.js'); require('./components/profile.js'); require('./components/market.js'); require('./components/groups.js'); +require('./components/users.js'); require('./classes/CMarketItem.js'); require('./classes/CMarketSearchResult.js'); require('./classes/CSteamGroup.js');