(hoofbeats) Added MusicBrainz API implementation (only getArtist so far).
authorSalvatore Iovene <salvatore.iovene@intel.com>
Thu, 24 Jan 2013 14:01:21 +0000 (16:01 +0200)
committerSalvatore Iovene <salvatore.iovene@intel.com>
Thu, 24 Jan 2013 14:01:21 +0000 (16:01 +0200)
examples/hoofbeats/javascripts/library.js
examples/hoofbeats/javascripts/musicbrainz.js [new file with mode: 0644]
examples/hoofbeats/tests/index.html
examples/hoofbeats/tests/unit/musicbrainz.js [new file with mode: 0644]
grunt.js

index 82a6986..29b887c 100644 (file)
@@ -1,7 +1,9 @@
+/* vi: set et sw=4 ts=4 si: */
 $(function() {
     var library = function() {
         // For readability:
         this.initialized = false;
+
         this.fetchCount = 100;
         this.fetchOffset = 0;
         this.mediaItems = [];
@@ -51,7 +53,9 @@ $(function() {
 
             items.forEach(function(item, index, items) {
                 self.mediaItems.push(item);
-                console.log("Item added to the library: " + item.title);
+                window.MusicBrainz.getArtist(item.name).done(function(data) {
+                    console.log(data);
+                });
             });
 
             if (items.length == this.fetchCount) {
diff --git a/examples/hoofbeats/javascripts/musicbrainz.js b/examples/hoofbeats/javascripts/musicbrainz.js
new file mode 100644 (file)
index 0000000..f0ae5cc
--- /dev/null
@@ -0,0 +1,23 @@
+/* vi: set et sw=4 ts=4 si: */
+$(function() {
+    var musicbrainz = function() {
+        this.baseUrl = 'http://musicbrainz.org/ws/2/';
+        this.fmtArg = 'fmt=json';
+
+        this.getArtist = function(q) {
+            var self = this,
+                lookup_url = self.baseUrl + 'artist/?query=' + q + '&' + self.fmtArg;
+                deferred = new $.Deferred();
+
+            $.getJSON(lookup_url).done(function(data) {
+                artist_url = self.baseUrl + 'artist/' + data.artist[0].id + '?' + self.fmtArg;
+                $.getJSON(artist_url).done(function(data) {
+                    deferred.resolve(data);
+                });
+            });
+            return deferred.promise();
+        };
+    }
+
+    window.MusicBrainz = new musicbrainz();
+});
index 4e2bdbb..836ddef 100644 (file)
 
   <!-- source -->
   <script src="../javascripts/library.js"></script>
+  <script src="../javascripts/musicbrainz.js"></script>
 
   <!-- unit tests -->
   <script src="unit/library.js"></script>
+  <script src="unit/musicbrainz.js"></script>
 </head>
 <body>
   <div>
diff --git a/examples/hoofbeats/tests/unit/musicbrainz.js b/examples/hoofbeats/tests/unit/musicbrainz.js
new file mode 100644 (file)
index 0000000..ddc8322
--- /dev/null
@@ -0,0 +1,20 @@
+/* vi: set et sw=4 ts=4 si: */
+$(function() {
+    module("hoofbeats-musicbrainz", {
+        setup: function() {
+        },
+        teardown: function() {
+        }
+    });
+
+    test("get artist data",
+    function() {
+        var name = "Regina Spektor";
+        var promise = MusicBrainz.getArtist(name);
+        stop();
+        promise.done(function(data) {
+            equals(data.name, name, "name matches");
+            start();
+        });
+    });
+});
index a4ea705..3379ad3 100644 (file)
--- a/grunt.js
+++ b/grunt.js
@@ -52,7 +52,8 @@ module.exports = function(grunt) {
         "devel"    : true,
         "boss"     : true,
         "expr"     : true,
-        "asi"      : true
+        "asi"      : true,
+        "es5"      : true
       }
     },
     less: {