1
0
Fork 0

Merge pull request #17 from lionelerard/master

Adds release group urls
This commit is contained in:
Murdoch 2013-02-06 08:18:52 -08:00
commit 687ce1b785
6 changed files with 11 additions and 4 deletions

View File

@ -93,7 +93,8 @@ MusicBrainz::ReleaseGroup.search(artist_name, title, type: 'Album')
:type => String,
:title => String,
:desc => String,
:first_release_date => Date
:first_release_date => Date,
:urls => Hash
}
```

View File

@ -8,7 +8,10 @@ module MusicBrainz
type: (xml.attribute('type').value rescue nil),
title: (xml.xpath('./title').text rescue nil),
desc: (xml.xpath('./disambiguation').text rescue nil),
first_release_date: (xml.xpath('./first-release-date').text rescue nil)
first_release_date: (xml.xpath('./first-release-date').text rescue nil),
urls: (Hash[xml.xpath('./relation-list[@target-type="url"]/relation').map{ |xml|
[xml.attribute('type').value.downcase.split(" ").join("_").to_sym, xml.xpath('./target').text]
}] rescue {})
}
end

View File

@ -9,7 +9,7 @@ module MusicBrainz
field :urls, Hash
def release_groups
@release_groups ||= client.load(:release_group, { artist: id }, {
@release_groups ||= client.load(:release_group, { artist: id, inc: [:url_rels] }, {
binding: :artist_release_groups,
create_models: :release_group,
sort: :first_release_date

View File

@ -5,6 +5,7 @@ module MusicBrainz
field :title, String
field :desc, String
field :first_release_date, Date
field :urls, Hash
alias_method :disambiguation, :desc
@ -18,7 +19,7 @@ module MusicBrainz
class << self
def find(id)
client.load(:release_group, { id: id }, {
client.load(:release_group, { id: id, inc: [:url_rels] }, {
binding: :release_group,
create_model: :release_group
})

View File

@ -56,5 +56,6 @@ describe MusicBrainz::Artist do
release_groups.first.type.should == "Single"
release_groups.first.title.should == "Club Foot"
release_groups.first.first_release_date.should == Date.new(2004, 5, 10)
release_groups.first.urls[:discogs].should == 'http://www.discogs.com/master/125150'
end
end

View File

@ -21,6 +21,7 @@ describe MusicBrainz::ReleaseGroup do
release_group.type.should == "Album"
release_group.title.should == "Empire"
release_group.first_release_date.should == Date.new(2006, 8, 28)
release_group.urls[:wikipedia].should == 'http://en.wikipedia.org/wiki/Empire_(Kasabian_album)'
end
end