From 3bd21d9244cae61b30976a75f0163fab763f9f2e Mon Sep 17 00:00:00 2001 From: Sahat Yalkabov Date: Tue, 10 Dec 2013 01:16:03 -0500 Subject: [PATCH] New york times bestsellers api implementation --- app.js | 1 - controllers/api.js | 20 +++++++++----------- views/api.jade | 2 -- views/api/nyt.jade | 2 +- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app.js b/app.js index e0cb9d7a4a..ef05699816 100755 --- a/app.js +++ b/app.js @@ -69,7 +69,6 @@ app.get('/api/scraping', api.getScraping); app.get('/api/github', passportConf.isAuthorized, api.getGithub); app.get('/api/lastfm', api.getLastfm); app.get('/api/nyt', api.getNewYorkTimes); -app.get('/api/twilio', api.getTwilio); app.get('/api/etsy', api.getEtsy); app.get('/api/twitter', passportConf.isAuthenticated, api.getTwitter); app.get('/api/aviary', api.getAviary); diff --git a/controllers/api.js b/controllers/api.js index d887f78313..c93375f516 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -1,5 +1,6 @@ var config = require('../config/config'); var User = require('../models/User'); +var querystring = require('querystring'); var async = require('async'); var cheerio = require('cheerio'); var request = require('request'); @@ -144,13 +145,6 @@ exports.getGithub = function(req, res) { }; -/** - * GET /api/twilio - */ -exports.getTwilio = function(req, res) { - -}; - /** * GET /api/aviary */ @@ -173,10 +167,14 @@ exports.getEtsy = function(req, res) { * New York Times API example */ exports.getNewYorkTimes = function(req, res) { - - res.render('api/nyt', { - title: 'New York Times API', - + var query = querystring.stringify({ 'api-key': config.nyt.key, 'list-name': 'young-adult' }); + var url = 'http://api.nytimes.com/svc/books/v2/lists?' + query; + request.get(url, function(error, request, body) { + var bestSellers = JSON.parse(body); + res.render('api/nyt', { + title: 'New York Times API', + books: bestSellers.results + }); }); }; diff --git a/views/api.jade b/views/api.jade index 510e2c93ed..8e1a8e502e 100644 --- a/views/api.jade +++ b/views/api.jade @@ -22,7 +22,5 @@ block content a(href='/api/tumblr') Tumblr li a(href='/api/twitter') Twitter - li - a(href='/api/twilio') Twilio li a(href='/api/scraping') Web Scraping diff --git a/views/api/nyt.jade b/views/api/nyt.jade index 63e3ff2413..df308ef0ad 100644 --- a/views/api/nyt.jade +++ b/views/api/nyt.jade @@ -1,4 +1,4 @@ -extends ..layout +extends ../layout block content .page-header