rbrainz 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,14 @@
1
1
  = Changelog
2
2
 
3
+ == 0.3.0 (2007-08-11)
4
+ * BUG: Relation end date was not set correctly in MBXML.
5
+ * NEW: Allow release type constants to be passed to include and filter objects.
6
+ * NEW: Methods Utils.add_namespace and Utils.remove_namespace.
7
+ * NEW: Methods Release#earliest_release_event and Release#earliest_release_date
8
+ * NEW: Entity#get_relations allows string with or without namespace for
9
+ target_type, relation_type and required_attributes
10
+ * BUG: Corrected constant TYPE_PSEUDO_RELEASE
11
+
3
12
  == 0.2.1 (2007-07-24)
4
13
  * Erroneous date strings in the XML are ignored. No error is raised and nil
5
14
  is set for the date.
@@ -40,4 +49,4 @@
40
49
  == 0.1.0 (2007-05-23)
41
50
  * Initial release
42
51
 
43
- $Id: CHANGES 156 2007-07-24 17:47:07Z phw $
52
+ $Id: CHANGES 167 2007-08-11 09:18:30Z phw $
@@ -3,7 +3,7 @@
3
3
  # Example script which queries the database for an
4
4
  # artist and displays the artist's data.
5
5
  #
6
- # $Id: getartist.rb 145 2007-07-19 13:11:44Z phw $
6
+ # $Id: getartist.rb 162 2007-07-29 17:44:11Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -28,7 +28,7 @@ mbid = Model::MBID.parse(id, :artist)
28
28
  # fetched.
29
29
  artist_includes = Webservice::ArtistIncludes.new(
30
30
  :aliases => true,
31
- :releases => ['Album', 'Official']
31
+ :releases => [Model::Release::TYPE_ALBUM, Model::Release::TYPE_OFFICIAL]
32
32
  )
33
33
 
34
34
  # Create a new Query object which will provide
data/examples/getlabel.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Example script which queries the database for an
4
4
  # label and displays the label's data.
5
5
  #
6
- # $Id: getlabel.rb 150 2007-07-24 08:16:16Z phw $
6
+ # $Id: getlabel.rb 160 2007-07-27 13:18:04Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -3,7 +3,7 @@
3
3
  # Example script which queries the database for an
4
4
  # release and displays the release's data.
5
5
  #
6
- # $Id: getrelease.rb 150 2007-07-24 08:16:16Z phw $
6
+ # $Id: getrelease.rb 160 2007-07-27 13:18:04Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -27,7 +27,8 @@ mbid = Model::MBID.parse(id, :release)
27
27
  # on the release will be fetched as well.
28
28
  release_includes = Webservice::ReleaseIncludes.new(
29
29
  :artist => true,
30
- :tracks => true
30
+ :tracks => true,
31
+ :release_events => true
31
32
  )
32
33
 
33
34
  # Create a new Query object which will provide
@@ -47,4 +48,9 @@ ID : #{release.id.uuid}
47
48
  Title : #{release.title}
48
49
  Artist : #{release.artist.unique_name}
49
50
  Tracks : #{release.tracks.to_a.join("\r\n ")}
50
- EOF
51
+ Release Events:
52
+ EOF
53
+
54
+ release.release_events.each do |event|
55
+ puts "#{event.date} #{Utils.get_country_name(event.country)}"
56
+ end
data/examples/gettrack.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  # Example script which queries the database for an
4
4
  # track and displays the track's data.
5
5
  #
6
- # $Id: gettrack.rb 150 2007-07-24 08:16:16Z phw $
6
+ # $Id: gettrack.rb 160 2007-07-27 13:18:04Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -3,7 +3,7 @@
3
3
  # Example script which searches the database for
4
4
  # labels and displays the label's data.
5
5
  #
6
- # $Id: searchlabels.rb 150 2007-07-24 08:16:16Z phw $
6
+ # $Id: searchlabels.rb 160 2007-07-27 13:18:04Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -3,7 +3,7 @@
3
3
  # Example script which searches the database for
