A resolver is something used to get song data online, e.g. MusicBrainz.
<script src="lib/cowhide.js"></script>
<!-- our own js files -->
- <script src="javascripts/musicbrainz.js"></script>
+ <script src="javascripts/resolvers/musicbrainz.js"></script>
<script src="javascripts/library.js"></script>
<!-- the application framework -->
var _priv = {
initialized: false,
deferred: undefined,
- // Whether items should be resolved on MusicBrainz
- resolve: false,
fetchCount: 100,
fetchOffset: 0,
oneTime: false,
mediaItems: [],
+ resolveBackend: MusicBrainz,
errorCB: function(error) {
console.log("HoofbeatsLibrary.errorCB: " + error.name);
findCB: function(items) {
items.forEach(function(item, index, items) {
_priv.mediaItems.push(item);
- if (_priv.resolve) {
- win.MusicBrainz.getArtist(item.artists[0]).done(
+ if (_priv.resolveBackend !== undefined) {
+ _priv.resolveBackend.getArtist(item.artists[0]).done(
function(data) {
console.log(
"HoofbeatsLibrary.findCB: " +
- "item resolved on MusicBrainz: " +
- data.name);
+ "item resolved on " + _priv.resolveBackend.name() +
+ ": " + data.name);
}
);
}
// Public stuff
-
return {
initialize: function() {
if (_priv.initialized)
scan: function(options) {
var opts = options || {};
- if (opts.resolve !== undefined) {
- _priv.resolve = opts.resolve;
+ if (opts.resolveBackend !== MusicBrainz) {
+ _priv.resolveBackend = opts.resolveBackend;
}
_priv.deferred = new $.Deferred();
getInitialized: function() { return _priv.initialized; },
getItems: function() { return _priv.mediaItems; },
getSize: function() { return _priv.mediaItems.length; },
- getResolve: function() {return _priv.resolve; }
+ getResolve: function() {return _priv.resolveBackend !== undefined; }
};
};
--- /dev/null
+/* vi: set et sw=4 ts=4 si: */
+(function(win, $) {
+ var dummyResolver = function() {
+ return {
+ name: function() { return "DummyResolver"; },
+
+ getArtist: function(q) {
+ return new $.Deferred().resolve({
+ name: 'Regina Spektor'
+ });
+ }
+ };
+ };
+
+ win.DummyResolver = new dummyResolver();
+}(window, jQuery));
/* Public methods */
return {
+ name: function() { return "MusicBrainz"; },
+
getArtist: function(q) {
var lookup_url = _priv._baseUrl + 'artist/?query="' + q +
'"&' + _priv._fmtArg,
<script src="unit/hoofbeats-phantom.js"></script>
<!-- source -->
+ <script src="javascripts/resolvers/dummy.js"></script>
+ <script src="javascripts/resolvers/musicbrainz.js"></script>
<script src="javascripts/library.js"></script>
- <script src="javascripts/musicbrainz.js"></script>
<!-- unit tests -->
+ <script src="unit/resolvers/musicbrainz.js"></script>
<script src="unit/library.js"></script>
- <script src="unit/musicbrainz.js"></script>
</head>
<body>
<div>
var lib = new HoofbeatsLibrary();
window.tizen = undefined;
raises(function() {
- lib.scan();
+ lib.scan({resolveBackend: DummyResolver});
}, Error, "scan throws Error");
});
test("successful scan", function() {
var lib = new HoofbeatsLibrary();
stop();
- lib.scan().then(function() {
+ lib.scan({resolveBackend: DummyResolver}).then(function() {
ok(lib.getSize() > 0, "there are items in the library");
start();
});
test("successful scan without resolving", function() {
var lib = new HoofbeatsLibrary();
stop();
- lib.scan({resolve: false}).then(function() {
- ok(lib.getResolve() == false, "lib.resolve is false");
+ lib.scan({resolveBackend: undefined}).then(function() {
+ ok(lib.getResolve() == false, "lib.getResolve() is false");
start();
});
});
test("scan with count", function() {
var lib = new HoofbeatsLibrary();
stop();
- lib.scan({count: 1}).then(function() {
+ lib.scan({count: 1, resolveBackend: DummyResolver}).then(function() {
ok(lib.getSize() == 1, "there is one item in the library");
start();
});
item_id = 'e7e7023b-54b3-41d5-b4a1-aa24498e0572';
stop();
- lib.scan({count: 1}).then(function() {
+ lib.scan({count: 1, resolveBackend: DummyResolver}).then(function() {
var item = lib.item(item_id);
ok(item !== undefined, "item was found");
ok(item.id == item_id, "correct item was found");
'examples/widget-gallery/javascripts/*.js',
'examples/hoofbeats/javascripts/*.js',
+ 'examples/hoofbeats/javascripts/resolvers/*.js',
'test/**/*.js'
]