add untappd support

This commit is contained in:
Tommy Parnell
2015-07-01 20:32:42 -04:00
parent e22f77bd46
commit b6348cb9e0
4 changed files with 44 additions and 6 deletions

1
.gitignore vendored
View File

@@ -3,3 +3,4 @@ node_modules/
public/out
public/dist
public/components
.idea/

View File

@@ -1,11 +1,45 @@
var express = require('express'),
router = express.Router();
router = express.Router(),
UntappdClient = require("node-untappd"),
moment = require("moment"),
_ = require("underscore"),
cache = require('memory-cache');
module.exports = function (app) {
app.use('/', router);
};
router.get('/', function (req, res, next) {
//var articles = [new Article(), new Article()];
res.render('index', {});
if(process.env.untappdkey == undefined
|| process.env.untappdkey == null
|| process.env.untappdsecret == undefined
|| process.env.untappdsecret == null ){
return res.render('index',{});
}
var cacheCheck = cache.get('checkin');
if(cacheCheck != null){
return res.render('index', {beer:cacheCheck});
}
var untappd = new UntappdClient(false);
untappd.setClientId(process.env.untappdkey);
untappd.setClientSecret(process.env.untappdsecret);
untappd.userFeed(function(err,obj){
var validCheckin = null;
obj.response.checkins.items.forEach(function(checkin){
console.log(checkin);
if(validCheckin == null){
var checkinTime = moment.utc(checkin.created_at);
var now = moment.utc().add(-3, 'hours');
if(checkinTime > now){
validCheckin = checkin.beer.beer_name;
}
}
});
cache.put('checkin', validCheckin, 600000)
res.render('index', {beer: validCheckin})
},"tparnell");
});

View File

@@ -40,10 +40,10 @@
</ul>
</div>
<div class="pull-right-md btn-toolbar">
@* @if (!string.IsNullOrWhiteSpace(Model.CurrentBeer))
@if (model.beer != undefined && model.beer != null)
{
<a class="btn btn-warning" href="https://untappd.com/user/tparnell"><i class="fa fa-beer"></i>drinking: @Model.CurrentBeer</a>
} *@
<a class="btn btn-warning" href="https://untappd.com/user/tparnell"><i class="fa fa-beer"></i>drinking: @model.beer</a>
}
<a class="btn btn-cta-primary" href="mailto:tparnell8@gmail.com" target="_blank"><i class="fa fa-paper-plane"></i> Contact Me</a>
</div>
</div>

View File

@@ -12,8 +12,11 @@
"express": "~4.12.0",
"glob": "~5.0.3",
"method-override": "~2.3.0",
"moment": "^2.10.3",
"morgan": "~1.5.0",
"node-untappd": "^0.3.1",
"serve-favicon": "~2.2.0",
"underscore": "^1.8.3",
"vash": "^0.9.2"
},
"devDependencies": {