﻿/// <reference path="http://www.google.com/jsapi?autoload=%7B%22modules%22%3A%5B%7B%22name%22%3A%22feeds%22%2C%22version%22%3A%221%22%2C%22nocss%22%3A%22true%22%7D%5D%7D" />


var RssFeedReader = (function() {
    function Class(url) {
        this.feed = new google.feeds.Feed(url);
    }

    Class.FORMAT = {
        "XML": google.feeds.Feed.XML_FORMAT,
        "JSON": google.feeds.Feed.JSON_FORMAT,
        "MIXED": google.feeds.Feed.MIXED_FORMAT
    }

    Class.prototype = {
        feed: null,
        load: function(callback, options) {
            if (options && options.max) this.feed.setNumEntries(options.max);
            if (options && options.format) this.feed.setResultFormat(options.format);
            this.feed.load(function(result) {
                if (result.error) throw new Error("RssFeedReaderError", "Failed to load feed(" + result.error.code + ") - " + result.error.message);
                callback(result.feed);
            });
        }
    }

    return Class;
})();