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::Base2 - Then on my SocialController I have this:
self.site = "http://www.jango.com"
end
class Comment < ActiveResource::Base
self.site = "http://www.jango.com/artists/48343/"
def user
@user ||= User.find(user_id)
end
end
class SocialController < ApplicationController3 - And in my views/social/index.html.erb I have
def index
@comments = Comment.find(:all)
end
end
<% @comments.each do |c| %>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.
<%= link_to "#{c.user.first_name} (#{c.user.country})", "http://www.jango.com/users/#{c.user.id}" %>
<%= c.body %>
<% end %>
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)"