Last active
December 8, 2017 20:26
-
-
Save fcrespo82/5348246 to your computer and use it in GitHub Desktop.
Simple javascript helper to acquire iTunes data from the lookup API.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8 /> | |
<title>iTunes Live Tile</title> | |
</head> | |
<body> | |
<div id='iltdemo'> | |
Icon: <img id='image'></img><br/> | |
Name: <span id='name'></span><br/> | |
Price: <span id='price'></span><br/> | |
Link: <a id='link'>here</a><br/> | |
</div><br/><br/> | |
All attributes: <div id='allattributes'></div> | |
</body> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> | |
<script src="iTunesLiveTile.js" language='javascript'></script> | |
<script> | |
$(document).ready(function () { | |
iTunesId = '584522205' | |
iTunesLiveTile.get(iTunesId, render); | |
}); | |
function render(data) | |
{ | |
$("#image").attr('src', data['artworkUrl60']); | |
$("#name").html(data['trackName']); | |
//$("#description").html(data['description']); | |
$("#price").html(data['formattedPrice']); | |
$("#link").attr('href', data['trackViewUrl']); | |
$("#allattributes").html(JSON.stringify(data)); | |
} | |
</script> | |
</html> |
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
/* | |
* Author: Fernando Xavier de Freitas Crespo | |
* Name: iTunesLiveTile.js | |
* Description: Simple js helper to acquire iTunes data from the lookup API. | |
* Why?: Some blogs and sites write reviews about apps and put their info on | |
* their page. But sometimes the app reviewed is free only for a week and | |
* after that raises its price. This js will fetch this data every time | |
* the page is loaded so the user will know the actual price for the app. | |
*/ | |
var iTunesLiveTile = { | |
_callback: function(){}, | |
_fullUrl: function(id) { | |
var SEARCH_URL_PRE = 'https://itunes.apple.com/lookup?id='; | |
var SEARCH_URL_POST = '&country=us&callback=iTunesLiveTile._prepareData'; | |
return SEARCH_URL_PRE + id + SEARCH_URL_POST; | |
}, | |
get: function(id, callback){ | |
_callback = callback; | |
$.getScript(this._fullUrl(id)); | |
}, | |
_prepareData: function(data){ | |
item = data.results[0]; | |
_callback(item); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it doesn't work....