Skip to content

Commit

Permalink
Fixed album example to work with the 2.0 version
Browse files Browse the repository at this point in the history
  • Loading branch information
xhochy committed Sep 11, 2009
1 parent 4d598bb commit fa2b63e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/album.rb
@@ -1,10 +1,12 @@
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler')) require File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib', 'scrobbler'))


album = Scrobbler::Album.new('Carrie Underwood', 'Some Hearts', :include_info => true) Scrobbler::Base::api_key = "..add..";

album = Scrobbler::Album.new('Some Hearts', :artist => 'Carrie Underwood', :include_info => true)


puts "Album: #{album.name}" puts "Album: #{album.name}"
puts "Artist: #{album.artist}" puts "Artist: #{album.artist}"
puts "Reach: #{album.reach}" puts "Playcount: #{album.playcount}"
puts "URL: #{album.url}" puts "URL: #{album.url}"
puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}" puts "Release Date: #{album.release_date.strftime('%m/%d/%Y')}"


Expand All @@ -14,4 +16,4 @@
puts "Tracks" puts "Tracks"
longest_track_name = album.tracks.collect(&:name).sort { |x, y| y.length <=> x.length }.first.length longest_track_name = album.tracks.collect(&:name).sort { |x, y| y.length <=> x.length }.first.length
puts "=" * longest_track_name puts "=" * longest_track_name
album.tracks.each { |t| puts t.name } album.tracks.each { |t| puts t.name }
5 changes: 5 additions & 0 deletions lib/scrobbler/album.rb
Expand Up @@ -95,6 +95,11 @@ def new_from_libxml(xml)
# #
# @todo Albums should be able to be created via a MusicBrainz id too # @todo Albums should be able to be created via a MusicBrainz id too
def initialize(name, input={}) def initialize(name, input={})
# Support old version of initialize where we had (artist_name, album_name)
if input.class == String
data = {:artist => name, :name => input}
name = input, input = data
end
data = {:include_profile => false}.merge(input) data = {:include_profile => false}.merge(input)
raise ArgumentError, "Artist or mbid is required" if data[:artist].nil? && data[:mbid].nil? raise ArgumentError, "Artist or mbid is required" if data[:artist].nil? && data[:mbid].nil?
raise ArgumentError, "Name is required" if name.blank? raise ArgumentError, "Name is required" if name.blank?
Expand Down

0 comments on commit fa2b63e

Please sign in to comment.