add untappd support
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -3,3 +3,4 @@ node_modules/
|
||||
public/out
|
||||
public/dist
|
||||
public/components
|
||||
.idea/
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
});
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user