Created
February 11, 2019 20:05
-
-
Save thomo/cae8c7c13b14e330726ca3dd74e1293f to your computer and use it in GitHub Desktop.
Patch retired Yahoo yql API in MagicMirror v1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//jQuery extension to fetch an rss feed and return it as json via YQL | |
//created by [email protected] | |
(function($) { | |
$.extend({ | |
feedToJson: function(options, callback) { | |
if ($.isFunction(options)) { | |
callback = options; | |
options = null; | |
} | |
options = $.extend($.feedToJson.defaults,options); | |
var url = options.yqlURL + options.yqlQS + encodeURIComponent(options.feed) ; | |
return $.getJSON(url, function(data){ | |
// console.log(data); | |
data.item = data.items; | |
$.isFunction(callback) && callback(data); //allows the callback function to be the only option | |
$.isFunction(options.success) && options.success(data); | |
}); | |
} | |
}); | |
//defaults | |
$.feedToJson.defaults = { | |
yqlURL : 'https://api.rss2json.com/v1/api.json', //yql | |
yqlQS : '?rss_url=', //yql query string | |
feed:'http://instagr.am/tags/tacos/feed/recent.rss', //instagram recent posts tagged 'tacos' | |
cachebuster: Math.floor((new Date().getTime()) / 1200 / 1000), //yql caches feeds, so we change the feed url every 20min | |
success:null //success callback | |
}; | |
})(jQuery); | |
// eo feedToJson |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment