Steam API code refactoring, added ownedGames API call
This commit is contained in:
@ -207,7 +207,7 @@ exports.getLastfm = function(req, res, next) {
|
||||
_.each(data.topalbums.album, function(album) {
|
||||
albums.push(album.image.slice(-1)[0]['#text']);
|
||||
});
|
||||
done(null, albums.slice(0,4));
|
||||
done(null, albums.slice(0, 4));
|
||||
},
|
||||
error: function(err) {
|
||||
done(err);
|
||||
@ -258,7 +258,7 @@ exports.getTwitter = function(req, res, next) {
|
||||
|
||||
/**
|
||||
* GET /api/paypal
|
||||
* PayPal SDK example
|
||||
* PayPal SDK example.
|
||||
*/
|
||||
|
||||
exports.getPayPal = function(req, res, next) {
|
||||
@ -272,16 +272,18 @@ exports.getPayPal = function(req, res, next) {
|
||||
'return_url': secrets.paypal.returnUrl,
|
||||
'cancel_url': secrets.paypal.cancelUrl
|
||||
},
|
||||
'transactions': [{
|
||||
'transactions': [
|
||||
{
|
||||
'description': 'Node.js Boilerplate',
|
||||
'amount': {
|
||||
'currency': 'USD',
|
||||
'total': '2.99'
|
||||
}
|
||||
}]
|
||||
}
|
||||
]
|
||||
};
|
||||
paypal.payment.create(payment_details, function (error, payment) {
|
||||
if(error){
|
||||
paypal.payment.create(payment_details, function(error, payment) {
|
||||
if (error) {
|
||||
console.log(error);
|
||||
} else {
|
||||
req.session.payment_id = payment.id;
|
||||
@ -299,14 +301,14 @@ exports.getPayPal = function(req, res, next) {
|
||||
|
||||
/**
|
||||
* GET /api/paypal/success
|
||||
* PayPal SDK example
|
||||
* PayPal SDK example.
|
||||
*/
|
||||
|
||||
exports.getPayPalSuccess = function(req, res, next) {
|
||||
var payment_id = req.session.payment_id;
|
||||
var payment_details = { 'payer_id': req.query.PayerID };
|
||||
paypal.payment.execute(payment_id, payment_details, function(error, payment){
|
||||
if(error){
|
||||
paypal.payment.execute(payment_id, payment_details, function(error, payment) {
|
||||
if (error) {
|
||||
res.render('api/paypal', {
|
||||
result: true,
|
||||
success: false
|
||||
@ -322,7 +324,7 @@ exports.getPayPalSuccess = function(req, res, next) {
|
||||
|
||||
/**
|
||||
* GET /api/paypal/cancel
|
||||
* PayPal SDK example
|
||||
* PayPal SDK example.
|
||||
*/
|
||||
|
||||
exports.getPayPalCancel = function(req, res, next) {
|
||||
@ -339,51 +341,40 @@ exports.getPayPalCancel = function(req, res, next) {
|
||||
*/
|
||||
|
||||
exports.getSteam = function(req, res) {
|
||||
var defaultSteamId = '76561197992403307';
|
||||
var steamId = _.findWhere(req.user.tokens, { kind: 'steam' }).steamId || defaultSteamId;
|
||||
var steamId = '76561197982488301';
|
||||
var query = { l: 'english', steamid: steamId, key: secrets.steam.apiKey };
|
||||
|
||||
async.parallel([
|
||||
function (callback) {
|
||||
builtQuery = querystring.stringify(query);
|
||||
request.get({url:'http://api.steampowered.com/IPlayerService/GetRecentlyPlayedGames/v0001/?' + builtQuery, json:true}, function(err, request, body) {
|
||||
if (err) return next(err);
|
||||
callback(null, body);
|
||||
async.parallel({
|
||||
playerAchievements: function(done) {
|
||||
query.appid = '49520';
|
||||
var qs = querystring.stringify(query);
|
||||
request.get({ url: 'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?' + qs, json: true }, function(error, request, body) {
|
||||
done(error, body.playerstats);
|
||||
});
|
||||
},
|
||||
function (callback) {
|
||||
query.appid = '570'; // Dota 2
|
||||
builtQuery = querystring.stringify(query);
|
||||
request.get({url:'http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?' + builtQuery, json:true}, function(err, request, body) {
|
||||
if (err) return next(err);
|
||||
delete query.appid;
|
||||
callback(null, body);
|
||||
playerSummaries: function(done) {
|
||||
query.steamids = steamId;
|
||||
var qs = querystring.stringify(query);
|
||||
request.get({ url: 'http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?' + qs, json: true }, function(error, request, body) {
|
||||
done(error, body);
|
||||
});
|
||||
},
|
||||
function (callback) {
|
||||
query.appid = '219640'; //Chivalry: Medieval Warfare
|
||||
builtQuery = querystring.stringify(query);
|
||||
request.get({url:'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?' + builtQuery, json:true}, function(err, request, body) {
|
||||
if (err) return next(err);
|
||||
delete query.appid;
|
||||
callback(null, body);
|
||||
ownedGames: function(done) {
|
||||
var qs = querystring.stringify(query);
|
||||
request.get({ url: 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/?' + qs, json: true }, function(error, request, body) {
|
||||
done(error, 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) {
|
||||
function(err, results) {
|
||||
if (err) return next(err);
|
||||
callback(null, body);
|
||||
});
|
||||
},
|
||||
],
|
||||
function (err, results) {
|
||||
console.log(require('util').inspect(results, false, null));
|
||||
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',
|
||||
items: results });
|
||||
ownedGames: results.ownedGames,
|
||||
playerAchievemments: results.playerAchievements,
|
||||
playerSummaries: results.playerSummaries
|
||||
});
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user