added search controller, added LastFM-Request-Core, switched from erb to haml

This commit is contained in:
Thomas Buchöster
2011-05-02 19:09:17 +02:00
parent 9a52abb144
commit edc53eadd6
17 changed files with 346 additions and 17 deletions
+4
View File
@@ -2,3 +2,7 @@
db/*.sqlite3
log/*.log
tmp/
/Icon
.DS_Store
Thumbs.db
+18 -1
View File
@@ -5,12 +5,29 @@ gem 'rails', '3.0.5'
gem 'sqlite3'
gem 'jquery-rails', '>= 0.2.6'
# templating
gem 'haml-rails'
# for using last.fm api
gem 'httparty'
# for converting json/xml to object
gem 'hashie'
# authentication, authorization, roles
gem 'cream'
group :development do
# for html2haml
gem 'hpricot'
gem 'ruby_parser'
end
# Deploy with Capistrano
# gem 'capistrano'
# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'
+136
View File
@@ -29,20 +29,115 @@ GEM
activesupport (= 3.0.5)
activesupport (3.0.5)
arel (2.0.9)
bcrypt-ruby (2.1.4)
builder (2.1.2)
cancan (1.6.4)
cancan-permits (0.3.10)
activemodel (>= 3.0.1)
activemodel (>= 3.0.1)
activeresource (>= 3.0.1)
activeresource (>= 3.0.1)
activesupport (>= 3.0.1)
activesupport (>= 3.0.1)
cancan (>= 1.4.1)
cancan (>= 1.4.1)
logging_assist (>= 0.2.0)
logging_assist (>= 0.2.0)
rails3_artifactor (~> 0.3.2)
rails3_artifactor (~> 0.3.2)
require_all (~> 1.2.0)
require_all (~> 1.2.0)
sugar-high (~> 0.3.1)
sugar-high (~> 0.3.1)
cancan-rest-links (0.2.2)
cancan (>= 1.4.1)
cancan (>= 1.4.1)
r3_plugin_toolbox (>= 0.4.0)
r3_plugin_toolbox (~> 0.4.0)
require_all (~> 1.2.0)
require_all (~> 1.2.0)
sugar-high (~> 0.3.1)
sugar-high (~> 0.3.1)
colorize (0.5.8)
crack (0.1.8)
cream (0.8.9.2)
cancan (>= 1.4.0)
cancan (>= 1.4.1)
cancan-permits (>= 0.3.10)
cancan-permits (>= 0.3.4)
cancan-rest-links (>= 0.2.0)
cancan-rest-links (>= 0.2.1)
colorize (>= 0.5.8)
colorize (>= 0.5.8)
devise (>= 1.1.5)
devise (>= 1.1.5)
devise-links (>= 0.2.0)
devise-links (>= 0.2.1)
logging_assist (>= 0.2.0)
logging_assist (>= 0.2.0)
r3_plugin_toolbox (>= 0.4.0)
r3_plugin_toolbox (>= 0.4.0)
rails (>= 3.0.1)
rails (>= 3.0.1)
rails3_artifactor (>= 0.3.2)
rails3_artifactor (~> 0.3.2)
require_all (~> 1.2.0)
require_all (~> 1.2.0)
sugar-high (>= 0.3.1)
sugar-high (~> 0.3.1)
devise (1.3.3)
bcrypt-ruby (~> 2.1.2)
orm_adapter (~> 0.0.3)
warden (~> 1.0.3)
devise-links (0.2.2)
activesupport (>= 3.0.0)
devise (>= 1.1.5)
logging_assist (>= 0.2.0)
r3_plugin_toolbox (>= 0.4.0)
rails3_artifactor (>= 0.3.1)
require_all (~> 1.2.0)
sugar-high (~> 0.3.1)
diff-lcs (1.1.2)
erubis (2.6.6)
abstract (>= 1.0.0)
haml (3.0.25)
haml-rails (0.3.4)
actionpack (~> 3.0)
activesupport (~> 3.0)
haml (~> 3.0)
railties (~> 3.0)
hashie (1.0.0)
hpricot (0.8.4)
httparty (0.7.7)
crack (= 0.1.8)
i18n (0.5.0)
jquery-rails (0.2.7)
rails (~> 3.0)
thor (~> 0.14.4)
log4r-color (1.2)
colorize
scribe
logging_assist (0.2.1)
colorize (~> 0.5.8)
log4r-color (>= 1.2)
require_all (~> 1.2.0)
sugar-high (~> 0.3.0)
mail (2.2.17)
activesupport (>= 2.3.6)
i18n (>= 0.4.0)
mime-types (~> 1.16)
treetop (~> 1.4.8)
migration_assist (0.1.9)
rails (>= 3.0.1)
require_all (~> 1.2.0)
mime-types (1.16)
mocha (0.9.12)
orm_adapter (0.0.4)
polyglot (0.3.1)
r3_plugin_toolbox (0.4.1)
rails (~> 3.0)
require_all (~> 1.2.0)
sugar-high (~> 0.3.0)
rack (1.2.2)
rack-mount (0.6.14)
rack (>= 1.0.0)
@@ -56,22 +151,63 @@ GEM
activesupport (= 3.0.5)
bundler (~> 1.0)
railties (= 3.0.5)
rails3_artifactor (0.3.2)
migration_assist (~> 0.1.4)
rails3_assist (~> 0.3.0)
require_all (~> 1.2.0)
rspec (>= 2.0.0)
sugar-high (~> 0.3.0)
rails3_assist (0.3.7)
activesupport (>= 3.0)
migration_assist (~> 0.1.7)
require_all (~> 1.2.0)
sugar-high (~> 0.3.0)
thor (>= 0.14.0)
railties (3.0.5)
actionpack (= 3.0.5)
activesupport (= 3.0.5)
rake (>= 0.8.7)
thor (~> 0.14.4)
rake (0.8.7)
require_all (1.2.0)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
ruby_parser (2.0.6)
sexp_processor (~> 3.0)
scribe (0.2.4)
rake
thrift_client (~> 0.6)
sexp_processor (3.0.5)
sqlite3 (1.3.3)
sugar-high (0.3.7)
mocha (>= 0.9.8)
require_all (~> 1.2.0)
thor (0.14.6)
thrift (0.5.0)
thrift_client (0.6.0)
thrift (~> 0.5.0)
treetop (1.4.9)
polyglot (>= 0.3.1)
tzinfo (0.3.26)
warden (1.0.3)
rack (>= 1.0.0)
PLATFORMS
ruby
DEPENDENCIES
cream
haml-rails
hashie
hpricot
httparty
jquery-rails (>= 0.2.6)
rails (= 3.0.5)
ruby_parser
sqlite3
View File
+11
View File
@@ -0,0 +1,11 @@
class SearchController < ApplicationController
def index
puts "TRACK SEARCH"
@results = LastFM::Track.search("one time")
@resultsTracks = @results["results"]
# puts "ARTIST INFO"
# @results = LastFM::Artist.getInfo("Justin Bieber")
end
end
+15
View File
@@ -1,2 +1,17 @@
module ApplicationHelper
def validate_img_url image, size
if image.nil?
"noImage"
else
image.each do |img|
if img["size"] == size.to_s
return img["#text"]
end
end
end
end
end
+2
View File
@@ -0,0 +1,2 @@
module SearchHelper
end
-14
View File
@@ -1,14 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Nineminutes</title>
<%= stylesheet_link_tag :all %>
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
</head>
<body>
<%= yield %>
</body>
</html>
+9
View File
@@ -0,0 +1,9 @@
!!!
%html
%head
%title Nineminutes
= stylesheet_link_tag :all
= javascript_include_tag :defaults
= csrf_meta_tag
%body
= yield
+13
View File
@@ -0,0 +1,13 @@
%h1 Search results for "Justin Bieber"
%p
%b= @resultsTracks["opensearch:totalResults"]
= "Ergebnisse insgesamt"
%ul
- @resultsTracks.trackmatches.track.each do |track|
%li
= image_tag validate_img_url(track.image, :small)
%b
= track.name
= " - #{track.artist}"
= "(#{track.listeners} Hörer)"
+3 -2
View File
@@ -13,8 +13,9 @@ module Nineminutes
# -- all .rb files in that directory are automatically loaded.
# Custom directories with classes and modules you want to be autoloadable.
# config.autoload_paths += %W(#{config.root}/extras)
# config.autoload_paths += %W(#{config.root}/lib/)
# config.autoload_paths += Dir["#{Rails.root.to_s}/lib/LastFM/"]
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named.
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
+4
View File
@@ -1,5 +1,9 @@
# Load the rails application
require File.expand_path('../application', __FILE__)
require "#{Rails.root.to_s}/lib/LastFM/LastFMRequest.rb"
require "#{Rails.root.to_s}/lib/LastFM/LastFM.rb"
# Initialize the rails application
Nineminutes::Application.initialize!
LastFMRequest::api_key = '4c32e360f68553ec8fdca3711456b4f9'
+1
View File
@@ -1,4 +1,5 @@
Nineminutes::Application.routes.draw do
resources :search
# The priority is based upon order of creation:
# first created -> highest priority.
+76
View File
@@ -0,0 +1,76 @@
module LastFM
class Artist < LastFMRequest
def self.search artist
get('/', :query => {:method => 'artist.search', :artist => artist})
end
# return: artist name, tags, similar artists, artist bio (summary / long), mbid, image urls ( different sizes )
def self.getInfo artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'artist.getInfo', :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
# return: artists ( name, mbid, image urls ( different sizes ) )
def self.getSimilar artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'artist.getSimilar', :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
def self.getTopTags artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'artist.getTopTags', :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
# return: tracks ( name, image urls ( different sizes ) ) ordered by popularity
def self.getTopTracks artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'artist.getTopTracks', :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
# return: albums ( name, mbid, album url, image urls ( different sizes ) ) ordered by popularity
def self.getTopAlbums artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'artist.getTopAlbums', :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
end
class Album < LastFMRequest
def self.search album
get('/', :query => {:method => 'album.search', :album => album})
end
# return: album name, artist, (top)tags, tracks ( name, duration (in sec) ) mbid (album), release date, image urls ( different sizes )
def self.getInfo album = nil, artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'album.getInfo', :album =>album, :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
def self.getTopTags album = nil, artist = nil, mbid = nil, autocorrect = 1
get('/', :query => {:method => 'album.getTopTags', :album =>album, :artist => artist, :mbid => mbid, :autocorrect => autocorrect})
end
end
class Track < LastFMRequest
def self.search track
get('/', :query => {:method => 'track.search', :track => track})
end
# return: track name, id, (top)tags, artist, duration (in msec), album ( artist, title, image urls ( different sizes) ), mbid
def self.getInfo track = nil, artist = nil, autocorrect = 1
get('/', :query => {:method => 'track.getInfo', :track => track, :artist => artist, :autocorrect => autocorrect})
end
# return: tracks ( name, artist (name, mbid), duration (in msec), image urls (sometimes) )
def self.getSimilar track = nil, artist = nil, autocorrect = 1
get('/', :query => {:method => 'track.getSimilar', :track => track, :artist => artist, :autocorrect => autocorrect})
end
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
def self.getTopTags track = nil, artist = nil, autocorrect = 1
get('/', :query => {:method => 'track.getTopTags', :track => track, :artist => artist, :autocorrect => autocorrect})
end
end
end
+41
View File
@@ -0,0 +1,41 @@
require 'httparty'
require 'active_support'
require 'hashie'
class LastFMRequest
include HTTParty
base_uri "ws.audioscrobbler.com/2.0/"
parser Proc.new { |data| Hashie::Mash.new(ActiveSupport::JSON.decode(data)) }
default_params :format => 'json'
debug_output $>
format :json
def self.api_key=(key)
@@api_key = key
default_params :api_key => key
end
def self.api_key
@@api_key
end
def self.limit=(limit)
@limit = limit
default_params :limit => limit
end
def self.limit
@limit
end
def self.page=(page)
@page = page
default_params :page => page
end
def self.page
@page
end
end
@@ -0,0 +1,9 @@
require 'test_helper'
class SearchControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
end
end
+4
View File
@@ -0,0 +1,4 @@
require 'test_helper'
class SearchHelperTest < ActionView::TestCase
end