4
4
  # releases and displays the release data.
5
5
  #
6
- # $Id: searchreleases.rb 150 2007-07-24 08:16:16Z phw $
6
+ # $Id: searchreleases.rb 160 2007-07-27 13:18:04Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -3,7 +3,7 @@
3
3
  # Example script which searches the database for
4
4
  # tracks and displays the track data.
5
5
  #
6
- # $Id: searchtracks.rb 150 2007-07-24 08:16:16Z phw $
6
+ # $Id: searchtracks.rb 160 2007-07-27 13:18:04Z phw $
7
7
 
8
8
  # Just make sure we can run this example from the command
9
9
  # line even if RBrainz is not yet installed properly.
@@ -1,4 +1,4 @@
1
- # $Id: entity.rb 145 2007-07-19 13:11:44Z phw $
1
+ # $Id: entity.rb 162 2007-07-29 17:44:11Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -137,8 +137,9 @@ module MusicBrainz
137
137
  :required_attributes => [], :direction => nil})
138
138
  Utils.check_options options,
139
139
  :target_type, :relation_type, :required_attributes, :direction
140
- target_type = options[:target_type]
141
- relation_type = options[:relation_type]
140
+
141
+ target_type = Utils.add_namespace(options[:target_type], NS_REL_1)
142
+ relation_type = Utils.add_namespace(options[:relation_type], NS_REL_1)
142
143
  required_attributes =
143
144
  options[:required_attributes] ? options[:required_attributes] : []
144
145
  direction = options[:direction]
@@ -160,7 +161,7 @@ module MusicBrainz
160
161
 
161
162
  # Filter for attributes
162
163
  #
163
- required = required_attributes.to_set
164
+ required = required_attributes.map{|a| Utils.add_namespace(a, NS_REL_1)}.to_set
164
165
  result.find_all do |r|
165
166
  required.subset?( r.attributes.to_set )
166
167
  end
@@ -1,4 +1,4 @@
1
- # $Id: release.rb 145 2007-07-19 13:11:44Z phw $
1
+ # $Id: release.rb 167 2007-08-11 09:18:30Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -22,26 +22,58 @@ module MusicBrainz
22
22
  #
23
23
  # See:: http://musicbrainz.org/doc/Release.
24
24
  # Note:: The current MusicBrainz server implementation supports only a
25
- # limited set of types.
26
- #
25
+ # limited set of types. See http://wiki.musicbrainz.org/ReleaseAttribute
26
+ # for more information.
27
27
  class Release < Entity
28
28
 
29
+ # A type for not a type. Currently unsupported by MusicBrainz
30
+ TYPE_NONE = NS_MMD_1 + 'None'
31
+
32
+ # An album, perhaps better defined as a "Long Play" (LP) release,
33
+ # generally consists of previously unreleased material. This includes
34
+ # release re-issues, with or without bonus tracks.
29
35
  TYPE_ALBUM = NS_MMD_1 + 'Album'
36
+ # An audiobook is a book read by a narrator without music.
30
37
  TYPE_AUDIOBOOK = NS_MMD_1 + 'Audiobook'
31
- TYPE_BOOTLEG = NS_MMD_1 + 'Bootleg'
38
+ # A compilation is a collection of previously released tracks by one or
39
+ # more artists. Please note that this is a simplified description of a
40
+ # compilation.
32
41
  TYPE_COMPILATION = NS_MMD_1 + 'Compilation'
42
+ # An EP is a so-called "Extended Play" release and often contains the
43
+ # letters EP in the title.
33
44
  TYPE_EP = NS_MMD_1 + 'EP'
45
+ # An interview release contains an interview, generally with an Artist.
34
46
  TYPE_INTERVIEW = NS_MMD_1 + 'Interview'
