Skip to content

Instantly share code, notes, and snippets.

@omardelarosa
Last active August 29, 2015 14:19
Show Gist options
  • Save omardelarosa/551fd2b604d82f232324 to your computer and use it in GitHub Desktop.
Save omardelarosa/551fd2b604d82f232324 to your computer and use it in GitHub Desktop.
Using Pitchfork Node API
//search
var p4k = require('pitchfork')
// start the search
var search = new p4k.Search('wilco');
// listen for 'ready' event on the search
search.on('ready', function(results){
// 'results' is an array of "Review" objects. (see ./review.js for methods, etc)
// iterate through results and show the full titles
results.forEach(function(review){
// get "fullTile" of each review. .html retrieves the content of the review
console.log("Review", review.fullTitle);
// this would print out a formatted version of the review
// console.log(review.text_pretty_print());
});
});
// possible output for this script would look like this:
/*
Review Billy Bragg / Wilco: Mermaid Avenue: The Complete Sessions | Album Reviews | Pitchfork
Review Wilco: Wilco (The Album) | Album Reviews | Pitchfork
Review Wilco: iTunes Session | Album Reviews | Pitchfork
Review Wilco: The Whole Love | Album Reviews | Pitchfork
Review Wilco: Alpha Mike Foxtrot: Rare Tracks 1994–2014/What's Your 20? Essential Tracks 1994–2014 | Album Reviews | Pitchfork
*/
var p4k = require('pitchfork')
// router
albumRouter.get('/:id', function(req, res) {
var search = new p4k.Search(req.params.id);
search.promise.then(function(results){
// this just returns the plain object/JSON-friendly review
var reviews = results.map(function(r){ return r.attributes; })
res.send(reviews)
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment