tried to autoload modules (does not yet work as expected)
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
module LastFM
|
||||
|
||||
class Album < LastFMRequest
|
||||
def self.search query, limit = nil, page = nil
|
||||
album_request "search", "albummatches", query, nil, limit, page
|
||||
end
|
||||
|
||||
# return: album name, artist, (top)tags, tracks ( name, duration (in sec) ) mbid (album), release date, image urls ( different sizes )
|
||||
def self.getInfo album, artist
|
||||
album_request "getInfo", nil, album, artist
|
||||
end
|
||||
|
||||
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
|
||||
def self.getTopTags album, artist
|
||||
album_request "getTopTags", "toptags", album, artist
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
module LastFM
|
||||
|
||||
class Artist < LastFMRequest
|
||||
def self.search query, limit = nil, page = nil
|
||||
artist_request "search", "artistmatches", query, limit, page
|
||||
end
|
||||
|
||||
# return: artist name, tags, similar artists, artist bio (summary / long), mbid, image urls ( different sizes )
|
||||
def self.getInfo artist
|
||||
artist_request "getInfo", nil, artist
|
||||
end
|
||||
|
||||
# return: artists ( name, mbid, image urls ( different sizes ) )
|
||||
def self.getSimilar artist, limit = nil
|
||||
artist_request "getSimilar", "similarartists", artist, limit
|
||||
end
|
||||
|
||||
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
|
||||
def self.getTopTags artist
|
||||
artist_request "getTopTags", "toptags", artist
|
||||
end
|
||||
|
||||
# return: tracks ( name, image urls ( different sizes ) ) ordered by popularity
|
||||
def self.getTopTracks artist, limit = nil, page = nil
|
||||
artist_request "getTopTracks", "toptracks", artist, limit, page
|
||||
end
|
||||
|
||||
# return: albums ( name, mbid, album url, image urls ( different sizes ) ) ordered by popularity
|
||||
def self.getTopAlbums artist, limit = nil, page = nil
|
||||
artist_request "getTopAlbums", "topalbums", artist, limit, page
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
@@ -1,75 +0,0 @@
|
||||
module LastFM
|
||||
|
||||
class Artist < LastFMRequest
|
||||
def self.search query, limit = nil, page = nil
|
||||
artist_request "search", "artistmatches", query, limit, page
|
||||
end
|
||||
|
||||
# return: artist name, tags, similar artists, artist bio (summary / long), mbid, image urls ( different sizes )
|
||||
def self.getInfo artist
|
||||
artist_request "getInfo", nil, artist
|
||||
end
|
||||
|
||||
# return: artists ( name, mbid, image urls ( different sizes ) )
|
||||
def self.getSimilar artist, limit = nil
|
||||
artist_request "getSimilar", "similarartists", artist, limit
|
||||
end
|
||||
|
||||
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
|
||||
def self.getTopTags artist
|
||||
artist_request "getTopTags", "toptags", artist
|
||||
end
|
||||
|
||||
# return: tracks ( name, image urls ( different sizes ) ) ordered by popularity
|
||||
def self.getTopTracks artist, limit = nil, page = nil
|
||||
artist_request "getTopTracks", "toptracks", artist, limit, page
|
||||
end
|
||||
|
||||
# return: albums ( name, mbid, album url, image urls ( different sizes ) ) ordered by popularity
|
||||
def self.getTopAlbums artist, limit = nil, page = nil
|
||||
artist_request "getTopAlbums", "topalbums", artist, limit, page
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
class Album < LastFMRequest
|
||||
def self.search query, limit = nil, page = nil
|
||||
album_request "search", "albummatches", query, nil, limit, page
|
||||
end
|
||||
|
||||
# return: album name, artist, (top)tags, tracks ( name, duration (in sec) ) mbid (album), release date, image urls ( different sizes )
|
||||
def self.getInfo album, artist
|
||||
album_request "getInfo", nil, album, artist
|
||||
end
|
||||
|
||||
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
|
||||
def self.getTopTags album, artist
|
||||
album_request "getTopTags", "toptags", album, artist
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
class Track < LastFMRequest
|
||||
def self.search query, limit = nil, page = nil
|
||||
track_request "search", "trackmatches", query, nil, limit, page
|
||||
end
|
||||
|
||||
# return: track name, id, (top)tags, artist, duration (in msec), album ( artist, title, image urls ( different sizes) ), mbid
|
||||
def self.getInfo track, artist
|
||||
track_request "getInfo", nil, track, artist
|
||||
end
|
||||
|
||||
# return: tracks ( name, artist (name, mbid), duration (in msec), image urls (sometimes) )
|
||||
def self.getSimilar track, artist, limit = nil
|
||||
track_request "getSimilar", "similartracks", track, artist, limit
|
||||
end
|
||||
|
||||
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
|
||||
def self.getTopTags track, artist
|
||||
track_request "getTopTags", "toptags", track, artist
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
+52
-49
@@ -2,56 +2,59 @@ 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', :autocorrect => '1'
|
||||
debug_output $>
|
||||
format :json
|
||||
module LastFM
|
||||
|
||||
def self.api_key=(key)
|
||||
@@api_key = key
|
||||
default_params :api_key => key
|
||||
end
|
||||
class LastFMRequest
|
||||
include HTTParty
|
||||
|
||||
def self.limit=(limit)
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def self.limit
|
||||
@limit
|
||||
end
|
||||
|
||||
def self.page=(page)
|
||||
@page = page
|
||||
end
|
||||
|
||||
def self.page
|
||||
@page
|
||||
end
|
||||
|
||||
def self.artist_request method, node, q, limit = nil, page = nil
|
||||
prepare_result method, node, get('/', :query => { :method => "artist.#{method.to_s}", :artist => q, :limit => limit, :page => page })
|
||||
end
|
||||
|
||||
def self.album_request method, node, q, artist = nil, limit = nil, page = nil
|
||||
prepare_result method, node, get('/', :query => { :method => "album.#{method.to_s}", :album => q, :artist => artist, :limit => limit, :page => page })
|
||||
end
|
||||
|
||||
def self.track_request method, node, q, artist = nil, limit = nil, page = nil
|
||||
prepare_result method, node, get('/', :query => { :method => "track.#{method.to_s}", :track => q, :artist => artist, :limit => limit, :page => page })
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.prepare_result method, node, response_hash
|
||||
if method.to_s == "search"
|
||||
response_hash = response_hash.results
|
||||
base_uri "ws.audioscrobbler.com/2.0/"
|
||||
parser Proc.new { |data| Hashie::Mash.new(ActiveSupport::JSON.decode(data)) }
|
||||
default_params :format => 'json', :autocorrect => '1'
|
||||
debug_output $>
|
||||
format :json
|
||||
|
||||
def self.api_key=(key)
|
||||
@@api_key = key
|
||||
default_params :api_key => key
|
||||
end
|
||||
response_hash.send(node.to_sym)
|
||||
|
||||
def self.limit=(limit)
|
||||
@limit = limit
|
||||
end
|
||||
|
||||
def self.limit
|
||||
@limit
|
||||
end
|
||||
|
||||
def self.page=(page)
|
||||
@page = page
|
||||
end
|
||||
|
||||
def self.page
|
||||
@page
|
||||
end
|
||||
|
||||
def self.artist_request method, node, q, limit = nil, page = nil
|
||||
prepare_result method, node, get('/', :query => { :method => "artist.#{method.to_s}", :artist => q, :limit => limit, :page => page })
|
||||
end
|
||||
|
||||
def self.album_request method, node, q, artist = nil, limit = nil, page = nil
|
||||
prepare_result method, node, get('/', :query => { :method => "album.#{method.to_s}", :album => q, :artist => artist, :limit => limit, :page => page })
|
||||
end
|
||||
|
||||
def self.track_request method, node, q, artist = nil, limit = nil, page = nil
|
||||
prepare_result method, node, get('/', :query => { :method => "track.#{method.to_s}", :track => q, :artist => artist, :limit => limit, :page => page })
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.prepare_result method, node, response_hash
|
||||
if method.to_s == "search"
|
||||
response_hash = response_hash.results
|
||||
end
|
||||
response_hash.send(node.to_sym)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
module LastFM
|
||||
|
||||
class Track < LastFMRequest
|
||||
def self.search query, limit = nil, page = nil
|
||||
track_request "search", "trackmatches", query, nil, limit, page
|
||||
end
|
||||
|
||||
# return: track name, id, (top)tags, artist, duration (in msec), album ( artist, title, image urls ( different sizes) ), mbid
|
||||
def self.getInfo track, artist
|
||||
track_request "getInfo", nil, track, artist
|
||||
end
|
||||
|
||||
# return: tracks ( name, artist (name, mbid), duration (in msec), image urls (sometimes) )
|
||||
def self.getSimilar track, artist, limit = nil
|
||||
track_request "getSimilar", "similartracks", track, artist, limit
|
||||
end
|
||||
|
||||
# return: tags ( name, tag´s last.fm-url ) ordered by popularity
|
||||
def self.getTopTags track, artist
|
||||
track_request "getTopTags", "toptags", track, artist
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user