47
+ # A release that was recorded live.
35
48
  TYPE_LIVE = NS_MMD_1 + 'Live'
36
- TYPE_NONE = NS_MMD_1 + 'None'
37
- TYPE_OFFICIAL = NS_MMD_1 + 'Official'
38
- TYPE_OTHER = NS_MMD_1 + 'Other'
39
- TYPE_PROMOTION = NS_MMD_1 + 'Promotion'
40
- TYPE_PSEUDO_RELEASE = NS_MMD_1 + 'Pseudo-Release'
49
+ # A release that primarily contains remixed material.
41
50
  TYPE_REMIX = NS_MMD_1 + 'Remix'
51
+ # A single typically has one main song and possibly a handful of
52
+ # additional tracks or remixes of the main track. A single is usually
53
+ # named after its main song.
42
54
  TYPE_SINGLE = NS_MMD_1 + 'Single'
55
+ # A soundtrack is the musical score to a movie, TV series, stage show,
56
+ # computer game etc.
43
57
  TYPE_SOUNDTRACK = NS_MMD_1 + 'Soundtrack'
58
+ # Non-music spoken word releases.
44
59
  TYPE_SPOKENWORD = NS_MMD_1 + 'Spokenword'
60
+ # Any release that does not fit or can't decisively be placed in any of
61
+ # the categories above.
62
+ TYPE_OTHER = NS_MMD_1 + 'Other'
63
+
64
+ # Any release officially sanctioned by the artist and/or their record
65
+ # company. (Most releases will fit into this category.)
66
+ TYPE_OFFICIAL = NS_MMD_1 + 'Official'
67
+ # A giveaway release or a release intended to promote an upcoming official
68
+ # release. (e.g. prerelease albums or releases included with a magazine,
69
+ # versions supplied to radio DJs for air-play, etc).
70
+ TYPE_PROMOTION = NS_MMD_1 + 'Promotion'
71
+ # An unofficial/underground release that was not sanctioned by the artist
72
+ # and/or the record company.
73
+ TYPE_BOOTLEG = NS_MMD_1 + 'Bootleg'
74
+ # A pseudo-release is a duplicate release for translation/transliteration
75
+ # purposes.
76
+ TYPE_PSEUDO_RELEASE = NS_MMD_1 + 'Pseudo-Release'
45
77
 
46
78
  # See Entity::ENTITY_TYPE.
47
79
  ENTITY_TYPE = :release # :nodoc:
@@ -126,6 +158,32 @@ module MusicBrainz
126
158
  tracks.all {|track| !track.artist || track.artist.id == artist.id }
127
159
  end
128
160
 
161
+ # Returns the earliest release date as an IncompleteDate.
162
+ #
163
+ # This favours complete dates. For example, '2006-09' is
164
+ # returned if there is '2000', too. If there is no release
165
+ # event associated with this release, +nil+ is returned.
166
+ #
167
+ # See:: earliest_release_date
168
+ def earliest_release_event
169
+ earliest_event = nil
170
+ release_events.each do |event|
171
+ if earliest_event.nil? or (event.date and
172
+ (event.date <= earliest_event.date or event.date.between?(earliest_event.date)))
173
+ earliest_event = event
174
+ end
175
+ end
176
+ return earliest_event
177
+ end
178
+
179
+ # Returns the earliest release event or +nil+.
180
+ #
181
+ # See:: earliest_release_event
182
+ def earliest_release_date
183
+ event = earliest_release_event
184
+ event ? event.date : nil
185
+ end
186
+
129
187
  # Returns the string representation for this release.
130
188
  #
131
189
  # Returns #title converted into a string.
@@ -1,4 +1,4 @@
1
- # $Id: helper.rb 141 2007-07-17 14:21:12Z phw $
1
+ # $Id: helper.rb 158 2007-07-25 16:19:19Z phw $
2
2
  #
3
3
  # Author:: Nigel Graham, Philipp Wolfer
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -8,14 +8,39 @@
8
8
  module MusicBrainz
