diff --git a/README.md b/README.md index ab1a07a604..85cc3aa32f 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,13 @@ Obtaining API Keys - Click **✔Register** - Copy and paste *OAuth consumer key* and *OAuth consumer secret* keys into `config/secrets.js` +
+ + +- 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 ----------------- diff --git a/app.js b/app.js index 8604328ca0..763cddeb0b 100755 --- a/app.js +++ b/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. diff --git a/config/passport.js b/config/passport.js index e086c1e2a2..26056214b4 100755 --- a/config/passport.js +++ b/config/passport.js @@ -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', diff --git a/controllers/api.js b/controllers/api.js index a9db5a6045..63bb8101a8 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -32,31 +32,31 @@ exports.getApi = function(req, res) { exports.getFoursquare = function(req, res, next) { var token = _.findWhere(req.user.tokens, { kind: 'foursquare' }); async.parallel({ - trendingVenues: function(callback) { - foursquare.Venues.getTrending('40.7222756', '-74.0022724', { limit: 50 }, token.accessToken, function(err, results) { - callback(err, results); - }); + trendingVenues: function(callback) { + foursquare.Venues.getTrending('40.7222756', '-74.0022724', { limit: 50 }, token.accessToken, function(err, results) { + callback(err, results); + }); + }, + venueDetail: function(callback) { + foursquare.Venues.getVenue('49da74aef964a5208b5e1fe3', token.accessToken, function(err, results) { + callback(err, results); + }); + }, + userCheckins: function(callback) { + foursquare.Users.getCheckins('self', null, token.accessToken, function(err, results) { + callback(err, results); + }); + } }, - venueDetail: function(callback) { - foursquare.Venues.getVenue('49da74aef964a5208b5e1fe3', token.accessToken, function(err, results) { - callback(err, results); + function(err, results) { + if (err) return next(err); + res.render('api/foursquare', { + title: 'Foursquare API', + trendingVenues: results.trendingVenues, + venueDetail: results.venueDetail, + userCheckins: results.userCheckins }); - }, - userCheckins: function(callback) { - foursquare.Users.getCheckins('self', null, token.accessToken, function(err, results) { - callback(err, results); - }); - } - }, - function(err, results) { - if (err) return next(err); - res.render('api/foursquare', { - title: 'Foursquare API', - trendingVenues: results.trendingVenues, - venueDetail: results.venueDetail, - userCheckins: results.userCheckins }); - }); }; /** @@ -90,25 +90,25 @@ exports.getFacebook = function(req, res, next) { var token = _.findWhere(req.user.tokens, { kind: 'facebook' }); graph.setAccessToken(token.accessToken); async.parallel({ - getMe: function(done) { - graph.get(req.user.facebook, function(err, me) { - done(err, me); - }); + getMe: function(done) { + graph.get(req.user.facebook, function(err, me) { + done(err, me); + }); + }, + getMyFriends: function(done) { + graph.get(req.user.facebook + '/friends', function(err, friends) { + done(err, friends.data); + }); + } }, - getMyFriends: function(done) { - graph.get(req.user.facebook + '/friends', function(err, friends) { - done(err, friends.data); + function(err, results) { + if (err) return next(err); + res.render('api/facebook', { + title: 'Facebook API', + me: results.getMe, + friends: results.getMyFriends }); - } - }, - function(err, results) { - if (err) return next(err); - res.render('api/facebook', { - title: 'Facebook API', - me: results.getMe, - friends: results.getMyFriends }); - }); }; /** @@ -185,53 +185,53 @@ exports.getNewYorkTimes = function(req, res, next) { exports.getLastfm = function(req, res, next) { var lastfm = new LastFmNode(secrets.lastfm); async.parallel({ - artistInfo: function(done) { - lastfm.request("artist.getInfo", { - artist: 'Epica', - handlers: { - success: function(data) { - done(null, data); - }, - error: function(err) { - done(err); + artistInfo: function(done) { + lastfm.request("artist.getInfo", { + artist: 'Epica', + handlers: { + success: function(data) { + done(null, data); + }, + error: function(err) { + done(err); + } } - } - }); + }); + }, + artistTopAlbums: function(done) { + lastfm.request("artist.getTopAlbums", { + artist: 'Epica', + handlers: { + success: function(data) { + var albums = []; + _.each(data.topalbums.album, function(album) { + albums.push(album.image.slice(-1)[0]['#text']); + }); + done(null, albums.slice(0, 4)); + }, + error: function(err) { + done(err); + } + } + }); + } }, - artistTopAlbums: function(done) { - lastfm.request("artist.getTopAlbums", { - artist: 'Epica', - handlers: { - success: function(data) { - var albums = []; - _.each(data.topalbums.album, function(album) { - albums.push(album.image.slice(-1)[0]['#text']); - }); - done(null, albums.slice(0,4)); - }, - error: function(err) { - done(err); - } - } + function(err, results) { + if (err) return next(err.message); + var artist = { + name: results.artistInfo.artist.name, + image: results.artistInfo.artist.image.slice(-1)[0]['#text'], + tags: results.artistInfo.artist.tags.tag, + bio: results.artistInfo.artist.bio.summary, + stats: results.artistInfo.artist.stats, + similar: results.artistInfo.artist.similar.artist, + topAlbums: results.artistTopAlbums + }; + res.render('api/lastfm', { + title: 'Last.fm API', + artist: artist }); - } - }, - function(err, results) { - if (err) return next(err.message); - var artist = { - name: results.artistInfo.artist.name, - image: results.artistInfo.artist.image.slice(-1)[0]['#text'], - tags: results.artistInfo.artist.tags.tag, - bio: results.artistInfo.artist.bio.summary, - stats: results.artistInfo.artist.stats, - similar: results.artistInfo.artist.similar.artist, - topAlbums: results.artistTopAlbums - }; - res.render('api/lastfm', { - title: 'Last.fm API', - artist: artist }); - }); }; /** @@ -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': [{ - 'description': 'Node.js Boilerplate', - 'amount': { - 'currency': 'USD', - 'total': '2.99' + '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) { @@ -331,4 +333,48 @@ exports.getPayPalCancel = function(req, res, next) { result: true, 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 + }); + }); }; \ No newline at end of file diff --git a/models/User.js b/models/User.js index 543a393a6e..013bb29064 100644 --- a/models/User.js +++ b/models/User.js @@ -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: { diff --git a/views/api/steam.jade b/views/api/steam.jade new file mode 100644 index 0000000000..52e633f480 --- /dev/null +++ b/views/api/steam.jade @@ -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='#') +