Medallia Blog

November 25, 2008

iPod + iPhone + Web Mashup

It's what the mobile music experience could be

This project started as I explored ways to view lyrics while listening to my music library on the iPod Touch. Ideas kept coming and I added some concepts (and code) from iMovieMash.com plus great content from the multitude of public video, music and search APIs.

The result was iMusicMash.com, an iPhone and Android G1 social web application that takes your music experience to a whole new level of enjoyment and discovery. You can start with the friends' playlists we already have or load your own iTunes music library. The interface is familiar as it mimics the iPhone's iPod. For each artist, we bring photos from Yahoo Boss Image Search, concert dates from Eventful, and live Twitter discussions. Then, for each song, we bring great YouTube videos, lyrics from LyricWiki, similar songs from Last.fm, and friends' songs for the same artist.

I recently added lyrics search and artist/title search.

iMusicMash was a winner in the Yahoo Developer Mashup contest at the recent Mashup Camp in Mt. View, California.

On the technical front, iMusicMash.com was developed with Perl for the backend and the IUI iPhone framework for the front end. It looks best on the iPhone or iPod Touch or Android G1.

We don't access the mobile device's music library directly, rather, we have a utility with which you can upload your iTunes XML file to iMusicMash from your desktop or laptop. We provide you a personal URL so that you can bookmark your library to appear on the mobile site's home page. (iPhone icon is available if you click "+").

These are some of the API's I used:

YouTube
(for music videos)
http://code.google.com/apis/youtube/2.0/reference.html

Yahoo BOSS Search & Image Search API
(for artist images and lyrics search)
http://developer.yahoo.com/search/boss/boss_guide/

Last.fm
(for similar songs)
http://www.last.fm/api

Seeqpod API
(for MP3s)
http://www.seeqpod.com/api.php

Eventful API
(for concert events)
http://api.eventful.com/

Twitter API
(for discussions on each artist)
http://apiwiki.twitter.com/


Al Nevarez
Product Manager

November 03, 2008

Spider Web Framework (for Java)

The Spider Web Framework is a framework for building web applications in Java. It was developed with a set of specific goals:
  • Make it trivially easy to write good test cases
  • Reduce boilerplate code to a minimum
  • Avoid static state through dependency injection
  • Strict M-V-C separation
  • Prefer convention over configuration
Before diving into the details of how each of these goals were achieved I would like to mention that the source code for the framework is available as well as a sample application with a tutorial. The sample application includes Jetty and can thus be started with a single command (Java and Ant required).

Unit testing

One of the most important feature of a framework is to facilitate testing; Spiderweb includes a testing framework that makes it trivial to write comprehensive test cases; a complete test, excluding the class and method declarations, can be written as:

assertHasContent(action(), "foo", "bar");

This will actually test the whole stack; HttpServletRequest and HttpServletResponse objects are instantiated and passed in to a servlet instance, and the data written to the response object is what is actually checked. The above checks that rendering a page without any request parameters returns a page that includes the strings "foo" and "bar".

Request parameter parsing

The HTTP protocol is text based, which means that any web application needs to parse request parameters into proper data types; this includes integers, enums and any custom data types defined by each application. This code tends to either be duplicated or at the very least need a method call for each request parameter to convert it into the right data type. Spiderweb handles this via a proxy interface which is dependency injected. Custom parsers can also be added easily.

Dependency injection

A web application often has several services and / or background tasks that are configured and instantiated when the servlet starts, typically in the Servlet.init() method. Since each module of the application typically needs to use a different set of these services a way to get references to the objects is needed. Often this is done by putting the references into static variables or having an object that has references to all the services and pass this object to all modules of the app. Both approaches make it difficult to determine which services a given module needs.

Spiderweb solves this problem by dependency injecting the needed services; the dependencies are thus documented simply as a list of arguments.

M-V-C separation

M-V-C is the preferred approach for an application that presents a UI, however, it turns out that, for a number of reasons, it is hard to keep this separation in practice. Spiderweb attempts to solve this problem by using StringTemplate as its templating language. StringTemplate was developed specifically to make a templating language with enough expressive power to make it useful, but no more. The author of StringTemplate wrote a paper going into detail on the motivation for StringTemplate.

Spiderweb goes a step further requiring all attributes used in the template be listed using TypeTags; these tags serve both as documentation for the template as well as a type safe way to set attributes.

Convention over configuration

Paradoxically having no choice can often be liberating; if there is only one way to do something the focus can simply be on actually getting it done.

Configuration for a web application tends to be very repetitive since most teams, if they are well organized, will adopt conventions to avoid having to check configuration files all the time. The configuration is thus copied and pasted each time a new module is added. In addition to being extra work this duplication also increases the maintenance burden.

Spiderweb solves this by having no mandatory configuration (beyond the minimum required for a Java Servlet). A URI maps to a name of a class and the URI is valid if that class exists. Various parameters can be changed, however, but this is typically done by method overriding instead of external configuration files (which cannot be automatically refactored and are not checked at compile time).

A tutorial that goes through writing a simple application can be found here.