9
9
  module Utils
10
10
 
11
- # Check an options hash for required options.
12
- # Raises an ArgumentError if unknown options are present in the hash.
13
- def self.check_options(options, *optdecl) # :nodoc:
14
- h = options.dup
15
- optdecl.each do |name|
16
- h.delete name
11
+ class << self
12
+
13
+ # Remove the given _namespace_ from _str_. Will return _str_ with the
14
+ # namespace removed. If the namespace was not present in _str_ it will
15
+ # be returned unchanged.
16
+ def remove_namespace(str, namespace=Model::NS_MMD_1)
17
+ if str =~ /^#{namespace}(.*)/
18
+ return $1
19
+ else
20
+ return str
21
+ end
17
22
  end
18
- raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
23
+
24
+ # Will return the given _str_ extended by _namespace_. If _str_ already
25
+ # includes the namespace or if _str_ is empty it will be returned unchanged.
26
+ def add_namespace(str, namespace=Model::NS_MMD_1)
27
+ unless str =~ /^#{namespace}/ or str.to_s.empty?
28
+ return namespace + str
29
+ else
30
+ return str
31
+ end
32
+ end
33
+
34
+ # Check an options hash for required options.
35
+ # Raises an ArgumentError if unknown options are present in the hash.
36
+ def check_options(options, *optdecl) # :nodoc:
37
+ h = options.dup
38
+ optdecl.each do |name|
39
+ h.delete name
40
+ end
41
+ raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
42
+ end
43
+
19
44
  end
20
45
 
21
46
  end
@@ -1,4 +1,4 @@
1
- # $Id: version.rb 153 2007-07-24 09:04:25Z phw $
1
+ # $Id: version.rb 164 2007-08-07 07:40:32Z 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.2.1'
13
+ RBRAINZ_VERSION = '0.3.0'
14
14
 
15
15
  end
@@ -1,4 +1,4 @@
1
- # $Id: filter.rb 148 2007-07-19 17:26:33Z phw $
1
+ # $Id: filter.rb 159 2007-07-25 16:53:32Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -84,8 +84,9 @@ module MusicBrainz
84
84
  # (36 character ASCII representation). If this is given,
85
85
  # the artist parameter is ignored.
86
86
  # [:releasetypes] The returned releases must match all of the given
87
- # release types. This is a list of space separated values
88
- # like Official, Bootleg, Album, Compilation, etc.
87
+ # release types. This is either an array of release types
88
+ # as defined in Model::Release or a string of space separated
89
+ # values like Official, Bootleg, Album, Compilation etc.
89
90
  # [:count] Number of tracks in the release.
90
91
  # [:date] Earliest release date for the release.
91
92
  # [:asin] The Amazon ASIN.
@@ -108,12 +109,20 @@ module MusicBrainz
108
109
  @filter[:discid] = filter[:discid] if filter[:discid]
109
110
  @filter[:artist] = filter[:artist] if filter[:artist]
110
111
  @filter[:artistid] = filter[:artistid] if filter[:artistid]
111
- @filter[:releasetypes] = filter[:releasetypes] if filter[:releasetypes]
112
112
  @filter[:count] = filter[:count] if filter[:count]
113
113
  @filter[:date] = filter[:date] if filter[:date]
114
114
  @filter[:asin] = filter[:asin] if filter[:asin]
115
115
  @filter[:lang] = filter[:lang] if filter[:lang]
116
116
  @filter[:script] = filter[:script] if filter[:script]
117
+
118
+ if releasetypes = filter[:releasetypes]
119
+ if releasetypes.respond_to?(:to_a)
120
+ releasetypes = releasetypes.to_a.map do |type|
121
+ Utils.remove_namespace(type)
122
+ end.join(' ')
123
+ end
124
+ @filter[:releasetypes] = releasetypes
125
+ end
117
126
  end
