Permalink
Browse files

Update API to reflect current last.fm API.

  • Loading branch information...
1 parent 718b40f commit 8be684e56cb2a4c2cd42047f80eacb216d84c4fa @fxb committed May 20, 2010
Showing with 40 additions and 8 deletions.
  1. +5 −2 README
  2. +4 −2 lastfm.api.cache.js
  3. +31 −4 lastfm.api.js
View
@@ -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>
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:
View
@@ -11,7 +11,9 @@ Storage.prototype.setObject = function(key, value){
/* Get an object from a Storage object. */
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. */
@@ -55,7 +57,7 @@ function LastFMCache(){
this.getExpirationTime = function(params){
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'){
return YEAR;
}
View
@@ -1,6 +1,6 @@
/*
*
- * Copyright (c) 2008-2009, Felix Bruns <felixbruns@web.de>
+ * Copyright (c) 2008-2010, Felix Bruns <felixbruns@web.de>
*
*/
@@ -156,10 +156,8 @@ function LastFM(options){
array.push(encodeURIComponent(param) + "=" + encodeURIComponent(params[param]));
}
- params = array.join('&').replace(/%20/g, '+');
-
/* Set script source. */
- script.src = apiUrl + '?' + params;
+ script.src = apiUrl + '?' + array.join('&').replace(/%20/g, '+');
/* Append script element. */
head.appendChild(script);
@@ -215,6 +213,10 @@ function LastFM(options){
signedCall('album.addTags', params, session, callbacks, 'POST');
},
+ getBuylinks : function(params, callbacks){
+ call('album.getBuylinks', params, callbacks);
+ },
+
getInfo : function(params, callbacks){
call('album.getInfo', params, callbacks);
},
@@ -229,6 +231,15 @@ function LastFM(options){
search : function(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);
}
};
@@ -389,6 +400,14 @@ function LastFM(options){
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){
call('geo.getMetroTrackChart', params, callbacks);
},
@@ -542,6 +561,10 @@ function LastFM(options){
signedCall('track.ban', params, session, callbacks, 'POST');
},
+ getBuylinks : function(params, callbacks){
+ call('track.getBuylinks', params, callbacks);
+ },
+
getInfo : function(params, callbacks){
call('track.getInfo', params, callbacks);
},
@@ -586,6 +609,10 @@ function LastFM(options){
/* User methods. */
this.user = {
+ getArtistTracks : function(params, callbacks){
+ call('user.getArtistTracks', params, callbacks);
+ },
+
getEvents : function(params, callbacks){
call('user.getEvents', params, callbacks);
},

0 comments on commit 8be684e

Please sign in to comment.