Class: TunecoreDirect::Album

Inherits:
Base
  • Object
show all
Includes:
TunecoreDirect
Defined in:
lib/tunecore_direct/album.rb

Overview

Represents an individual TuneCore Album. Each album belongs to a Person and has one or more Song objects attached to it. To attach artwork to the Album you should place the Artwork file on Amazon S3 and provide the S3 location in the #artwork_s3_url accessor. You can upload the artwork file using !TuneCore’s web-based upload tool or you can use a 3rd party S3 interface such as the Amazon_S3_Library_for_REST_in_Ruby.

Stores should be defined using the following abbreviations, seperated by commas: iTunesUS iTunesAU iTunesCA iTunesEU iTunesJP iTunesUK RhapsodyRH MusicNet Napster eMusic Amazon Lala

Instance Attribute Summary collapse

Attributes inherited from Base

#log

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

api_key, #api_key, api_key=, #to_xml, tunecore_server, #tunecore_server, tunecore_server=

Constructor Details

#initialize(options = {}) ⇒ Album

Returns a new instance of Album.



33
34
35
36
37
# File 'lib/tunecore_direct/album.rb', line 33

def initialize(options = {})
  options.each do |k,v|
    self.send("#{k}=", v)
  end
end

Instance Attribute Details

#album_idObject

Returns the value of attribute album_id.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def album_id
  @album_id
end

#artist_nameObject

Returns the value of attribute artist_name.



27
28
29
# File 'lib/tunecore_direct/album.rb', line 27

def artist_name
  @artist_name
end

#artworkObject

this should be set to an Artwork object



31
32
33
# File 'lib/tunecore_direct/album.rb', line 31

def artwork
  @artwork
end

#artwork_s3_idObject

Returns the value of attribute artwork_s3_id.



28
29
30
# File 'lib/tunecore_direct/album.rb', line 28

def artwork_s3_id
  @artwork_s3_id
end

Returns the value of attribute c_copyright.



27
28
29
# File 'lib/tunecore_direct/album.rb', line 27

def c_copyright
  @c_copyright
end

#errorsObject

Returns the value of attribute errors.



29
30
31
# File 'lib/tunecore_direct/album.rb', line 29

def errors
  @errors
end

#label_nameObject

Returns the value of attribute label_name.



27
28
29
# File 'lib/tunecore_direct/album.rb', line 27

def label_name
  @label_name
end

#nameObject

Returns the value of attribute name.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def name
  @name
end

#orig_release_dateObject

Returns the value of attribute orig_release_date.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def orig_release_date
  @orig_release_date
end

Returns the value of attribute p_copyright.



27
28
29
# File 'lib/tunecore_direct/album.rb', line 27

def p_copyright
  @p_copyright
end

#parental_advisoryObject

Returns the value of attribute parental_advisory.



27
28
29
# File 'lib/tunecore_direct/album.rb', line 27

def parental_advisory
  @parental_advisory
end

#person_idObject

Returns the value of attribute person_id.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def person_id
  @person_id
end

#primary_genreObject

Returns the value of attribute primary_genre.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def primary_genre
  @primary_genre
end

#recording_locationObject

Returns the value of attribute recording_location.



27
28
29
# File 'lib/tunecore_direct/album.rb', line 27

def recording_location
  @recording_location
end

#sale_dateObject

Returns the value of attribute sale_date.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def sale_date
  @sale_date
end

#secondary_genreObject

Returns the value of attribute secondary_genre.



26
27
28
# File 'lib/tunecore_direct/album.rb', line 26

def secondary_genre
  @secondary_genre
end

#stateObject

Returns the value of attribute state.



30
31
32
# File 'lib/tunecore_direct/album.rb', line 30

def state
  @state
end

#storesObject

Returns the value of attribute stores.



30
31
32
# File 'lib/tunecore_direct/album.rb', line 30

def stores
  @stores
end

#takedown_atObject

Returns the value of attribute takedown_at.



28
29
30
# File 'lib/tunecore_direct/album.rb', line 28

def takedown_at
  @takedown_at
end

#xmlObject

Returns the value of attribute xml.



30
31
32
# File 'lib/tunecore_direct/album.rb', line 30

def xml
  @xml
end

Class Method Details

.from_xml_element(album_element) ⇒ Object

Creates an Album object from a Rexml:Element



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/tunecore_direct/album.rb', line 40