118
127
 
119
128
  end
@@ -138,7 +147,8 @@ module MusicBrainz
138
147
  # parameter is ignored.
139
148
  # [:puid] The returned tracks have to match the given PUID.
140
149
  # [:count] Number of tracks on the release.
141
- # [:releasetype] The type of the release this track appears on
150
+ # [:releasetype] The type of the release this track appears on. See
151
+ # Model::Release for possible values.
142
152
  # [:limit] The maximum number of tracks returned. Defaults
143
153
  # to 25, the maximum allowed value is 100.
144
154
  # [:offset] Return search results starting at a given offset. Used
@@ -161,7 +171,9 @@ module MusicBrainz
161
171
  @filter[:releaseid] = filter[:releaseid] if filter[:releaseid]
162
172
  @filter[:puid] = filter[:puid] if filter[:puid]
163
173
  @filter[:count] = filter[:count] if filter[:count]
164
- @filter[:releasetype] = filter[:releasetype] if filter[:releasetype]
174
+ if filter[:releasetype]
175
+ @filter[:releasetype] = Utils.remove_namespace(filter[:releasetype])
176
+ end
165
177
  end
166
178
 
167
179
  end
@@ -1,4 +1,4 @@
1
- # $Id: includes.rb 148 2007-07-19 17:26:33Z phw $
1
+ # $Id: includes.rb 158 2007-07-25 16:19:19Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -75,11 +75,11 @@ module MusicBrainz
75
75
  @parameters << 'tags' if includes[:tags]
76
76
 
77
77
  includes[:releases].each {|release_type|
78
- @parameters << 'sa-' + release_type.to_s
78
+ @parameters << 'sa-' + Utils.remove_namespace(release_type.to_s)
79
79
  } if includes[:releases]
80
80
 
81
81
  includes[:va_releases].each {|release_type|
82
- @parameters << 'va-' + release_type.to_s
82
+ @parameters << 'va-' + Utils.remove_namespace(release_type.to_s)
83
83
  } if includes[:va_releases]
84
84
  end
85
85
 
@@ -1,4 +1,4 @@
1
- # $Id: mbxml.rb 152 2007-07-24 08:47:28Z phw $
1
+ # $Id: mbxml.rb 158 2007-07-25 16:19:19Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Nigel Graham, Philipp Wolfer
@@ -122,7 +122,7 @@ module MusicBrainz
122
122
  # Read all defined data fields
123
123
  artist.id = node.attributes['id']
124
124
  if node.attributes['type']
125
- artist.type = MBXML.add_namespace(node.attributes['type'], Model::NS_MMD_1)
125
+ artist.type = Utils.add_namespace(node.attributes['type'])
126
126
  end
127
127
 
128
128
  artist.name = node.elements['name'].text if node.elements['name']
@@ -185,7 +185,7 @@ module MusicBrainz
185
185
 
186
186
  # Read the types
187
187
  node.attributes['type'].split(' ').each {|type|
188
- release.types << MBXML.add_namespace(type, Model::NS_MMD_1)
188
+ release.types << Utils.add_namespace(type)
189
189
  } if node.attributes['type']
190
190
 
191
191
  # Read the text representation information.
@@ -289,7 +289,7 @@ module MusicBrainz
289
289
  # Read all defined data fields
290
290
  label.id = node.attributes['id']
291
291
  if node.attributes['type']
292
- label.type = MBXML.add_namespace(node.attributes['type'], Model::NS_MMD_1)
292
+ label.type = Utils.add_namespace(node.attributes['type'])
293
293
  end
294
294
 
295
295
  label.name = node.elements['name'].text if node.elements['name']
@@ -338,7 +338,7 @@ module MusicBrainz
338
338
  alias_model = @factory.new_alias
339
339
  alias_model.name = node.text
340
340
  if node.attributes['type']
