Skip to content

Commit

Permalink
Update API to reflect current last.fm API.
Browse files Browse the repository at this point in the history
  • Loading branch information
fxb committed May 20, 2010
1 parent 718b40f commit 8be684e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 8 deletions.
7 changes: 5 additions & 2 deletions README
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ If you want to use caching, you need to add another script:
<script type="text/javascript" src="lastfm.api.cache.js"></script> <script type="text/javascript" src="lastfm.api.cache.js"></script>


Built in JSON support should be available in modern browsers, if you want to Built in JSON support should be available in modern browsers, if you want to
be sure it's supported, include the following line: be sure it's supported, include the following:


<script type="text/javascript" src="http://www.json.org/json2.js"></script> <script type="text/javascript" src="json2.js"></script>

You can get that file at http://www.json.org/json2.js , and make sure you've
removed the first line before using it.


Now you can use the JavaScript last.fm API like this: Now you can use the JavaScript last.fm API like this:


Expand Down
6 changes: 4 additions & 2 deletions lastfm.api.cache.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ Storage.prototype.setObject = function(key, value){


/* Get an object from a Storage object. */ /* Get an object from a Storage object. */
Storage.prototype.getObject = function(key){ Storage.prototype.getObject = function(key){
return JSON.parse(this.getItem(key)); var item = this.getItem(key);

return JSON.parse(item);
} }


/* Creates a new cache object. */ /* Creates a new cache object. */
Expand Down Expand Up @@ -55,7 +57,7 @@ function LastFMCache(){
this.getExpirationTime = function(params){ this.getExpirationTime = function(params){
var method = params.method; var method = params.method;


if((/Weekly/).test(method) && /List/.test(method) == false){ if((/Weekly/).test(method) && !(/List/).test(method)){
if(typeof(params.to) != 'undefined' && typeof(params.from) != 'undefined'){ if(typeof(params.to) != 'undefined' && typeof(params.from) != 'undefined'){
return YEAR; return YEAR;
} }
Expand Down
35 changes: 31 additions & 4 deletions lastfm.api.js
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
/* /*
* *
* Copyright (c) 2008-2009, Felix Bruns <felixbruns@web.de> * Copyright (c) 2008-2010, Felix Bruns <felixbruns@web.de>
* *
*/ */


Expand Down Expand Up @@ -156,10 +156,8 @@ function LastFM(options){
array.push(encodeURIComponent(param) + "=" + encodeURIComponent(params[param])); array.push(encodeURIComponent(param) + "=" + encodeURIComponent(params[param]));
} }


params = array.join('&').replace(/%20/g, '+');

/* Set script source. */ /* Set script source. */
script.src = apiUrl + '?' + params; script.src = apiUrl + '?' + array.join('&').replace(/%20/g, '+');


/* Append script element. */ /* Append script element. */
head.appendChild(script); head.appendChild(script);
Expand Down Expand Up @@ -215,6 +213,10 @@ function LastFM(options){
signedCall('album.addTags', params, session, callbacks, 'POST'); signedCall('album.addTags', params, session, callbacks, 'POST');
}, },


getBuylinks : function(params, callbacks){
call('album.getBuylinks', params, callbacks);
},

getInfo : function(params, callbacks){ getInfo : function(params, callbacks){
call('album.getInfo', params, callbacks); call('album.getInfo', params, callbacks);
}, },
Expand All @@ -229,6 +231,15 @@ function LastFM(options){


search : function(params, callbacks){ search : function(params, callbacks){
call('album.search', params, callbacks); call('album.search', params, callbacks);
},

share : function(params, session, callbacks){
/* Build comma separated recipients string. */
if(typeof(params.recipient) == 'object'){
params.recipient = params.recipient.join(',');
}

signedCall('album.share', params, callbacks);
} }
}; };


Expand Down Expand Up @@ -389,6 +400,14 @@ function LastFM(options){
call('geo.getMetroArtistChart', params, callbacks); call('geo.getMetroArtistChart', params, callbacks);
}, },


getMetroHypeArtistChart : function(params, callbacks){
call('geo.getMetroHypeArtistChart', params, callbacks);
},

getMetroHypeTrackChart : function(params, callbacks){
call('geo.getMetroHypeTrackChart', params, callbacks);
},

getMetroTrackChart : function(params, callbacks){ getMetroTrackChart : function(params, callbacks){
call('geo.getMetroTrackChart', params, callbacks); call('geo.getMetroTrackChart', params, callbacks);
}, },
Expand Down Expand Up @@ -542,6 +561,10 @@ function LastFM(options){
signedCall('track.ban', params, session, callbacks, 'POST'); signedCall('track.ban', params, session, callbacks, 'POST');
}, },


getBuylinks : function(params, callbacks){
call('track.getBuylinks', params, callbacks);
},

getInfo : function(params, callbacks){ getInfo : function(params, callbacks){
call('track.getInfo', params, callbacks); call('track.getInfo', params, callbacks);
}, },
Expand Down Expand Up @@ -586,6 +609,10 @@ function LastFM(options){


/* User methods. */ /* User methods. */
this.user = { this.user = {
getArtistTracks : function(params, callbacks){
call('user.getArtistTracks', params, callbacks);
},

getEvents : function(params, callbacks){ getEvents : function(params, callbacks){
call('user.getEvents', params, callbacks); call('user.getEvents', params, callbacks);
}, },
Expand Down

0 comments on commit 8be684e

Please sign in to comment.