STP iOS Recent Reviews

by Adam Patridge

HTML

<script src="https://cdn.rawgit.com/lodash/lodash/2.4.1/dist/lodash.min.js"></script>
<script src="https://cdn.rawgit.com/moappi/jquery.json2html/master/jquery.json2html.js"></script>
<ul id="reviews"></ul>

JavaScript

jQuery.fn.outerHTML = function(s) {
    return s
        ? this.before(s).remove()
        : jQuery("<p>").append(this.eq(0).clone()).html();
};
$(function() {
    var feedUrl = "https://itunes.apple.com/us/rss/customerreviews/id=646121874/sortBy=mostRecent/xml";
    var maxItems = 30;
    var dateCutoff = new Date(2015, 00, 01); // month is 0-based, because evil
    var $reviews = $("#reviews");
    console.log($reviews);
    var getFeedJson = $.ajax({url: "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=" + maxItems + "&scoring=h&output=json&q=" + encodeURIComponent(feedUrl) + "&hl=en&callback=?", dataType: "json"});
    getFeedJson.done(function(feed) {
        var reviews = _.chain(feed.responseData.feed.entries)
            .rest() // Skip the first entry, since it is actually header HTML.
            .filter(function(val) { // Grab since cut-off date.
                var entryDate = new Date(val.publishedDate);
                return entryDate.getTime() > dateCutoff.getTime(); // Compare by ms since 1/1/1970.
            })
            .map(function(val) {
                return {
                    // WHERE IS RATING!?
                    "author": val.author,
                    "date": new Date(val.publishedDate),
                    "html": val.content // Grab the HTML entries.
                };
            })
            .map(function(val) {
                var $val = $(val.html);
                var $titleLink = $val.find("a");
                var title = $titleLink.text();
                var url = $titleLink.attr("href"); // This might just be the overall app store listing.
                var body = $val.find("font:eq(1)").text();
                return {
                    author: val.author,
                    url: url,
                    title: title,
                    body: body
                };
            })
            .forEach(function(val) {
                var $li = $("<li>");
                var $title =...