Skip to content

Commit

Permalink
Merge branch 'lastfm-errors'
Browse files Browse the repository at this point in the history
  • Loading branch information
dsingleton committed Jul 16, 2011
2 parents e36db46 + bef20ca commit 2c8afe3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion index.html
Expand Up @@ -18,7 +18,7 @@
<link rel="apple-touch-icon" href="icon.png" />
<link rel="shortcut icon" href="/icon.png" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="js/lastfm.js"></script>
<script src="js/now-playing.js"></script>

Expand Down
18 changes: 13 additions & 5 deletions js/lastfm.js
Expand Up @@ -13,21 +13,29 @@ LastfmAPI = function(api_key) {
LastfmAPI.prototype = {
root: 'http://ws.audioscrobbler.com/2.0/',

get: function (method, params, success)
get: function (method, params, success, error)
{
jQuery.ajax({
url: this.root,
dataType: "jsonp",
success: success,
data: jQuery.extend({
'api_key': this.api_key,
'format': 'json',
'method': method
}, params)
}, params),
// Forces JSONP errors to fire, needs re-evaluation if long polling is used
timeout: 2000
})
.success(function(response) {
(response.error ? error : success)(response);
})
.error(function() {
// JSONP limitations mean we'll only get timeout errors
console.log({error: 0, message: 'HTTP Error'});
});
},

getNowPlayingTrack: function(user, success)
getNowPlayingTrack: function(user, success, error)
{
this.get('user.recenttracks', {user: user}, function(response) {
var track = response.recenttracks.track[0];
Expand All @@ -38,6 +46,6 @@ LastfmAPI.prototype = {
else {
success(false);
}
});
}, error);
}
};
6 changes: 5 additions & 1 deletion js/now-playing.js
Expand Up @@ -15,7 +15,11 @@ NowPlaying.prototype = {

update: function()
{
this.api.getNowPlayingTrack(this.user, jQuery.proxy(this.handleResponse, this));
this.api.getNowPlayingTrack(
this.user,
jQuery.proxy(this.handleResponse, this),
function(error) { console && console.log(error); }
);
},

autoUpdate: function()
Expand Down

0 comments on commit 2c8afe3

Please sign in to comment.