rbrainz 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -2
- data/doc/README.rdoc +7 -1
- data/examples/getrelease.rb +1 -1
- data/examples/getuser.rb +2 -3
- data/examples/searchreleases.rb +4 -3
- data/examples/tag.rb +42 -0
- data/lib/rbrainz/core_ext/net_http_digest.rb +42 -5
- data/lib/rbrainz/model/collection.rb +4 -2
- data/lib/rbrainz/model/duration.rb +96 -0
- data/lib/rbrainz/model/relation.rb +6 -3
- data/lib/rbrainz/model/release.rb +6 -6
- data/lib/rbrainz/model/release_event.rb +23 -1
- data/lib/rbrainz/model/scored_collection.rb +10 -2
- data/lib/rbrainz/model/tag.rb +2 -3
- data/lib/rbrainz/utils/helper.rb +2 -2
- data/lib/rbrainz/version.rb +2 -2
- data/lib/rbrainz/webservice/filter.rb +4 -4
- data/lib/rbrainz/webservice/mbxml.rb +10 -6
- data/lib/rbrainz/webservice/query.rb +84 -7
- data/lib/rbrainz/webservice/webservice.rb +53 -25
- data/test/test-data/valid/release/Under_the_Pink_3.xml +1 -1
- data/test/test_collection.rb +2 -3
- data/test/test_mbxml.rb +31 -30
- data/test/test_release_event.rb +9 -1
- data/test/test_scored_collection.rb +11 -0
- metadata +22 -20
data/lib/rbrainz/model/tag.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: tag.rb
|
1
|
+
# $Id: tag.rb 181 2007-10-04 09:20:49Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -13,8 +13,7 @@ module MusicBrainz
|
|
13
13
|
#
|
14
14
|
# Tags are arbitrary labels assigned to entities by the users of MusicBrainz.
|
15
15
|
#
|
16
|
-
#
|
17
|
-
# be added in the near future.
|
16
|
+
# See:: http://wiki.musicbrainz.org/FolksonomyTagging
|
18
17
|
class Tag
|
19
18
|
# The tag text.
|
20
19
|
attr_accessor :text
|
data/lib/rbrainz/utils/helper.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: helper.rb
|
1
|
+
# $Id: helper.rb 173 2007-08-24 15:11:11Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Nigel Graham, Philipp Wolfer
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -25,7 +25,7 @@ module MusicBrainz
|
|
25
25
|
# includes the namespace or if _str_ is empty it will be returned unchanged.
|
26
26
|
def add_namespace(str, namespace=Model::NS_MMD_1)
|
27
27
|
unless str =~ /^#{namespace}/ or str.to_s.empty?
|
28
|
-
return namespace + str
|
28
|
+
return namespace + str.to_s
|
29
29
|
else
|
30
30
|
return str
|
31
31
|
end
|
data/lib/rbrainz/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: version.rb
|
1
|
+
# $Id: version.rb 172 2007-08-24 11:19:19Z phw $
|
2
2
|
#
|
3
3
|
# Version information.
|
4
4
|
#
|
@@ -10,6 +10,6 @@
|
|
10
10
|
module MusicBrainz
|
11
11
|
|
12
12
|
# The version of the RBrainz library.
|
13
|
-
RBRAINZ_VERSION = '0.
|
13
|
+
RBRAINZ_VERSION = '0.4.0'
|
14
14
|
|
15
15
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: filter.rb
|
1
|
+
# $Id: filter.rb 166 2007-08-10 08:56:09Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -50,7 +50,7 @@ module MusicBrainz
|
|
50
50
|
class ArtistFilter < AbstractFilter
|
51
51
|
|
52
52
|
# The parameter _filter_ is a hash with filter options. At least the
|
53
|
-
# <tt>:name</tt> filter must be specified.
|
53
|
+
# <tt>:name</tt> or <tt>:query</tt> filter must be specified.
|
54
54
|
#
|
55
55
|
# Available filter options:
|
56
56
|
# [:name] Fetch a list of artists with a matching name.
|
@@ -131,7 +131,7 @@ module MusicBrainz
|
|
131
131
|
class TrackFilter < AbstractFilter
|
132
132
|
|
133
133
|
# The parameter _filter_ is a hash with filter options. At least the
|
134
|
-
# <tt>:title</tt> filter must be specified.
|
134
|
+
# <tt>:title</tt>, <tt>:puid</tt> or <tt>:query</tt> filter must be specified.
|
135
135
|
#
|
136
136
|
# Available filter options:
|
137
137
|
# [:title] Fetch a list of tracks with a matching title.
|
@@ -182,7 +182,7 @@ module MusicBrainz
|
|
182
182
|
class LabelFilter < AbstractFilter
|
183
183
|
|
184
184
|
# The parameter _filter_ is a hash with filter options. At least the
|
185
|
-
# <tt>:name</tt> filter must be specified.
|
185
|
+
# <tt>:name</tt> or <tt>:query</tt> filter must be specified.
|
186
186
|
#
|
187
187
|
# Available filter options:
|
188
188
|
# [:name] Fetch a list of labels with a matching name.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: mbxml.rb
|
1
|
+
# $Id: mbxml.rb 189 2007-11-26 00:10:49Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -72,10 +72,11 @@ module MusicBrainz
|
|
72
72
|
end
|
73
73
|
|
74
74
|
# Read the XML string and create a list of entity models for the given
|
75
|
-
# entity type.
|
76
|
-
# +metadata+ element in
|
75
|
+
# entity type. The list is returned as a Model::ScoredCollection. There
|
76
|
+
# must be an entity-list element as a child of the +metadata+ element in
|
77
|
+
# the document.
|
77
78
|
#
|
78
|
-
# Returns an empty ScoredCollection if the list is empty or if no
|
79
|
+
# Returns an empty Model::ScoredCollection if the list is empty or if no
|
79
80
|
# entity-list element can be found.
|
80
81
|
def get_entity_list(entity_type, ns=Model::NS_MMD_1)
|
81
82
|
# Search for the first occuring node of type entity which is a child node
|
@@ -347,8 +348,8 @@ module MusicBrainz
|
|
347
348
|
# Iterate over a list of tags and add them to the target collection.
|
348
349
|
#
|
349
350
|
# The node must be of the type <em>tag-list</em>.
|
350
|
-
def read_tag_list(list_node, target_collection)
|
351
|
-
read_list(list_node, target_collection, 'tag') do |a|
|
351
|
+
def read_tag_list(list_node, target_collection, read_scores=false)
|
352
|
+
read_list(list_node, target_collection, 'tag', read_scores) do |a|
|
352
353
|
yield a if block_given?
|
353
354
|
end
|
354
355
|
end
|
@@ -380,6 +381,7 @@ module MusicBrainz
|
|
380
381
|
event.catalog_number = node.attributes['catalog-number']
|
381
382
|
event.barcode = node.attributes['barcode']
|
382
383
|
event.label = create_label(node.elements['label']) if node.elements['label']
|
384
|
+
event.format = Utils.add_namespace(node.attributes['format'])
|
383
385
|
|
384
386
|
return event
|
385
387
|
end
|
@@ -432,6 +434,8 @@ module MusicBrainz
|
|
432
434
|
# Read all defined data fields
|
433
435
|
if node.attributes['direction']
|
434
436
|
relation.direction = node.attributes['direction'].to_sym
|
437
|
+
else
|
438
|
+
relation.direction = :both
|
435
439
|
end
|
436
440
|
|
437
441
|
if node.attributes['type']
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: query.rb
|
1
|
+
# $Id: query.rb 174 2007-08-24 15:23:56Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -294,24 +294,101 @@ module MusicBrainz
|
|
294
294
|
|
295
295
|
# Submit track to PUID mappings.
|
296
296
|
#
|
297
|
-
# The <em>tracks2puids</em> parameter has to be a
|
298
|
-
#
|
299
|
-
#
|
300
|
-
#
|
297
|
+
# The <em>tracks2puids</em> parameter has to be a Hash or Array
|
298
|
+
# with track ID/PUID pairs. The track IDs are either instances of MBID,
|
299
|
+
# absolute URIs or the 36 character ASCII representation. PUIDs are
|
300
|
+
# 36 characters ASCII strings.
|
301
|
+
#
|
302
|
+
# Example:
|
303
|
+
# ws = Webservice::Webservice.new(
|
304
|
+
# :host => 'test.musicbrainz.org',
|
305
|
+
# :username => 'outsidecontext',
|
306
|
+
# :password => 'secret'
|
307
|
+
# )
|
308
|
+
#
|
309
|
+
# query = Webservice::Query.new(ws, :client_id=>'My Tagging App 1.0')
|
310
|
+
#
|
311
|
+
# query.submit_puids([
|
312
|
+
# ['90a56b15-4259-4a33-be13-20d5513504d5', '09ff336b-79e7-1303-f613-7f1cd0d5a346'],
|
313
|
+
# ['90a56b15-4259-4a33-be13-20d5513504d5', '18fd245f-bc0c-3361-9d61-61a225ed8c79'],
|
314
|
+
# ['6d9276af-b990-41b6-ad14-de2f128437ea', '3b633298-e671-957a-1f74-83fe71969ad0']
|
315
|
+
# ])
|
301
316
|
#
|
302
317
|
# Note that this method only works if a valid user name and
|
303
318
|
# password have been set. If username and/or password are incorrect,
|
304
319
|
# an AuthenticationError is raised. See the example in Query on
|
305
320
|
# how to supply authentication data.
|
306
321
|
#
|
322
|
+
# See:: http://test.musicbrainz.org/doc/PUID
|
307
323
|
# Raises:: ConnectionError, RequestError, AuthenticationError
|
308
324
|
def submit_puids(tracks2puids)
|
309
325
|
raise RequestError, 'Please supply a client ID' unless @client_id
|
310
326
|
params = [['client', @client_id.to_s]] # Encoded as utf-8
|
311
327
|
|
312
|
-
tracks2puids.each
|
328
|
+
tracks2puids.each do |track_id, puid|
|
329
|
+
track_id = Model::MBID.parse(track_id, :track).uuid
|
330
|
+
params << ['puid', track_id + ' ' + puid ]
|
331
|
+
end
|
313
332
|
|
314
|
-
@webservice.post(
|
333
|
+
@webservice.post(:track, :params=>params)
|
334
|
+
end
|
335
|
+
|
336
|
+
# Submit tags for an entity. _mbid_ must be an instance of MBID identifying
|
337
|
+
# the entity the tag should applied to and _tags_ is either and array or
|
338
|
+
# Collection of Tag objects or a string with comma separated tags.
|
339
|
+
#
|
340
|
+
# Note that this method only works if a valid user name and password have
|
341
|
+
# been set. The tags will be applied for the authenticated user. If
|
342
|
+
# username and/or password are incorrect, an AuthenticationError is raised.
|
343
|
+
# See the example in Query on how to supply authentication data.
|
344
|
+
#
|
345
|
+
# Example:
|
346
|
+
# ws = Webservice::Webservice.new(
|
347
|
+
# :host => 'test.musicbrainz.org',
|
348
|
+
# :username => 'outsidecontext',
|
349
|
+
# :password => 'secret'
|
350
|
+
# )
|
351
|
+
#
|
352
|
+
# query = Webservice::Query.new(ws)
|
353
|
+
#
|
354
|
+
# mbid = Model::MBID.new('http://musicbrainz.org/artist/10bf95b6-30e3-44f1-817f-45762cdc0de0')
|
355
|
+
# query.set_tags(mbid, 'doom metal, british')
|
356
|
+
#
|
357
|
+
# See:: Model::Tag
|
358
|
+
# Raises:: ConnectionError, RequestError, AuthenticationError
|
359
|
+
def submit_user_tags(mbid, tags)
|
360
|
+
mbid = Model::MBID.parse(mbid)
|
361
|
+
tag_string = tags.respond_to?(:to_ary) ? tags.to_ary.join(',') : tags.to_s
|
362
|
+
params = {:entity=>mbid.entity, :id=>mbid.uuid, :tags=>tag_string}
|
363
|
+
@webservice.post(:tag, :params=>params)
|
364
|
+
end
|
365
|
+
|
366
|
+
# Returns a Model::Collection of tags a user has applied to the entity
|
367
|
+
# identified by _mbid_.
|
368
|
+
#
|
369
|
+
# Note that this method only works if a valid user name and password have
|
370
|
+
# been set. Only the tags the authenticated user apllied to the entity will
|
371
|
+
# be returned. If username and/or password are incorrect, an
|
372
|
+
# AuthenticationError is raised. See the example in Query on how to supply
|
373
|
+
# authentication data.
|
374
|
+
#
|
375
|
+
# Example:
|
376
|
+
# ws = Webservice::Webservice.new(
|
377
|
+
# :host => 'test.musicbrainz.org',
|
378
|
+
# :username => 'outsidecontext',
|
379
|
+
# :password => 'secret'
|
380
|
+
# )
|
381
|
+
#
|
382
|
+
# query = Webservice::Query.new(ws)
|
383
|
+
#
|
384
|
+
# mbid = Model::MBID.new('http://musicbrainz.org/artist/10bf95b6-30e3-44f1-817f-45762cdc0de0')
|
385
|
+
# query.get_tags(mbid)
|
386
|
+
#
|
387
|
+
# See:: Model::Tag
|
388
|
+
# Raises:: ConnectionError, RequestError, ResponseError, AuthenticationError
|
389
|
+
def get_user_tags(mbid)
|
390
|
+
mbid = Model::MBID.parse(mbid)
|
391
|
+
return get_entities(:tag, "entity=#{mbid.entity}&id=#{mbid.uuid}").to_collection
|
315
392
|
end
|
316
393
|
|
317
394
|
private # ----------------------------------------------------------------
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: webservice.rb
|
1
|
+
# $Id: webservice.rb 182 2007-10-16 14:46:17Z nigel_graham $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -40,9 +40,9 @@ module MusicBrainz
|
|
40
40
|
#
|
41
41
|
# Options:
|
42
42
|
# [:id] A MBID if querying for a single ressource.
|
43
|
-
# [:
|
43
|
+
# [:params] A Hash or Array containing the data to post as key/value pairs.
|
44
44
|
# [:version] The version of the webservice to use. Defaults to 1.
|
45
|
-
def post(entity_type, options={ :id=>nil, :
|
45
|
+
def post(entity_type, options={ :id=>nil, :params=>[], :version=>1 })
|
46
46
|
raise NotImplementedError.new('Called abstract method.')
|
47
47
|
end
|
48
48
|
|
@@ -71,17 +71,26 @@ module MusicBrainz
|
|
71
71
|
# the server. Defaults to '/ws'.
|
72
72
|
# [:username] The username to authenticate with.
|
73
73
|
# [:password] The password to authenticate with.
|
74
|
-
# [:user_agent] Value sent in the User-Agent HTTP header. Defaults to
|
75
|
-
|
76
|
-
|
74
|
+
# [:user_agent] Value sent in the User-Agent HTTP header. Defaults to "rbrainz/#{RBRAINZ_VERSION}"
|
75
|
+
# [:proxy] URL for the proxy server to connect through
|
76
|
+
def initialize(options={ :host=>nil, :port=>nil, :path_prefix=>'/ws', :username=>nil, :password=>nil, :user_agent=>"rbrainz/#{RBRAINZ_VERSION}", :proxy=>nil })
|
77
|
+
Utils.check_options options, :host, :port, :path_prefix, :username, :password, :user_agent, :proxy
|
77
78
|
@host = options[:host] ? options[:host] : 'musicbrainz.org'
|
78
79
|
@port = options[:port] ? options[:port] : 80
|
79
80
|
@path_prefix = options[:path_prefix] ? options[:path_prefix] : '/ws'
|
80
81
|
@username = options[:username]
|
81
82
|
@password = options[:password]
|
82
|
-
@user_agent = options[:user_agent] ? options[:user_agent] :
|
83
|
+
@user_agent = options[:user_agent] ? options[:user_agent] : "rbrainz/#{RBRAINZ_VERSION}"
|
83
84
|
@open_timeout = nil
|
84
85
|
@read_timeout = nil
|
86
|
+
@proxy = {}
|
87
|
+
unless options[:proxy].nil?
|
88
|
+
uri = URI.parse( options[:proxy] )
|
89
|
+
@proxy[:host], @proxy[:port] = uri.host, uri.port
|
90
|
+
if uri.userinfo
|
91
|
+
@proxy[:username], @proxy[:password] = uri.userinfo.split(/:/)
|
92
|
+
end
|
93
|
+
end
|
85
94
|
end
|
86
95
|
|
87
96
|
# Query the Webservice with HTTP GET.
|
@@ -102,7 +111,7 @@ module MusicBrainz
|
|
102
111
|
url = URI.parse(create_uri(entity_type, options))
|
103
112
|
request = Net::HTTP::Get.new(url.request_uri)
|
104
113
|
request['User-Agent'] = @user_agent
|
105
|
-
connection = Net::HTTP.new(url.host, url.port)
|
114
|
+
connection = Net::HTTP.new(url.host, url.port, @proxy[:host], @proxy[:port])
|
106
115
|
|
107
116
|
# Set timeouts
|
108
117
|
connection.open_timeout = @open_timeout if @open_timeout
|
@@ -112,10 +121,18 @@ module MusicBrainz
|
|
112
121
|
begin
|
113
122
|
response = connection.start do |http|
|
114
123
|
response = http.request(request)
|
124
|
+
if response.is_a?(Net::HTTPProxyAuthenticationRequired) && @proxy[:user] && @proxy[:password]
|
125
|
+
request = Net::HTTP::Post.new(url.request_uri)
|
126
|
+
request['User-Agent'] = @user_agent
|
127
|
+
request.proxy_select_auth( @username, @password, response)
|
128
|
+
request.set_form_data(options[:params])
|
129
|
+
response = http.request(request)
|
130
|
+
end
|
131
|
+
|
115
132
|
if response.is_a?(Net::HTTPUnauthorized) && @username && @password
|
116
133
|
request = Net::HTTP::Get.new(url.request_uri)
|
117
134
|
request['User-Agent'] = @user_agent
|
118
|
-
request.
|
135
|
+
request.select_auth @username, @password, response
|
119
136
|
response = http.request(request)
|
120
137
|
end
|
121
138
|
response
|
@@ -149,20 +166,20 @@ module MusicBrainz
|
|
149
166
|
#
|
150
167
|
# Options:
|
151
168
|
# [:id] A MBID if querying for a single ressource.
|
152
|
-
# [:
|
169
|
+
# [:params] A Hash or Array containing the data to post as key/value pairs.
|
153
170
|
# [:version] The version of the webservice to use. Defaults to 1.
|
154
171
|
#
|
155
172
|
# Raises:: ConnectionError, RequestError, AuthenticationError,
|
156
173
|
# ResourceNotFoundError
|
157
174
|
#
|
158
175
|
# See:: IWebservice#post
|
159
|
-
def post(entity_type, options={:id=>nil, :
|
160
|
-
Utils.check_options options, :id, :
|
176
|
+
def post(entity_type, options={ :id=>nil, :params=>[], :version=>1 })
|
177
|
+
Utils.check_options options, :id, :params, :version
|
161
178
|
url = URI.parse(create_uri(entity_type, options))
|
162
179
|
request = Net::HTTP::Post.new(url.request_uri)
|
163
180
|
request['User-Agent'] = @user_agent
|
164
|
-
request.set_form_data(options[:
|
165
|
-
connection = Net::HTTP.new(url.host, url.port)
|
181
|
+
request.set_form_data(options[:params])
|
182
|
+
connection = Net::HTTP.new(url.host, url.port, @proxy[:host], @proxy[:port])
|
166
183
|
|
167
184
|
# Set timeouts
|
168
185
|
connection.open_timeout = @open_timeout if @open_timeout
|
@@ -173,11 +190,18 @@ module MusicBrainz
|
|
173
190
|
response = connection.start do |http|
|
174
191
|
response = http.request(request)
|
175
192
|
|
193
|
+
if response.is_a?(Net::HTTPProxyAuthenticationRequired) && @proxy[:user] && @proxy[:password]
|
194
|
+
request = Net::HTTP::Post.new(url.request_uri)
|
195
|
+
request['User-Agent'] = @user_agent
|
196
|
+
request.proxy_select_auth( @username, @password, response)
|
197
|
+
request.set_form_data(options[:params])
|
198
|
+
response = http.request(request)
|
199
|
+
end
|
176
200
|
if response.is_a?(Net::HTTPUnauthorized) && @username && @password
|
177
201
|
request = Net::HTTP::Post.new(url.request_uri)
|
178
202
|
request['User-Agent'] = @user_agent
|
179
|
-
request.
|
180
|
-
request.set_form_data(options[:
|
203
|
+
request.select_auth( @username, @password, response)
|
204
|
+
request.set_form_data(options[:params])
|
181
205
|
response = http.request(request)
|
182
206
|
end
|
183
207
|
response
|
@@ -205,9 +229,10 @@ module MusicBrainz
|
|
205
229
|
private # ----------------------------------------------------------------
|
206
230
|
|
207
231
|
# Builds a request URI for querying the webservice.
|
208
|
-
def create_uri(entity_type, options = {:id
|
232
|
+
def create_uri(entity_type, options = {:id=>nil, :include=>nil, :filter=>nil, :version=>1, :type=>nil})
|
209
233
|
# Make sure the version is set
|
210
234
|
options[:version] = 1 if options[:version].nil?
|
235
|
+
options[:type] = 'xml' if options[:type].nil?
|
211
236
|
|
212
237
|
# Build the URI
|
213
238
|
if options[:id]
|
@@ -217,16 +242,19 @@ module MusicBrainz
|
|
217
242
|
id = Model::MBID.parse(id, entity_type)
|
218
243
|
end
|
219
244
|
|
220
|
-
uri = 'http://%s:%d%s/%d/%s/%s
|
221
|
-
[@host, @port, @path_prefix, options[:version],
|
222
|
-
entity_type, id.uuid, 'xml']
|
245
|
+
uri = 'http://%s:%d%s/%d/%s/%s' %
|
246
|
+
[@host, @port, @path_prefix, options[:version], entity_type, id.uuid]
|
223
247
|
else
|
224
|
-
uri = 'http://%s:%d%s/%d/%s
|
225
|
-
[@host, @port, @path_prefix, options[:version],
|
226
|
-
entity_type, 'xml']
|
248
|
+
uri = 'http://%s:%d%s/%d/%s/' %
|
249
|
+
[@host, @port, @path_prefix, options[:version], entity_type]
|
227
250
|
end
|
228
|
-
|
229
|
-
|
251
|
+
|
252
|
+
# Append the querystring
|
253
|
+
querystring = []
|
254
|
+
querystring << 'type=' + URI.escape(options[:type]) unless options[:type].nil?
|
255
|
+
querystring << options[:include].to_s unless options[:include].nil?
|
256
|
+
querystring << options[:filter].to_s unless options[:filter].nil?
|
257
|
+
uri += '?' + querystring.join('&') unless querystring.empty?
|
230
258
|
return uri
|
231
259
|
end
|
232
260
|
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<name>Tori Amos</name>
|
7
7
|
</artist>
|
8
8
|
<release-event-list>
|
9
|
-
<event date="1994-01-31" catalog-number="82567-2" barcode="07567825672">
|
9
|
+
<event date="1994-01-31" catalog-number="82567-2" barcode="07567825672" format="CD">
|
10
10
|
<label id="50c384a2-0b44-401b-b893-8181173339c7">
|
11
11
|
<name>Atlantic Records</name>
|
12
12
|
</label>
|
data/test/test_collection.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_collection.rb
|
1
|
+
# $Id: test_collection.rb 172 2007-08-24 11:19:19Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Philipp Wolfer
|
@@ -36,8 +36,7 @@ class TestCollection < Test::Unit::TestCase
|
|
36
36
|
# Fill the collection
|
37
37
|
assert_nothing_raised {
|
38
38
|
collection << @artist_one
|
39
|
-
collection << @artist_two
|
40
|
-
collection << @artist_three
|
39
|
+
collection << @artist_two << @artist_three
|
41
40
|
}
|
42
41
|
assert_equal 3, collection.size
|
43
42
|
assert !collection.empty?
|
data/test/test_mbxml.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# $Id: test_mbxml.rb
|
1
|
+
# $Id: test_mbxml.rb 189 2007-11-26 00:10:49Z phw $
|
2
2
|
#
|
3
3
|
# Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
|
4
4
|
# Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
|
@@ -15,12 +15,12 @@ include MusicBrainz
|
|
15
15
|
# We test against the official test files supplied by
|
16
16
|
# MusicBrainz. See http://bugs.musicbrainz.org/browser/mmd-schema/trunk/test-data
|
17
17
|
class TestMBXML < Test::Unit::TestCase
|
18
|
-
|
18
|
+
|
19
19
|
DATA_PATH = 'test/test-data/valid/'
|
20
|
-
|
20
|
+
|
21
21
|
def setup
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
def teardown
|
25
25
|
end
|
26
26
|
|
@@ -54,7 +54,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
54
54
|
assert_equal nil, mbxml.get_entity(:release)
|
55
55
|
assert_equal nil, mbxml.get_entity(:track)
|
56
56
|
assert_equal nil, mbxml.get_entity(:label)
|
57
|
-
|
57
|
+
|
58
58
|
artist_list = mbxml.get_entity_list(:artist)
|
59
59
|
assert_equal 0, artist_list.offset
|
60
60
|
assert_equal 47, artist_list.count
|
@@ -100,7 +100,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
100
100
|
assert_equal 'composer', artist.tags[3].text
|
101
101
|
assert_equal 120, artist.tags[3].count
|
102
102
|
end
|
103
|
-
|
103
|
+
|
104
104
|
def test_artist_tori_amos_1
|
105
105
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'artist/Tori_Amos_1.xml')
|
106
106
|
artist = mbxml.get_entity(:artist)
|
@@ -111,7 +111,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
111
111
|
assert_equal 'Amos, Tori', artist.sort_name
|
112
112
|
assert_equal '1963-08-22', artist.begin_date.to_s
|
113
113
|
end
|
114
|
-
|
114
|
+
|
115
115
|
def test_artist_tori_amos_2
|
116
116
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'artist/Tori_Amos_2.xml')
|
117
117
|
artist = mbxml.get_entity(:artist)
|
@@ -132,7 +132,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
132
132
|
assert_equal artist, artist.releases[2].artist
|
133
133
|
assert_equal 4, artist.releases[2].discs.count
|
134
134
|
end
|
135
|
-
|
135
|
+
|
136
136
|
def test_artist_tori_amos_3
|
137
137
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'artist/Tori_Amos_3.xml')
|
138
138
|
artist = mbxml.get_entity(:artist)
|
@@ -157,7 +157,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
157
157
|
assert_equal Model::NS_REL_1 + 'Wikipedia', url_rels[1].type
|
158
158
|
assert_equal 'http://en.wikipedia.org/wiki/Tori_Amos', url_rels[1].target
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
def test_artist_tori_amos_4
|
162
162
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'artist/Tori_Amos_4.xml')
|
163
163
|
artist = mbxml.get_entity(:artist)
|
@@ -175,7 +175,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
175
175
|
assert_equal 'Latn', artist.aliases[2].script
|
176
176
|
assert_equal Model::NS_MMD_1 + 'Misspelling', artist.aliases[2].type
|
177
177
|
end
|
178
|
-
|
178
|
+
|
179
179
|
def test_artist_tori_amos_5
|
180
180
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'artist/Tori_Amos_5.xml')
|
181
181
|
artist = mbxml.get_entity(:artist)
|
@@ -193,14 +193,14 @@ class TestMBXML < Test::Unit::TestCase
|
|
193
193
|
assert artist.releases[0].types.include?(Model::Release::TYPE_ALBUM)
|
194
194
|
assert artist.releases[0].types.include?(Model::Release::TYPE_OFFICIAL)
|
195
195
|
end
|
196
|
-
|
196
|
+
|
197
197
|
def test_release_search
|
198
198
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'release/search_result_1.xml')
|
199
199
|
assert_equal nil, mbxml.get_entity(:artist)
|
200
200
|
assert_equal nil, mbxml.get_entity(:release)
|
201
201
|
assert_equal nil, mbxml.get_entity(:track)
|
202
202
|
assert_equal nil, mbxml.get_entity(:label)
|
203
|
-
|
203
|
+
|
204
204
|
release_list = mbxml.get_entity_list(:release)
|
205
205
|
assert_equal 0, release_list.offset
|
206
206
|
assert_equal 234, release_list.count
|
@@ -238,14 +238,14 @@ class TestMBXML < Test::Unit::TestCase
|
|
238
238
|
assert_equal 9, release.tracks.size
|
239
239
|
assert_equal '430aa3d3-3dac-4bd5-857d-eb10212ffefb', release.tracks[0].id.uuid
|
240
240
|
assert_equal 'd315625a-3976-41b4-b2e0-43336b0f67bc', release.tracks[8].id.uuid
|
241
|
-
|
241
|
+
|
242
242
|
url_rels = release.get_relations(:target_type => Model::Relation::TO_URL)
|
243
243
|
assert_equal 2, url_rels.size, release.get_relations.inspect
|
244
244
|
assert_equal Model::NS_REL_1 + 'Wikipedia', url_rels[0].type
|
245
|
-
assert_equal
|
245
|
+
assert_equal Model::Relation::DIR_BOTH, url_rels[0].direction
|
246
246
|
assert_equal 'http://en.wikipedia.org/wiki/Highway_61_Revisited', url_rels[0].target
|
247
247
|
assert_equal Model::NS_REL_1 + 'AmazonAsin', url_rels[1].type
|
248
|
-
assert_equal
|
248
|
+
assert_equal Model::Relation::DIR_BOTH, url_rels[1].direction
|
249
249
|
assert_equal 'http://www.amazon.com/gp/product/B0000024SI', url_rels[1].target
|
250
250
|
end
|
251
251
|
|
@@ -286,7 +286,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
286
286
|
assert_equal 3, release.discs.size
|
287
287
|
assert_equal 'ILKp3.bZmvoMO7wSrq1cw7WatfA-', release.discs[0].id
|
288
288
|
end
|
289
|
-
|
289
|
+
|
290
290
|
def test_release_little_earthquakes_2
|
291
291
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'release/Little_Earthquakes_2.xml')
|
292
292
|
release = mbxml.get_entity(:release)
|
@@ -309,7 +309,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
309
309
|
assert_equal 'Crucify', release.tracks[0].title
|
310
310
|
assert_equal 301186, release.tracks[0].duration
|
311
311
|
end
|
312
|
-
|
312
|
+
|
313
313
|
# This is a various artist release.
|
314
314
|
def test_release_mission_impossible_2
|
315
315
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'release/Mission_Impossible_2.xml')
|
@@ -330,7 +330,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
330
330
|
assert_not_equal release.artist, track.artist
|
331
331
|
}
|
332
332
|
end
|
333
|
-
|
333
|
+
|
334
334
|
def test_release_under_the_pink_1
|
335
335
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'release/Under_the_Pink_1.xml')
|
336
336
|
release = mbxml.get_entity(:release)
|
@@ -349,7 +349,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
349
349
|
assert_equal 4, release.discs.count
|
350
350
|
assert_equal 12, release.tracks.count
|
351
351
|
end
|
352
|
-
|
352
|
+
|
353
353
|
def test_release_under_the_pink_2
|
354
354
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'release/Under_the_Pink_2.xml')
|
355
355
|
release = mbxml.get_entity(:release)
|
@@ -364,7 +364,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
364
364
|
assert_equal '0a984e3b-e38a-4b86-80be-f3a3eb1114ca', release.tracks[0].id.uuid
|
365
365
|
assert_equal 'God', release.tracks[0].title
|
366
366
|
end
|
367
|
-
|
367
|
+
|
368
368
|
def test_release_under_the_pink_3
|
369
369
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'release/Under_the_Pink_3.xml')
|
370
370
|
release = mbxml.get_entity(:release)
|
@@ -381,15 +381,16 @@ class TestMBXML < Test::Unit::TestCase
|
|
381
381
|
assert_equal '07567825672', release.release_events[0].barcode
|
382
382
|
assert_equal '50c384a2-0b44-401b-b893-8181173339c7', release.release_events[0].label.id.uuid
|
383
383
|
assert_equal 'Atlantic Records', release.release_events[0].label.name
|
384
|
+
assert_equal Model::ReleaseEvent::FORMAT_CD, release.release_events[0].format
|
384
385
|
end
|
385
|
-
|
386
|
+
|
386
387
|
def test_track_search
|
387
388
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'track/search_result_1.xml')
|
388
389
|
assert_equal nil, mbxml.get_entity(:artist)
|
389
390
|
assert_equal nil, mbxml.get_entity(:release)
|
390
391
|
assert_equal nil, mbxml.get_entity(:track)
|
391
392
|
assert_equal nil, mbxml.get_entity(:label)
|
392
|
-
|
393
|
+
|
393
394
|
track_list = mbxml.get_entity_list(:track)
|
394
395
|
assert_equal 7, track_list.offset
|
395
396
|
assert_equal 100, track_list.count
|
@@ -414,7 +415,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
414
415
|
assert_equal 'Silent All These Years', track.title
|
415
416
|
assert_equal 253466, track.duration
|
416
417
|
end
|
417
|
-
|
418
|
+
|
418
419
|
def test_track_silent_all_these_years_2
|
419
420
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'track/Silent_All_These_Years_2.xml')
|
420
421
|
track = mbxml.get_entity(:track)
|
@@ -431,7 +432,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
431
432
|
assert track_rels[0].target.is_a?(Model::Track)
|
432
433
|
assert_equal '5bcd4eaa-fae7-465f-9f03-d005b959ed02', track_rels[0].target.artist.id.uuid
|
433
434
|
end
|
434
|
-
|
435
|
+
|
435
436
|
def test_track_silent_all_these_years_3
|
436
437
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'track/Silent_All_These_Years_3.xml')
|
437
438
|
track = mbxml.get_entity(:track)
|
@@ -443,7 +444,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
443
444
|
assert_equal 'c2a2cee5-a8ca-4f89-a092-c3e1e65ab7e6', track.puids[0]
|
444
445
|
assert_equal '42ab76ea-5d42-4259-85d7-e7f2c69e4485', track.puids[6]
|
445
446
|
end
|
446
|
-
|
447
|
+
|
447
448
|
def test_track_silent_all_these_years_4
|
448
449
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'track/Silent_All_These_Years_4.xml')
|
449
450
|
track = mbxml.get_entity(:track)
|
@@ -458,7 +459,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
458
459
|
assert_equal 'c2a2cee5-a8ca-4f89-a092-c3e1e65ab7e6', track.puids[0]
|
459
460
|
assert_equal '42ab76ea-5d42-4259-85d7-e7f2c69e4485', track.puids[6]
|
460
461
|
end
|
461
|
-
|
462
|
+
|
462
463
|
# This test is similiar to silent_all_these_years_3, but it includes an
|
463
464
|
# schema exctension which mustn't disturb the parsing.
|
464
465
|
def test_track_silent_all_these_years_5
|
@@ -482,14 +483,14 @@ class TestMBXML < Test::Unit::TestCase
|
|
482
483
|
assert_equal 253466, track.duration
|
483
484
|
assert_equal 0, track.tags.size
|
484
485
|
end
|
485
|
-
|
486
|
+
|
486
487
|
def test_label_search
|
487
488
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'label/search_result_1.xml')
|
488
489
|
assert_equal nil, mbxml.get_entity(:artist)
|
489
490
|
assert_equal nil, mbxml.get_entity(:release)
|
490
491
|
assert_equal nil, mbxml.get_entity(:track)
|
491
492
|
assert_equal nil, mbxml.get_entity(:label)
|
492
|
-
|
493
|
+
|
493
494
|
label_list = mbxml.get_entity_list(:label)
|
494
495
|
assert_equal 0, label_list.offset
|
495
496
|
assert_equal 2, label_list.count
|
@@ -518,7 +519,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
518
519
|
assert_equal 'US', label.country
|
519
520
|
assert_equal '1947', label.begin_date.to_s
|
520
521
|
end
|
521
|
-
|
522
|
+
|
522
523
|
def test_label_atlantic_records_2
|
523
524
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'label/Atlantic_Records_2.xml')
|
524
525
|
label = mbxml.get_entity(:label)
|
@@ -534,7 +535,7 @@ class TestMBXML < Test::Unit::TestCase
|
|
534
535
|
assert_equal 1, label.aliases.size
|
535
536
|
assert_equal 'Atlantic Rec.', label.aliases[0].name
|
536
537
|
end
|
537
|
-
|
538
|
+
|
538
539
|
def test_label_atlantic_records_3
|
539
540
|
mbxml = Webservice::MBXML.new File.new(DATA_PATH + 'label/Atlantic_Records_3.xml')
|
540
541
|
label = mbxml.get_entity(:label)
|