Merge branch 'KarlJakober-master'
* KarlJakober-master: Add profile information and owned games to Steam template Steam API template display achievements Steam API code refactoring, added ownedGames API call removes steam auth, sets up steam api requests in async Adds Steam auth and API Conflicts: views/api/index.jade
This commit is contained in:
@ -193,6 +193,13 @@ Obtaining API Keys
|
||||
- Click **✔Register**
|
||||
- Copy and paste *OAuth consumer key* and *OAuth consumer secret* keys into `config/secrets.js`
|
||||
|
||||
<hr>
|
||||
|
||||
<img src="http://www.userlogos.org/files/logos/jumpordie/steam_01.png" width="200">
|
||||
- Go to http://steamcommunity.com/dev/apikey
|
||||
- Once signed in, enter your domainm agree to terms, and click **Register**
|
||||
- Copy and paste *key* into `config.secrets.js`
|
||||
|
||||
Project Structure
|
||||
-----------------
|
||||
|
||||
|
2
app.js
2
app.js
@ -121,6 +121,8 @@ app.get('/api/aviary', apiController.getAviary);
|
||||
app.get('/api/paypal', apiController.getPayPal);
|
||||
app.get('/api/paypal/success', apiController.getPayPalSuccess);
|
||||
app.get('/api/paypal/cancel', apiController.getPayPalCancel);
|
||||
app.get('/api/steam', apiController.getSteam);
|
||||
|
||||
|
||||
/**
|
||||
* OAuth routes for sign-in.
|
||||
|
@ -37,7 +37,7 @@ passport.use(new LocalStrategy({ usernameField: 'email' }, function(email, passw
|
||||
* Sign in with Facebook.
|
||||
*/
|
||||
|
||||
passport.use(new FacebookStrategy(secrets.facebook, function (req, accessToken, refreshToken, profile, done) {
|
||||
passport.use(new FacebookStrategy(secrets.facebook, function(req, accessToken, refreshToken, profile, done) {
|
||||
if (req.user) {
|
||||
User.findOne({ $or: [{ facebook: profile.id }, { email: profile.email }] }, function(err, existingUser) {
|
||||
if (existingUser) {
|
||||
@ -205,6 +205,10 @@ passport.use(new GoogleStrategy(secrets.google, function(req, accessToken, refre
|
||||
}
|
||||
}));
|
||||
|
||||
/**
|
||||
* Sign in with Tumblr.
|
||||
*/
|
||||
|
||||
passport.use('tumblr', new OAuthStrategy({
|
||||
requestTokenURL: 'http://www.tumblr.com/oauth/request_token',
|
||||
accessTokenURL: 'http://www.tumblr.com/oauth/access_token',
|
||||
@ -224,6 +228,10 @@ passport.use('tumblr', new OAuthStrategy({
|
||||
}
|
||||
));
|
||||
|
||||
/**
|
||||
* Sign in with Foursquare.
|
||||
*/
|
||||
|
||||
passport.use('foursquare', new OAuth2Strategy({
|
||||
authorizationURL: 'https://foursquare.com/oauth2/authorize',
|
||||
tokenURL: 'https://foursquare.com/oauth2/access_token',
|
||||
|
@ -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) {
|
||||
@ -332,3 +334,47 @@ exports.getPayPalCancel = function(req, res, next) {
|
||||
canceled: true
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* GET /api/steam
|
||||
* Steam API example.
|
||||
*/
|
||||
|
||||
exports.getSteam = function(req, res) {
|
||||
var steamId = '76561197982488301';
|
||||
var query = { l: 'english', steamid: steamId, key: secrets.steam.apiKey };
|
||||
|
||||
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);
|
||||
});
|
||||
},
|
||||
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);
|
||||
});
|
||||
},
|
||||
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(err, results) {
|
||||
if (err) return next(err);
|
||||
console.log(results.ownedGames);
|
||||
console.log(results.playerSummaries);
|
||||
res.render('api/steam', {
|
||||
title: 'Steam Web API',
|
||||
ownedGames: results.ownedGames,
|
||||
playerAchievemments: results.playerAchievements,
|
||||
playerSummaries: results.playerSummaries
|
||||
});
|
||||
});
|
||||
};
|
@ -10,6 +10,7 @@ var userSchema = new mongoose.Schema({
|
||||
twitter: { type: String, unique: true, sparse: true },
|
||||
google: { type: String, unique: true, sparse: true },
|
||||
github: { type: String, unique: true, sparse: true },
|
||||
|
||||
tokens: Array,
|
||||
|
||||
profile: {
|
||||
|
32
views/api/steam.jade
Normal file
32
views/api/steam.jade
Normal file
@ -0,0 +1,32 @@
|
||||
extends ../layout
|
||||
|
||||
block content
|
||||
.page-header
|
||||
h2
|
||||
i.fa.fa-gamepad
|
||||
| Steam Web API
|
||||
|
||||
.btn-group.btn-group-justified
|
||||
a.btn.btn-primary(href='https://developer.valvesoftware.com/wiki/Steam_Web_API', target='_blank')
|
||||
i.fa.fa-check-square-o
|
||||
| Overview
|
||||
|
||||
h3 Profile Information
|
||||
.lead
|
||||
// profile name
|
||||
// profile avatar
|
||||
// online status
|
||||
|
||||
h3 Player achievements for #{playerAchievemments.gameName}
|
||||
p Returns a list of achievements for this user by app id
|
||||
ul.lead.list-unstyled
|
||||
for achievement in playerAchievemments.achievements
|
||||
if achievement.achieved
|
||||
li.text-success= achievement.name
|
||||
|
||||
h3 Owned Games
|
||||
ul.list-unstyled
|
||||
for game in ownedGames
|
||||
li
|
||||
img(src='#')
|
||||
|
Reference in New Issue
Block a user