musicbrainz 0.7.5 → 0.7.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ tmp
4
4
  Gemfile.lock
5
5
  .gem
6
6
  *.swp
7
+ pkg/*
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## musicbrainz (unreleased) ##
2
2
 
3
+ # 0.7.6 (June 14, 2013) ##
4
+
5
+ * Improves urls attribute to return an array if there are multiple urls for a relation type. [#19]
6
+
3
7
  # 0.7.5 (May 6, 2013) ##
4
8
 
5
9
  * Created new track_search binding to allow searching for tracks. [#18]
data/lib/musicbrainz.rb CHANGED
@@ -24,6 +24,7 @@ require "musicbrainz/models/track"
24
24
  require "musicbrainz/bindings/artist"
25
25
  require "musicbrainz/bindings/artist_search"
26
26
  require "musicbrainz/bindings/artist_release_groups"
27
+ require "musicbrainz/bindings/relations"
27
28
  require "musicbrainz/bindings/release_group"
28
29
  require "musicbrainz/bindings/release_group_search"
29
30
  require "musicbrainz/bindings/release_group_releases"
@@ -3,18 +3,18 @@ module MusicBrainz
3
3
  module Bindings
4
4
  module Artist
5
5
  def parse(xml)
6
- xml = xml.xpath('./artist') unless xml.xpath('./artist').empty?
6
+ xml = xml.xpath('./artist')
7
+
8
+ return {} if xml.empty?
9
+
7
10
  {
8
11
  id: (xml.attribute('id').value rescue nil),
9
12
  type: (xml.attribute('type').value rescue nil),
10
13
  name: (xml.xpath('./name').text.gsub(/[`’]/, "'") rescue nil),
11
14
  country: (xml.xpath('./country').text rescue nil),
12
15
  date_begin: (xml.xpath('./life-span/begin').text rescue nil),
13
- date_end: (xml.xpath('./life-span/end').text rescue nil),
14
- urls: (Hash[xml.xpath('./relation-list[@target-type="url"]/relation').map{ |xml|
15
- [xml.attribute('type').value.downcase.split(" ").join("_").to_sym, xml.xpath('./target').text]
16
- }] rescue {})
17
- }
16
+ date_end: (xml.xpath('./life-span/end').text rescue nil)
17
+ }.merge(Relations.parse(xml))
18
18
  end
19
19
 
20
20
  extend self
@@ -0,0 +1,26 @@
1
+ # encoding: UTF-8
2
+ module MusicBrainz
3
+ module Bindings
4
+ module Relations
5
+ def parse(xml)
6
+ hash = { urls: {} }
7
+
8
+ xml.xpath('./relation-list[@target-type="url"]/relation').map do |xml|
9
+ next unless type = xml.attribute('type')
10
+
11
+ type = type.value.downcase.split(" ").join("_").to_sym
12
+ target = xml.xpath('./target').text
13
+
14
+ if hash[:urls][type].nil? then hash[:urls][type] = target
15
+ elsif hash[:urls][type].is_a?(Array) then hash[:urls][type] << target
16
+ else hash[:urls][type] = [hash[:urls][type]]; hash[:urls][type] << target
17
+ end
18
+ end
19
+
20
+ hash
21
+ end
22
+
23
+ extend self
24
+ end
25
+ end
26
+ end
@@ -8,11 +8,8 @@ module MusicBrainz
8
8
  type: (xml.attribute('type').value rescue nil),
9
9
  title: (xml.xpath('./title').text rescue nil),
10
10
  desc: (xml.xpath('./disambiguation').text rescue nil),
11
- first_release_date: (xml.xpath('./first-release-date').text rescue nil),
12
- urls: (Hash[xml.xpath('./relation-list[@target-type="url"]/relation').map{ |xml|
13
- [xml.attribute('type').value.downcase.split(" ").join("_").to_sym, xml.xpath('./target').text]
14
- }] rescue {})
15
- }
11
+ first_release_date: (xml.xpath('./first-release-date').text rescue nil)
12
+ }.merge(Relations.parse(xml))
16
13
  end
17
14
 
18
15
  extend self
@@ -1,3 +1,3 @@
1
1
  module MusicBrainz
2
- VERSION = "0.7.5"
2
+ VERSION = "0.7.6"
3
3
  end
@@ -0,0 +1,44 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require "spec_helper"
4
+
5
+ describe MusicBrainz::Bindings::Relations do
6
+ describe '.parse' do
7
+ describe 'attributes' do
8
+ describe 'urls' do
9
+ context '1 url for relation type' do
10
+ it 'returns a string' do
11
+ xml = Nokogiri::XML.parse(
12
+ %Q{<artist><relation-list target-type="url">
13
+ <relation type-id="99429741-f3f6-484b-84f8-23af51991770" type="social network">
14
+ <target id="4f4068cb-7001-47a3-a2fe-9146eb6b5d16">https://plus.google.com/+Madonna</target>
15
+ </relation>
16
+ </relation-list></artist>}
17
+ )
18
+
19
+ described_class.parse(xml.xpath('./artist'))[:urls][:social_network].should == 'https://plus.google.com/+Madonna'
20
+ end
21
+ end
22
+
23
+ context 'multiple urls for relation types' do
24
+ it 'returns an array' do
25
+ xml = Nokogiri::XML.parse(
26
+ %Q{<artist><relation-list target-type="url">
27
+ <relation type-id="99429741-f3f6-484b-84f8-23af51991770" type="social network">
28
+ <target id="4f4068cb-7001-47a3-a2fe-9146eb6b5d16">https://plus.google.com/+Madonna</target>
29
+ </relation>
30
+ <relation type-id="99429741-f3f6-484b-84f8-23af51991770" type="social network">
31
+ <target id="1dc9e14d-ebfb-448c-a005-e3481d320595">https://www.facebook.com/madonna</target>
32
+ </relation>
33
+ </relation-list></artist>}
34
+ )
35
+
36
+ described_class.parse(xml.xpath('./artist'))[:urls][:social_network].should == [
37
+ 'https://plus.google.com/+Madonna', 'https://www.facebook.com/madonna'
38
+ ]
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,67 @@
1
+ <?xml version="1.0" standalone="yes"?>
2
+ <metadata created="2013-06-11T14:02:53.104Z" xmlns="http://musicbrainz.org/ns/mmd-2.0#" xmlns:ext="http://musicbrainz.org/ns/ext#-2.0">
3
+ <artist-list count="5" offset="0">
4
+ <artist id="90fff570-a4ef-4cd4-ba21-e00c7261b05a" type="Person" ext:score="100">
5
+ <name>Chris Martin</name>
6
+ <sort-name>Martin, Chris</sort-name>
7
+ <disambiguation>Reggae / Dancehall singer Christopher Martin</disambiguation>
8
+ <life-span>
9
+ <ended>false</ended>
10
+ </life-span>
11
+ </artist>
12
+ <artist id="b732a912-af95-472c-be52-b14610734c64" type="Person" ext:score="100">
13
+ <name>Chris Martin</name>
14
+ <sort-name>Martin, Chris</sort-name>
15
+ <disambiguation>Illustrator</disambiguation>
16
+ <life-span>
17
+ <ended>false</ended>
18
+ </life-span>
19
+ </artist>
20
+ <artist id="98d1ec5a-dd97-4c0b-9c83-7928aac89bca" type="Person" ext:score="100">
21
+ <name>Chris Martin</name>
22
+ <sort-name>Martin, Chris</sort-name>
23
+ <gender>male</gender>
24
+ <country>GB</country>
25
+ <area id="8a754a16-0027-3a29-b6d7-2b40ea0481ed">
26
+ <name>United Kingdom</name>
27
+ <sort-name>United Kingdom</sort-name>
28
+ </area>
29
+ <disambiguation>lead singer of Coldplay</disambiguation>
30
+ <ipi-list>
31
+ <ipi>00280536565</ipi>
32
+ </ipi-list>
33
+ <life-span>
34
+ <begin>1977-03-02</begin>
35
+ <ended>false</ended>
36
+ </life-span>
37
+ <alias-list>
38
+ <alias sort-name="Martin, Christopher Anthony John" type="Legal name">Christopher Anthony John Martin</alias>
39
+ </alias-list>
40
+ <tag-list>
41
+ <tag count="1">
42
+ <name>pop/rock</name>
43
+ </tag>
44
+ </tag-list>
45
+ </artist>
46
+ <artist id="af2ab893-3212-4226-9e73-73a1660b6952" type="Person" ext:score="100">
47
+ <name>Chris Martin</name>
48
+ <sort-name>Martin, Chris</sort-name>
49
+ <disambiguation>hip hop producer DJ Premier, DJ Primo</disambiguation>
50
+ <life-span>
51
+ <begin>1965-05-05</begin>
52
+ <ended>false</ended>
53
+ </life-span>
54
+ <alias-list>
55
+ <alias sort-name="Christopher Edward Martin">Christopher Edward Martin</alias>
56
+ </alias-list>
57
+ </artist>
58
+ <artist id="444d1b63-534b-4ea6-89f0-0af6ab2e20c3" type="Person" ext:score="100">
59
+ <name>Chris Martin</name>
60
+ <sort-name>Martin, Chris</sort-name>
61
+ <disambiguation>Disney songwriter/composer</disambiguation>
62
+ <life-span>
63
+ <ended>false</ended>
64
+ </life-span>
65
+ </artist>
66
+ </artist-list>
67
+ </metadata>
@@ -21,18 +21,16 @@ describe MusicBrainz::Artist do
21
21
  end
22
22
 
23
23
  it "should return search results in the right order and pass back the correct score" do
24
+ response = File.open(File.join(File.dirname(__FILE__), "../fixtures/artist/search.xml")).read
25
+ MusicBrainz::Client.any_instance.stub(:get_contents).with('http://musicbrainz.org/ws/2/artist?query=artist:"Chris+Martin"&limit=10').
26
+ and_return({ status: 200, body: response})
27
+
24
28
  matches = MusicBrainz::Artist.search('Chris Martin')
25
29
 
26
30
  matches[0][:score].should == 100
27
- matches[0][:id].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca"
31
+ matches[0][:id].should == "90fff570-a4ef-4cd4-ba21-e00c7261b05a"
28
32
  matches[1][:score].should == 100
29
- matches[1][:id].should == "af2ab893-3212-4226-9e73-73a1660b6952"
30
- end
31
-
32
- it "finds name first than alias" do
33
- matches = MusicBrainz::Artist.search('Chris Martin')
34
- matches.length.should be > 0
35
- matches.first[:mbid].should == "98d1ec5a-dd97-4c0b-9c83-7928aac89bca"
33
+ matches[1][:id].should == "b732a912-af95-472c-be52-b14610734c64"
36
34
  end
37
35
 
38
36
  it "gets correct result by name" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musicbrainz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.7.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-06 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -96,6 +96,7 @@ files:
96
96
  - lib/musicbrainz/bindings/artist.rb
97
97
  - lib/musicbrainz/bindings/artist_release_groups.rb
98
98
  - lib/musicbrainz/bindings/artist_search.rb
99
+ - lib/musicbrainz/bindings/relations.rb
99
100
  - lib/musicbrainz/bindings/release.rb
100
101
  - lib/musicbrainz/bindings/release_group.rb
101
102
  - lib/musicbrainz/bindings/release_group_releases.rb
@@ -117,12 +118,14 @@ files:
117
118
  - lib/musicbrainz/models/track.rb
118
119
  - lib/musicbrainz/version.rb
119
120
  - musicbrainz.gemspec
121
+ - spec/bindings/relations_spec.rb
120
122
  - spec/bindings/release_group_search_spec.rb
121
123
  - spec/bindings/release_spec.rb
122
124
  - spec/bindings/track_search_spec.rb
123
125
  - spec/client_modules/cache_spec.rb
124
126
  - spec/deprecated/cache_config_spec.rb
125
127
  - spec/deprecated/proxy_config_spec.rb
128
+ - spec/fixtures/artist/search.xml
126
129
  - spec/fixtures/kasabian.xml
127
130
  - spec/fixtures/release_group/entity.xml
128
131
  - spec/fixtures/release_group/search.xml
@@ -147,7 +150,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
147
150
  version: '0'
148
151
  segments:
149
152
  - 0
150
- hash: 3461617473548305683
153
+ hash: 85383648681558491
151
154
  required_rubygems_version: !ruby/object:Gem::Requirement
152
155
  none: false
153
156
  requirements:
@@ -156,7 +159,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
159
  version: '0'
157
160
  segments:
158
161
  - 0
159
- hash: 3461617473548305683
162
+ hash: 85383648681558491
160
163
  requirements: []
161
164
  rubyforge_project:
162
165
  rubygems_version: 1.8.24
@@ -164,12 +167,14 @@ signing_key:
164
167
  specification_version: 3
165
168
  summary: MusicBrainz Web Service wrapper with ActiveRecord-style models
166
169
  test_files:
170
+ - spec/bindings/relations_spec.rb
167
171
  - spec/bindings/release_group_search_spec.rb
168
172
  - spec/bindings/release_spec.rb
169
173
  - spec/bindings/track_search_spec.rb
170
174
  - spec/client_modules/cache_spec.rb
171
175
  - spec/deprecated/cache_config_spec.rb
172
176
  - spec/deprecated/proxy_config_spec.rb
177
+ - spec/fixtures/artist/search.xml
173
178
  - spec/fixtures/kasabian.xml
174
179
  - spec/fixtures/release_group/entity.xml
175
180
  - spec/fixtures/release_group/search.xml