Skip to content

Instantly share code, notes, and snippets.

@koenbok
Created September 8, 2010 12:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbok/570080 to your computer and use it in GitHub Desktop.
Save koenbok/570080 to your computer and use it in GitHub Desktop.
/*
AppCast Dowloader (c) 2010 Sofa BV (Koen Bok)
Description:
Returns the url for the latest version in an AppCast url.
Requirements:
jQuery > 1.4
Example:
$("#button").click(function() {
downloadLatest("http://files.madebysofa.com/public/Enstore/ETUUpdates/appcast.xml");
});
*/
function downloadLatest(appcastURL) {
var highestVersion = 0;
var downloadURL = '';
function handleError() {
alert("Could not retreive download link for: " + appcastURL);
}
$.ajax({
type: "GET",
url: appcastURL,
dataType: "xml",
error: handleError,
success: function(xml) {
$(xml).find("enclosure").each(function() {
var node = $(this);
var version = parseInt(node.attr("sparkle:version"));
var url = node.attr("url");
if (version > highestVersion) {
highestVersion = version;
downloadURL = url;
}
});
// At this point we should have a download url
if (downloadURL.indexOf("http") == -1) {
handleError()
} else {
window.location = downloadURL;
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment