(hoofbeats) Fixes some anonymous closures and gets scanning working.
[profile/ivi/cowhide.git] / examples / hoofbeats / javascripts / musicbrainz.js
1 /* vi: set et sw=4 ts=4 si: */
2 (function(win, $) {
3     var musicbrainz = function() {
4         this.baseUrl = 'http://musicbrainz.org/ws/2/';
5         this.fmtArg = 'fmt=json';
6
7         this.getArtist = function(q) {
8             var self = this,
9                 lookup_url = self.baseUrl + 'artist/?query="' + q +
10                              '"&' + self.fmtArg;
11                 deferred = new $.Deferred();
12
13             if (q !== undefined) {
14                 $.getJSON(lookup_url).done(function(data) {
15                     if (data.count > 0) {
16                         artist_url = self.baseUrl + 'artist/' +
17                                      data.artist[0].id + '?' + self.fmtArg;
18                         $.getJSON(artist_url).done(function(data) {
19                             deferred.resolve(data);
20                         });
21                     } else {
22                         deferred.reject();
23                     }
24                 });
25             } else {
26                 deferred.reject();
27             }
28
29             return deferred.promise();
30         };
31     }
32
33     win.MusicBrainz = new musicbrainz();
34 }(window, jQuery));