341
- alias_model.type = MBXML.add_namespace(node.attributes['type'], Model::NS_MMD_1)
341
+ alias_model.type = Utils.add_namespace(node.attributes['type'])
342
342
  end
343
343
  alias_model.script = node.attributes['script']
344
344
  return alias_model
@@ -419,7 +419,7 @@ module MusicBrainz
419
419
  #
420
420
  # The node must be of the type <em>relation-list</em>.
421
421
  def read_relation_list(node)
422
- target_type = MBXML.add_namespace(node.attributes['target-type'], Model::NS_REL_1)
422
+ target_type = Utils.add_namespace(node.attributes['target-type'], Model::NS_REL_1)
423
423
  node.elements.each('relation') {|child|
424
424
  yield create_relation(child, target_type)
425
425
  }
@@ -435,18 +435,15 @@ module MusicBrainz
435
435
  end
436
436
 
437
437
  if node.attributes['type']
438
- relation.type = MBXML.add_namespace(node.attributes['type'], Model::NS_REL_1)
438
+ relation.type = Utils.add_namespace(node.attributes['type'], Model::NS_REL_1)
439
439
  end
440
440
 
441
441
  relation.begin_date = read_date_attribute(node, 'begin')
442
-
443
- if node.attributes['end']
444
- relation.begin_end = Model::IncompleteDate.new node.attributes['end']
445
- end
442
+ relation.end_date = read_date_attribute(node, 'end')
446
443
 
447
444
  if node.attributes['attributes']
448
445
  node.attributes['attributes'].split(' ').each {|attribute|
449
- relation.attributes << MBXML.add_namespace(attribute, Model::NS_REL_1)
446
+ relation.attributes << Utils.add_namespace(attribute, Model::NS_REL_1)
450
447
  }
451
448
  end
452
449
 
@@ -501,7 +498,7 @@ module MusicBrainz
501
498
  user_model = @factory.new_user
502
499
  # Read the types
503
500
  node.attributes['type'].split(' ').each {|type|
504
- user_model.types << MBXML.add_namespace(type, Model::NS_EXT_1)
501
+ user_model.types << Utils.add_namespace(type, Model::NS_EXT_1)
505
502
  } if node.attributes['type']
506
503
 
507
504
  user_model.name = node.elements['name'].text
@@ -530,19 +527,6 @@ module MusicBrainz
530
527
  end
531
528
  end
532
529
 
533
- # Helper method which will return the given property
534
- # extended by the namespace. If the property
535
- # already includes the namespace it will be returned
536
- # unchanged.
537
- def self.add_namespace(property, namespace)
538
- regex = Regexp.new("/#{namespace}[a-z-]/i")
539
- unless property =~ regex
540
- return namespace + property
541
- else
542
- return property
543
- end
544
- end
545
-
546
530
  def self.get_element(node, local_name, ns)
547
531
  node.elements["*[local-name() = '#{local_name}' and namespace-uri() = '#{ns}']"]
548
532
  end
@@ -1,4 +1,4 @@
1
- # $Id: test_entity.rb 118 2007-07-11 22:46:58Z phw $
1
+ # $Id: test_entity.rb 162 2007-07-29 17:44:11Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -60,16 +60,16 @@ module TestEntity
60
60
  artist_rel.target = Model::Artist.new
61
61
  artist_rel.type = Model::NS_REL_1 + 'Vocal'
62
62
  artist_rel.direction = Model::Relation::DIR_BACKWARD
63
- artist_rel.attributes << 'Guest'
64
- artist_rel.attributes << 'Lead'
63
+ artist_rel.attributes << Model::NS_REL_1 + 'Guest'
64
+ artist_rel.attributes << Model::NS_REL_1 + 'Lead'
65
65
  assert_nothing_raised {entity.add_relation artist_rel}
66
66
 
67
67
  track_rel = Model::Relation.new
68
68
  track_rel.target = Model::Track.new
69
69
  track_rel.type = Model::NS_REL_1 + 'Vocal'
