1
0
Fork 0

Updated readme, discography method moved to Artist model, version bump

This commit is contained in:
Gregory Eremin 2011-09-14 13:08:03 +04:00
parent 0477633f8f
commit 7fdde0dfa1
5 changed files with 22 additions and 23 deletions

View File

@ -7,17 +7,23 @@
=== Usage
require 'musicbrainz'
# Search for artists
@suggestions = MusicBrainz::Artist.search('Jet')
# Find artist by name or mbid
@foo_fighters = MusicBrainz::Artist.find_by_name('Foo Fighters')
@kasabian = MusicBrainz::Artist.find('69b39eab-6577-46a4-a9f5-817839092033')
# Use them like ActiveRecord models
@empire_tracks = @kasabian.release_groups[8].releases.first.tracks
=== Future
It should work all like ActiveRecord models.
=== Api
MusicBrainzArtist
@artists = MusicBrainz::Artist.search(query)
@artist = MusicBrainz::Artist.find_by_name(name)
@artist = MusicBrainz::Artist.find(mbid)
@artist.id
@artist.type

View File

@ -1 +1 @@
0.4.0
0.4.1

View File

@ -1,21 +1,14 @@
module MusicBrainz
@@last_query_time = 0
def self.last_query_time
@@last_query_time
end
def self.last_query_time= time
@@last_query_time = time
end
@@query_interval = 1.1
def self.load url
sleep 1.1 - (Time.now.to_f - self.last_query_time) if Time.now.to_f - self.last_query_time < 1.1
sleep @@query_interval - (Time.now.to_f - @@last_query_time) if Time.now.to_f - @@last_query_time < @@query_interval
response = nil
5.times do
begin
response = open(url, "User-Agent" => "gem musicbrainz (https://github.com/magnolia-fan/musicbrainz) @ " + Socket.gethostname)
self.last_query_time = Time.now.to_f
@@last_query_time = Time.now.to_f
rescue => e
p "MusicBrainz: 503"
end
@ -23,10 +16,4 @@ module MusicBrainz
end
response
end
def self.discography mbid
artist = MusicBrainz::Artist.find(mbid)
artist.release_groups.each {|rg| rg.releases.each {|r| r.tracks } }
artist
end
end

View File

@ -30,6 +30,12 @@ module MusicBrainz
@artist
end
def self.discography mbid
artist = self.find(mbid)
artist.release_groups.each {|rg| rg.releases.each {|r| r.tracks } }
artist
end
def self.find_by_name name
matches = self.search name
matches.length.zero? ? nil : self.find(matches.first[:mbid])

View File

@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{musicbrainz}
s.version = "0.4.0"
s.version = "0.4.1"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Gregory Eremin}]