Merge pull request #32 from jvoegele/feature/find-release-by-discid
Find release by DiscID with updated RSpec
This commit is contained in:
commit
426fed8906
|
@ -1,3 +1,4 @@
|
||||||
|
.ruby-version
|
||||||
coverage
|
coverage
|
||||||
.bundle
|
.bundle
|
||||||
tmp
|
tmp
|
||||||
|
|
|
@ -24,6 +24,7 @@ require "musicbrainz/models/track"
|
||||||
require "musicbrainz/bindings/artist"
|
require "musicbrainz/bindings/artist"
|
||||||
require "musicbrainz/bindings/artist_search"
|
require "musicbrainz/bindings/artist_search"
|
||||||
require "musicbrainz/bindings/artist_release_groups"
|
require "musicbrainz/bindings/artist_release_groups"
|
||||||
|
require "musicbrainz/bindings/discid_releases"
|
||||||
require "musicbrainz/bindings/relations"
|
require "musicbrainz/bindings/relations"
|
||||||
require "musicbrainz/bindings/release_group"
|
require "musicbrainz/bindings/release_group"
|
||||||
require "musicbrainz/bindings/release_group_search"
|
require "musicbrainz/bindings/release_group_search"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
module MusicBrainz
|
||||||
|
module Bindings
|
||||||
|
module DiscidReleases
|
||||||
|
def parse(xml)
|
||||||
|
xml.xpath('./disc/release-list/release').map do |xml|
|
||||||
|
MusicBrainz::Bindings::Release.parse(xml)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
extend self
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@ module MusicBrainz
|
||||||
field :asin, String
|
field :asin, String
|
||||||
field :barcode, String
|
field :barcode, String
|
||||||
field :quality, String
|
field :quality, String
|
||||||
|
|
||||||
def tracks
|
def tracks
|
||||||
@tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, {
|
@tracks ||= client.load(:release, { id: id, inc: [:recordings, :media], limit: 100 }, {
|
||||||
binding: :release_tracks,
|
binding: :release_tracks,
|
||||||
|
@ -26,6 +26,13 @@ module MusicBrainz
|
||||||
create_model: :release
|
create_model: :release
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def find_by_discid(id)
|
||||||
|
client.load(:discid, { id: id }, {
|
||||||
|
binding: :discid_releases,
|
||||||
|
create_models: :release
|
||||||
|
})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,4 +35,12 @@ describe MusicBrainz::Release do
|
||||||
expect(tracks.first.title).to eq "Empire"
|
expect(tracks.first.title).to eq "Empire"
|
||||||
expect(tracks.first.length).to eq 233013
|
expect(tracks.first.length).to eq 233013
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "gets a list of matching releases for a discid" do
|
||||||
|
releases = MusicBrainz::Release.find_by_discid("pmzhT6ZlFiwSRCdVwV0eqire5_Y-")
|
||||||
|
expect(releases.length).to eq 2
|
||||||
|
expect(releases.first.id).to eq "7a31cd5f-6a57-4fca-a731-c521df1d3b78"
|
||||||
|
expect(releases.first.title).to eq "Kveikur"
|
||||||
|
expect(releases.first.asin).to eq "B00C1GBOU6"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue