Jango, Rails and RESTful – Integrating websites in 18 minutes and 18 lines of code.

Jango.com is one of the most incredible on-line radios I know and some time ago I decided to put Daniella Alcarpe songs on this site. Jango has many things that make artists life happier and easier: you pay Jango to play your songs to people who probably will like your song. For example, Daniella sings Brazilian Bossa Music, so in Jango I choosed to play her songs just for people who like this kind of music, people who listen to João Gilberto, Caetano Veloso, Chico Buarque and so on.

After songs starts playing, the artist starts to get fans. And they really come! With just 2 months of Jango, Daniella has almost 400 new fans, from all over the world.

Now comes the coolest part: we can interact with these fans. They can send us messages, comment on our profile, send us feedback and we can send them messages too. This is awesome and very useful for an artist who is becoming her artist life.

Jango website was made in RubyOnRails, so they provide an API for people who wants to use Jango information on their own website. And that’s what I did, in an extremely easy way. I wanted to show in Daniella’s website recent comments from fans on Jango. It took 18 minutes for me to integrate these two websites, using Rails ActiveResource. Here’s what I did:

1 – I’ve created two models (models/user.rb and models/comment.rb) on my project, one to deal with Jango Users and one to deal with Jango Comments:

class User < ActiveResource::Base
   self.site = "http://www.jango.com"

class Comment < ActiveResource::Base
  self.site = "http://www.jango.com/artists/48343/"

  def user
     @user ||= User.find(user_id)

2 – Then on my SocialController I have this:

class SocialController < ApplicationController
  def index
    @comments = Comment.find(:all)

3 – And in my views/social/index.html.erb I have

<% @comments.each do |c| %>
  <%= link_to "#{c.user.first_name} (#{c.user.country})", "http://www.jango.com/users/#{c.user.id}" %>
  <%= c.body %>
<% end %>

And that’s it: 9 model lines of code, 5 controller lines of code and 6 view lines of code. With 18 lines of code, I’ve integrated Daniella Alcarpe website with Jango. This is the power of Rails and RESTful. Now everybody who visits www.cantora.mus.br can see what fans are saying about the singer and her wonderful work. Check for yourself.

PS: of course there are some cache stuff to deal with on this integration, but for now I’m not worried. Premature optimization is the root of all evil (Donald Knuth)

3 Comments Jango, Rails and RESTful – Integrating websites in 18 minutes and 18 lines of code.

  1. Daniel Cukier

    Thank you for noticing this error. I just realized that Jango changed it’s xml interface and broke my integration! 🙂 I’ll fix it as soon as possible


Leave a Reply

Your email address will not be published. Required fields are marked *