Class: TunecoreDirect::Song
- Includes:
- TunecoreDirect
- Defined in:
- lib/tunecore_direct/song.rb
Overview
Represents a song in TuneCore. Every song must belong to an #Album, which in turn must belong to a #Person. The actual media file (wav, mp3, flac, etc.) should be placed on Amazon S3, either using the TuneCore uploaders or a 3rd party library such as the Amazon_S3_Library_for_REST_in_Ruby.
Instance Attribute Summary collapse
-
#album_id ⇒ Object
Returns the value of attribute album_id.
-
#artist_name ⇒ Object
Returns the value of attribute artist_name.
-
#asset_url ⇒ Object
Returns the value of attribute asset_url.
-
#errors ⇒ Object
Returns the value of attribute errors.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parental_advisory ⇒ Object
Returns the value of attribute parental_advisory.
-
#s3_bucket_name ⇒ Object
Returns the value of attribute s3_bucket_name.
-
#s3_key ⇒ Object
Returns the value of attribute s3_key.
-
#s3_url ⇒ Object
Returns the value of attribute s3_url.
-
#song_id ⇒ Object
Returns the value of attribute song_id.
-
#track_num ⇒ Object
Returns the value of attribute track_num.
Attributes inherited from Base
Class Method Summary collapse
-
.from_xml_element(song_element) ⇒ Object
Creates an Album object from a Rexml:Element.
Instance Method Summary collapse
-
#album ⇒ Object
Returns that Album that this Song belongs to.
-
#initialize(options = {}) ⇒ Song
constructor
A new instance of Song.
-
#person ⇒ Object
Returns the Person that this Song belongs to.
-
#save ⇒ Object
Save’s the song in Tunecore’s system.
-
#upload_url ⇒ Object
Returns the URL for the upload tool.
Methods inherited from Base
api_key, #api_key, api_key=, #to_xml, tunecore_server, #tunecore_server, tunecore_server=
Constructor Details
#initialize(options = {}) ⇒ Song
Returns a new instance of Song.
13 14 15 16 17 |
# File 'lib/tunecore_direct/song.rb', line 13 def initialize( = {}) .each do |k,v| self.send("#{k}=", v) end end |
Instance Attribute Details
#album_id ⇒ Object
Returns the value of attribute album_id.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def album_id @album_id end |
#artist_name ⇒ Object
Returns the value of attribute artist_name.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def artist_name @artist_name end |
#asset_url ⇒ Object
Returns the value of attribute asset_url.
11 12 13 |
# File 'lib/tunecore_direct/song.rb', line 11 def asset_url @asset_url end |
#errors ⇒ Object
Returns the value of attribute errors.
11 12 13 |
# File 'lib/tunecore_direct/song.rb', line 11 def errors @errors end |
#name ⇒ Object
Returns the value of attribute name.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def name @name end |
#parental_advisory ⇒ Object
Returns the value of attribute parental_advisory.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def parental_advisory @parental_advisory end |
#s3_bucket_name ⇒ Object
Returns the value of attribute s3_bucket_name.
11 12 13 |
# File 'lib/tunecore_direct/song.rb', line 11 def s3_bucket_name @s3_bucket_name end |
#s3_key ⇒ Object
Returns the value of attribute s3_key.
11 12 13 |
# File 'lib/tunecore_direct/song.rb', line 11 def s3_key @s3_key end |
#s3_url ⇒ Object
Returns the value of attribute s3_url.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def s3_url @s3_url end |
#song_id ⇒ Object
Returns the value of attribute song_id.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def song_id @song_id end |
#track_num ⇒ Object
Returns the value of attribute track_num.
10 11 12 |
# File 'lib/tunecore_direct/song.rb', line 10 def track_num @track_num end |
Class Method Details
.from_xml_element(song_element) ⇒ Object
Creates an Album object from a Rexml:Element
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/tunecore_direct/song.rb', line 51 def self.from_xml_element( song_element) song = self.new song.song_id = song_element.elements["id"].text song.album_id = song_element.elements["album-id"].text song.name = song_element.elements["name"].text song.artist_name = song_element.elements["artist-name"].text unless song_element.elements["artist-name"].nil? song.parental_advisory = song_element.elements["parental-advisory"].text song.track_num = song_element.elements["track-num"].text return song end |
Instance Method Details
#album ⇒ Object
Returns that Album that this Song belongs to
20 21 22 |
# File 'lib/tunecore_direct/song.rb', line 20 def album raise "Song#album is not supported in this version of the SDK" end |
#person ⇒ Object
Returns the Person that this Song belongs to
25 26 27 |
# File 'lib/tunecore_direct/song.rb', line 25 def person raise "Song#person is not supported in this version of the SDK" end |
#save ⇒ Object
Save’s the song in Tunecore’s system
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/tunecore_direct/song.rb', line 30 def save req = Request.new params = { "album_id" => @album_id, "name" => @name, "artist_name" => @artist_name, "track_num" => @track_num, "parental_advisory" => @parental_advisory, "asset_url" => @asset_url } res = req.create_song( params ) raise "Unexpected return type: #{res.type}" unless res.type == "song" if res.status == "created" @song_id = res.object.song_id return true else @errors = res.errors return false end end |
#upload_url ⇒ Object
Returns the URL for the upload tool
63 64 65 |
# File 'lib/tunecore_direct/song.rb', line 63 def upload_url "#{tunecore_server}/partner/track_upload?api_key=#{api_key}&song_id=#{self.song_id}" end |