An Angular LastFm API service. The services covered are those not requiring authentication. A Last.FM API Key is required.
Add as dependency...
var app = angular.module('app', ['lastfm']);Set your API key in a config block...
app.config(function (LastFMProvider) {
LastFMProvider.setAPIKey('YOUR_API_KEY');
});Inject into controllers...
app.controller('MainCtrl', function (Lastfm) {
//
});Each call will return a promise.
// e.g.
$ctrl.albums = LastFM.Artist.getTopAlbums('The Cure');
// or
LastFM.Artist.getTopAlbums('The Cure')
.then(albums){
console.log(albums);
});Send in an object to set any options - see Last.FM for options available for each call.
// e.g.
LastFM.Artist.getSimilar('The Cure', {limit: 10})
.then(artists){
console.log(artists);
});If a MusicBrainz Identifier (mbid) is accepted by a method, the other parameters are not required. An mbid always takes precedence over other parameters.
// e.g.
LastFM.Track.getSimilar('The Cure', 'Faith')
.then(tracks){
console.log(tracks);
});
// Or using mbid...
LastFM.Track.getSimilar('e7da35ed-ad25-4721-a3b2-43784fa4f856')
.then(tracks){
console.log(tracks);
});The main methods dig out and return the relevant data from the last.fm response. If you require the full response, append an underscore to the method name.
// e.g.
LastFM.Artist._getTopAlbums('The Cure')
.then(function(response){
// To get the array of albums,
// look for...
console.log(response.data.topalbums.album);
});The following methods are available:
- LastFM.Album.getInfo(artist or mbid, album, options);
- LastFM.Album.getTopTags(artist or mbid, album, options);
- LastFM.Album.search(album, options);
- LastFM.Artist.getInfo(artist or mbid, options);
- LastFM.Artist.getSimilar(artist or mbid, options);
- LastFM.Artist.getTopAlbums(artist or mbid, options);
- LastFM.Artist.getTopTags(artist or mbid, options);
- LastFM.Artist.getTopTracks(artist or mbid, options);
- LastFM.Artist.search(artist, options);
- LastFM.Charts.getTopArtists(options);
- LastFM.Charts.getTopTags(options);
- LastFM.Charts.getTopTracks(options);
- LastFM.Geo.getTopArtists(country, options);
- LastFM.Geo.getTopTracks(country, options);
- LastFM.Track.getInfo(artist or mbid, track, options);
- LastFM.Track.getSimilar(artist or mbid, track, options);
- LastFM.Track.getTopTags(artist or mbid, track, options);
- LastFM.Track.search(track, options);
1.1.0
Mike