2011-04-05 22:58:11 +00:00
|
|
|
# encoding: utf-8
|
2011-04-03 16:21:05 +00:00
|
|
|
class ArtistController < ApplicationController
|
2011-04-05 22:58:11 +00:00
|
|
|
require 'open-uri'
|
2011-04-03 16:21:05 +00:00
|
|
|
def view
|
2011-04-09 13:31:13 +00:00
|
|
|
if params[:name].nil?
|
|
|
|
name = ''
|
|
|
|
else
|
2011-04-11 03:12:06 +00:00
|
|
|
if request.request_method == 'POST'
|
|
|
|
redirect_to :action => 'view', :name => params[:name].gsub(' ', '+')
|
|
|
|
end
|
|
|
|
name = params[:name].gsub('+', ' ')
|
2011-04-09 13:31:13 +00:00
|
|
|
end
|
|
|
|
@artist = Artist.getByName(name)
|
2011-04-03 16:21:05 +00:00
|
|
|
end
|
2011-04-10 06:17:06 +00:00
|
|
|
|
|
|
|
def autocomplete
|
|
|
|
autocomplete = Artist.getLastFmAutocomplete(params[:query])
|
|
|
|
return render :nothing => true if autocomplete.nil?
|
|
|
|
suggestions = []
|
|
|
|
pp autocomplete["response"]
|
|
|
|
autocomplete["response"]["docs"].each do |doc|
|
|
|
|
suggestions << doc["artist"] unless suggestions.include?(doc["artist"])
|
|
|
|
end
|
|
|
|
|
|
|
|
render :json => {
|
|
|
|
:query => params[:query],
|
|
|
|
:suggestions => suggestions
|
|
|
|
}
|
|
|
|
end
|
2011-04-03 16:21:05 +00:00
|
|
|
end
|
2011-04-09 13:02:28 +00:00
|
|
|
|