Steam API code refactoring, added ownedGames API call
This commit is contained in:
@ -258,7 +258,7 @@ exports.getTwitter = function(req, res, next) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/paypal
|
* GET /api/paypal
|
||||||
* PayPal SDK example
|
* PayPal SDK example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPayPal = function(req, res, next) {
|
exports.getPayPal = function(req, res, next) {
|
||||||
@ -272,13 +272,15 @@ exports.getPayPal = function(req, res, next) {
|
|||||||
'return_url': secrets.paypal.returnUrl,
|
'return_url': secrets.paypal.returnUrl,
|
||||||
'cancel_url': secrets.paypal.cancelUrl
|
'cancel_url': secrets.paypal.cancelUrl
|
||||||
},
|
},
|
||||||
'transactions': [{
|
'transactions': [
|
||||||
|
{
|
||||||
'description': 'Node.js Boilerplate',
|
'description': 'Node.js Boilerplate',
|
||||||
'amount': {
|
'amount': {
|
||||||
'currency': 'USD',
|
'currency': 'USD',
|
||||||
'total': '2.99'
|
'total': '2.99'
|
||||||
}
|
}
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
};
|
};
|
||||||
paypal.payment.create(payment_details, function(error, payment) {
|
paypal.payment.create(payment_details, function(error, payment) {
|
||||||
if (error) {
|
if (error) {
|
||||||
@ -299,7 +301,7 @@ exports.getPayPal = function(req, res, next) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/paypal/success
|
* GET /api/paypal/success
|
||||||
* PayPal SDK example
|
* PayPal SDK example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPayPalSuccess = function(req, res, next) {
|
exports.getPayPalSuccess = function(req, res, next) {
|
||||||
@ -322,7 +324,7 @@ exports.getPayPalSuccess = function(req, res, next) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/paypal/cancel
|
* GET /api/paypal/cancel
|
||||||
* PayPal SDK example
|
* PayPal SDK example.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getPayPalCancel = function(req, res, next) {
|
exports.getPayPalCancel = function(req, res, next) {
|
||||||
@ -339,51 +341,40 @@ exports.getPayPalCancel = function(req, res, next) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
exports.getSteam = function(req, res) {
|
exports.getSteam = function(req, res) {
|
||||||
var defaultSteamId = '76561197992403307';
|
var steamId = '76561197982488301';
|
||||||
var steamId = _.findWhere(req.user.tokens, { kind: 'steam' }).steamId || defaultSteamId;
|
|
||||||
var query = { l: 'english', steamid: steamId, key: secrets.steam.apiKey };
|
var query = { l: 'english', steamid: steamId, key: secrets.steam.apiKey };
|
||||||
|
|
||||||
async.parallel([
|
async.parallel({
|
||||||
function (callback) {
|
playerAchievements: function(done) {
|
||||||
builtQuery = querystring.stringify(query);
|
query.appid = '49520';
|
||||||
request.get({url:'http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?' + builtQuery, json:true}, function(err, request, body) {
|
var qs = querystring.stringify(query);
|
||||||
if (err) return next(err);
|
request.get({ url: 'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?' + qs, json: true }, function(error, request, body) {
|
||||||
callback(null, body);
|
done(error, body.playerstats);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function (callback) {
|
playerSummaries: function(done) {
|
||||||
query.appid = '570'; // Dota 2
|
query.steamids = steamId;
|
||||||
builtQuery = querystring.stringify(query);
|
var qs = querystring.stringify(query);
|
||||||
request.get({url:'http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?' + builtQuery, json:true}, function(err, request, body) {
|
request.get({ url: 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' + qs, json: true }, function(error, request, body) {
|
||||||
if (err) return next(err);
|
done(error, body);
|
||||||
delete query.appid;
|
|
||||||
callback(null, body);
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
function (callback) {
|
ownedGames: function(done) {
|
||||||
query.appid = '219640'; //Chivalry: Medieval Warfare
|
var qs = querystring.stringify(query);
|
||||||
builtQuery = querystring.stringify(query);
|
request.get({ url: 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?' + qs, json: true }, function(error, request, body) {
|
||||||
request.get({url:'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?' + builtQuery, json:true}, function(err, request, body) {
|
done(error, body);
|
||||||
if (err) return next(err);
|
|
||||||
delete query.appid;
|
|
||||||
callback(null, body);
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
function (callback) {
|
|
||||||
delete query.steamid;
|
|
||||||
query.steamids = steamId; //this request can be supplied a set of comma seperated steam ids
|
|
||||||
builtQuery = querystring.stringify(query);
|
|
||||||
request.get({url:'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' + builtQuery, json:true}, function(err, request, body) {
|
|
||||||
if (err) return next(err);
|
|
||||||
callback(null, body);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
],
|
|
||||||
function(err, results) {
|
function(err, results) {
|
||||||
console.log(require('util').inspect(results, false, null));
|
|
||||||
if (err) return next(err);
|
if (err) return next(err);
|
||||||
else res.render('api/steam', {
|
console.log(results.ownedGames);
|
||||||
|
console.log(results.playerSummaries);
|
||||||
|
res.render('api/steam', {
|
||||||
title: 'Steam Web API',
|
title: 'Steam Web API',
|
||||||
items: results });
|
ownedGames: results.ownedGames,
|
||||||
|
playerAchievemments: results.playerAchievements,
|
||||||
|
playerSummaries: results.playerSummaries
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
Reference in New Issue
Block a user