diff --git a/.gitignore b/.gitignore index fe73828..75876a6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ public/out public/dist public/components +.idea/ diff --git a/app/controllers/home.js b/app/controllers/home.js index 91b8a14..d3e60d6 100644 --- a/app/controllers/home.js +++ b/app/controllers/home.js @@ -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"); + + }); diff --git a/app/views/index.vash b/app/views/index.vash index fdca402..9f01f89 100644 --- a/app/views/index.vash +++ b/app/views/index.vash @@ -40,10 +40,10 @@
diff --git a/package.json b/package.json index e082fa1..c7839a1 100644 --- a/package.json +++ b/package.json @@ -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": {