def self.from_xml_element( album_element)
  @xml = album_element
  album = self.new(:xml => @xml)
  album.album_id = album_element.elements["id"].text
  album.person_id = album_element.elements["person-id"].text 
  album.name = album_element.elements["name"].text
  album.orig_release_date = album_element.elements["orig-release-year"].text
  album.sale_date = album_element.elements["sale-date"].text
  album.primary_genre = album_element.elements["primary-genre"].text 
  album.secondary_genre = album_element.elements["secondary-genre"].text unless album_element.elements["secondary-genre"].nil?
  album.artist_name = album_element.elements["artist-name"].text
  album.label_name = album_element.elements["label-name"].text
  album.c_copyright = album_element.elements["c-copyright"].text
  album.p_copyright = album_element.elements["p-copyright"].text
  album.recording_location = album_element.elements["recording-location"].text
  album.state = album_element.elements["state"].text
  album.takedown_at = album_element.elements["takedown-at"].text
  return album
end

.get(album_id) ⇒ Object

Returns an Album



92
93
94
95
96
97
# File 'lib/tunecore_direct/album.rb', line 92

def self.get(album_id)
  req = Request.new
  res = req.get_album(album_id)
  raise "Unexpected return type: #{res.type}" unless res.type == "album"
  return res.object
end

.get_all(person_id = nil) ⇒ Object

Returns all your albums. If a person_id is specified it will return only albums for that person.



100
101
102
103
104
105
# File 'lib/tunecore_direct/album.rb', line 100

def self.get_all(person_id=nil)
  req = Request.new
  res = req.get_albums(person_id)
  raise "Unexpected return type: #{res.type}" unless res.type == "albums"
  return res.object
end

.takedown(album_id) ⇒ Object

Takes down an album from the stores



130
131
132
133
134
135
136
137
138
139
# File 'lib/tunecore_direct/album.rb', line 130

def self.takedown(album_id)
  req = Request.new
  res = req.takedown_album(album_id)
  raise "Unexpected return type: #{res.type}" unless res.type == "album"
  if res.object.takedown_at != nil
    return true
  else
    return false
  end
end

Instance Method Details

#artwork_upload_urlObject



145
146
147
# File 'lib/tunecore_direct/album.rb', line 145

def artwork_upload_url
  "http://#{tunecore_server}/partner/artwork_upload?album_id=#{self.album_id}&api_key=#{api_key}"
end

#createObject

Creates a new album



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/tunecore_direct/album.rb', line 61

def create
 req = Request.new
 params = { "person_id" => @person_id, 
            "name" => @name, 
            "orig_release_year" => @orig_release_date, 
            "sale_date" => @sale_date, 
            "primary_genre" => @primary_genre,
            "secondary_genre" => @secondary_genre,
            "artist_name" => @artist_name, 
            "label_name" => @label_name,
            "c_copyright" => @c_copyright, 
            "p_copyright" => @p_copyright,
            "recording_location" => @recording_location,
            "stores" => @stores }
            
  if @artwork.asset_url
    params["artwork_asset_url"] = @artwork.asset_url
  end
  
  res = req.create_album(params)
  raise "Unexpected return type: #{res.type}" unless res.type == "album"
  if res.status == "created"
    @album_id = res.object.album_id
    return true
  else
    @errors = res.errors
    return false
  end
end

#finalizeObject

Once you call Album#finalize the album will be queued for delivery to the stores. After you call finalize you can no longer make changes to the Album.

All the songs should be created and media assets for the Album should be uploaded to S3.



125
126
127
# File 'lib/tunecore_direct/album.rb', line 125

def finalize
  raise "Album#finalize is not implemented in this version of the SDK"
end

#is_taken_down?Boolean

Returns:

  • (Boolean)


141
142
143
# File 'lib/tunecore_direct/album.rb', line 141

def is_taken_down?
  !@takedown.nil?
end

#song_countObject

Returns the number of songs that have been created for this album



119
120
121
# File 'lib/tunecore_direct/album.rb', line 119

def song_count
  raise "Album#song_count is not implemented in this version of the SDK"
end

#songsObject

Returns an array that contains every Song in this Album



108
109
110
111
112
113
114
115
116
# File 'lib/tunecore_direct/album.rb', line 108

def songs
#  if @xml == nil
#    self.
  songs = []
  @xml.elements.each("songs/song") do |song_element|
    songs << Song.from_xml_element( song_element)
  end
  return songs
end