/*
---

name: MooLastFm

description: Read your user data from Last.FM

authors: Stéphane P. Péricat (@sppericat)

license: MIT-style license.

requires: [Core, More]

provides : MooLastFm

...
*/

mooLastFm = {
	'author': 'Stephane P. Pericat',
	'version': '1.0',
	
	'api': {
		'version': '2.0',
		'rootUrl': 'http://ws.audioscrobbler.com/2.0/',
		'key': 'fa46ba355d58e768dc8930e945552d9e'
	},
	'defaultCover': 'http://cdn.last.fm/flatness/catalogue/noimage/2/default_album_small.png',
	
	call: function(method, user, callback) {
		new Request.JSONP({
			url: mooLastFm.api.rootUrl + '?method=' + method + '&user=' + user + '&api_key=' + mooLastFm.api.key + '&limit=50&format=json&callback=?',
			method: 'get',
			onComplete: function(result) {callback(result);}
		}).send();
	}
}

mooLastFm.User = new Class({
	Implements: [Options],
	options: {
		'username': null
	},
	
	initialize: function(options) {
		if(options) this.setOptions(options);
	},
	
	getRecentTracks: function(callback) {
		mooLastFm.call('user.getRecentTracks', this.options.username, callback);
	},
	
	getFavoriteArtists: function(callback) {
		mooLastFm.call('user.getTopArtists', this.options.username, callback);
	},
	
	getFavoriteAlbums: function(callback) {
		mooLastFm.call('user.getTopAlbums', this.options.username, callback);
	}
});