70
70
  track_rel.direction = Model::Relation::DIR_FORWARD
71
- track_rel.attributes << 'Lead'
72
- track_rel.attributes << 'Guest'
71
+ track_rel.attributes << Model::NS_REL_1 + 'Lead'
72
+ track_rel.attributes << Model::NS_REL_1 + 'Guest'
73
73
  assert_nothing_raised {entity.add_relation track_rel}
74
74
 
75
75
  url_rel = Model::Relation.new
@@ -91,15 +91,27 @@ module TestEntity
91
91
  assert_equal 1, rel_list.size
92
92
  assert rel_list.include?(artist_rel)
93
93
 
94
+ # Get only artist relation by target type (without namespace)
95
+ assert_nothing_raised {rel_list = entity.get_relations(
96
+ :target_type => 'Artist')}
97
+ assert_equal 1, rel_list.size
98
+ assert rel_list.include?(artist_rel)
99
+
94
100
  # Get only url relation type
95
101
  assert_nothing_raised {rel_list = entity.get_relations(
96
102
  :relation_type => Model::NS_REL_1 + 'OfficialHomepage')}
97
103
  assert_equal 1, rel_list.size
98
104
  assert rel_list.include?(url_rel)
99
105
 
106
+ # Get only url relation type (without namespace)
107
+ assert_nothing_raised {rel_list = entity.get_relations(
108
+ :relation_type => 'OfficialHomepage')}
109
+ assert_equal 1, rel_list.size
110
+ assert rel_list.include?(url_rel)
111
+
100
112
  # Get only artist and track relation by attribute
101
113
  assert_nothing_raised {rel_list = entity.get_relations(
102
- :required_attributes => ['Guest', 'Lead'])}
114
+ :required_attributes => ['Guest', Model::NS_REL_1 + 'Lead'])}
103
115
  assert_equal 2, rel_list.size
104
116
  assert rel_list.include?(artist_rel)
105
117
  assert rel_list.include?(track_rel)
@@ -1,4 +1,4 @@
1
- # $Id: test_artist_includes.rb 118 2007-07-11 22:46:58Z phw $
1
+ # $Id: test_artist_includes.rb 158 2007-07-25 16:19:19Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -26,8 +26,8 @@ class TestArtistIncludes < Test::Unit::TestCase
26
26
  :track_rels => true,
27
27
  :label_rels => true,
28
28
  :url_rels => true,
29
- :releases => ['Album', 'Official'],
30
- :va_releases => ['Album', 'Official'],
29
+ :releases => [Model::Release::TYPE_ALBUM, 'Official'],
30
+ :va_releases => ['Album', Model::Release::TYPE_OFFICIAL],
31
31
  :tags => true
32
32
  )
33
33
  result_string = includes.to_s
data/test/test_release.rb CHANGED
@@ -1,4 +1,4 @@
1
- # $Id: test_release.rb 138 2007-07-17 09:05:01Z phw $
1
+ # $Id: test_release.rb 163 2007-07-29 17:52:22Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -14,7 +14,8 @@ class TestRelease < Test::Unit::TestCase
14
14
  @tested_class = Model::Release
15
15
  @invalid_entity_types = [:artist, :track, :label]
16
16
  @tracks = [Model::Track.new, Model::Track.new]
17
- @release_events = [Model::ReleaseEvent.new, Model::ReleaseEvent.new]
17
+ @release_events = [Model::ReleaseEvent.new('DE', 2007), Model::ReleaseEvent.new('GB', 1996),
18
+ Model::ReleaseEvent.new('GB', '1996-06-01'), Model::ReleaseEvent.new('GB', '1996-06')]
18
19
  @discs = [Model::Disc.new, Model::Disc.new]
19
20
  end
20
21
 
@@ -121,12 +122,27 @@ class TestRelease < Test::Unit::TestCase
121
122
  # Many release events can be added
122
123
  def test_add_and_remove_release_events
123
124
  release = Model::Release.new
125
+
126
+ assert_equal nil, release.earliest_release_event
127
+ assert_equal nil, release.earliest_release_date
128
+
124
129
  assert_equal 0, release.release_events.size
125
130
  assert_nothing_raised {release.release_events << @release_events[0]}
126
131
  assert_equal 1, release.release_events.size
127
132
  assert_nothing_raised {release.release_events << @release_events[1]}
128
133
  assert_equal 2, release.release_events.size
134
+ assert_nothing_raised {release.release_events << @release_events[2]}
135
+ assert_equal 3, release.release_events.size
136
+ assert_nothing_raised {release.release_events << @release_events[3]}
137
+ assert_equal 4, release.release_events.size
129
138
 
139
+ assert_equal @release_events[2], release.earliest_release_event
140
+ assert_equal release.earliest_release_event.date, release.earliest_release_date
141
+
142
+ assert_nothing_raised {release.release_events.delete @release_events[2]}
143
+ assert_equal 3, release.release_events.size
144
+ assert_nothing_raised {release.release_events.delete @release_events[3]}
145
+ assert_equal 2, release.release_events.size
130
146
  assert_nothing_raised {release.release_events.delete @release_events[1]}
131
147
  assert_equal 1, release.release_events.size
132
148
  assert_nothing_raised {release.release_events.delete @release_events[0]}
@@ -1,4 +1,4 @@
1
- # $Id: test_release_filter.rb 121 2007-07-12 08:56:19Z phw $
1
+ # $Id: test_release_filter.rb 159 2007-07-25 16:53:32Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -55,6 +55,15 @@ class TestReleaseFilter < Test::Unit::TestCase
55
55
  assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
56
56
  end
57
57
 
58
+ def test_release_types_as_array
59
+ filter = Webservice::ReleaseFilter.new(:releasetypes => [Model::Release::TYPE_ALBUM, 'Official'])
60
+ filter_string = filter.to_s
61
+ assert_not_equal '&', filter_string[0]
62
+
63
+ result_hash = query_string_to_hash filter_string
64
+ assert_equal 'Album Official', result_hash['releasetypes'], filter_string
65
+ end
66
+
58
67
  def test_empty_filter
59
68
  filter = Webservice::ReleaseFilter.new({})
60
69
  assert_equal '', filter.to_s
@@ -1,4 +1,4 @@
1
- # $Id: test_track_filter.rb 121 2007-07-12 08:56:19Z phw $
1
+ # $Id: test_track_filter.rb 159 2007-07-25 16:53:32Z phw $
2
2
  #
3
3
  # Author:: Philipp Wolfer (mailto:phw@rubyforge.org)
4
4
  # Copyright:: Copyright (c) 2007, Philipp Wolfer
@@ -55,6 +55,15 @@ class TestTrackFilter < Test::Unit::TestCase
55
55
  assert_equal @filter_hash[:query].to_s, result_hash['query'], filter_string
56
56
  end
57
57
 
58
+ def test_release_type_as_constant
59
+ filter = Webservice::TrackFilter.new(:releasetype => Model::Release::TYPE_ALBUM)
60
+ filter_string = filter.to_s
61
+ assert_not_equal '&', filter_string[0]
62
+
63
+ result_hash = query_string_to_hash filter_string
64
+ assert_equal 'Album', result_hash['releasetype'], filter_string
65
+ end
66
+
58
67
  def test_empty_filter
59
68
  filter = Webservice::TrackFilter.new({})
60
69
  assert_equal '', filter.to_s
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: rbrainz
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.2.1
7
- date: 2007-07-24 00:00:00 +02:00
6
+ version: 0.3.0
7
+ date: 2007-08-11 00:00:00 +02:00
8
8
  summary: Ruby library for the MusicBrainz XML web service.
9
9
  require_paths:
10
10
  - lib